请教:怎样读取计算机中的机器名 c语言是没有办法的用API吧GetComputerName/GetComputerNameEx 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 char a[128]gethostname(a,128)就ok了还可以取得ipchar szhostname[128];if( gethostname(szhostname, 128) == 0 ){// get host adresses struct hostent * phost; int i; phost = gethostbyname(szhostname); m_hostname=szhostname; i=0; int j; int h_length=4; for( j = 0; j<h_length; j++ ) { CString addr; if( j > 0 ) str += "."; addr.Format("%u", (unsigned int)((unsigned char*)phost->h_addr_list[i])[j]); str += addr; } char pLocalIP[32], pHostname[256];PHOSTENT hostinfo;if( gethostname ( pHostname, sizeof(pHostname)) == 0){ if((hostinfo = gethostbyname(pHostname)) != NULL) { strcpy(pLocalIP,inet_ntoa (*(struct in_addr *)*hostinfo->h_addr_list)); strcpy(pHostname,hostinfo->h_name); }} 可变大小的无锯齿不规则窗口如何实现? 请教:如何在MFC对话框中实现模拟键盘输入 一段刚写的代码,不收敛,帮忙改改。 请问如何在一个类中取其成员函数的指针 如何打印CListCtrl中的内容? 如何表示10(-37)幂? 麻烦的打印问题!请帮看看,谢谢谢....!!!!! 如何实现两个对话框数据的通信,实现母对话框的数据的及时更新 CTabCtrl换页问题 帮帮小弟我 如何使编写的程序在开机时自动运行? 在线等待:mciSendString在哪个DLL中的?
gethostname(a,128)就ok了还可以取得ip
char szhostname[128];
if( gethostname(szhostname, 128) == 0 )
{
// get host adresses
struct hostent * phost;
int i;
phost = gethostbyname(szhostname);
m_hostname=szhostname;
i=0;
int j;
int h_length=4;
for( j = 0; j<h_length; j++ )
{
CString addr;
if( j > 0 )
str += "."; addr.Format("%u", (unsigned int)((unsigned
char*)phost->h_addr_list[i])[j]);
str += addr;
}
PHOSTENT hostinfo;if( gethostname ( pHostname, sizeof(pHostname)) == 0)
{
if((hostinfo = gethostbyname(pHostname)) != NULL)
{
strcpy(pLocalIP,inet_ntoa (*(struct in_addr *)*hostinfo->h_addr_list));
strcpy(pHostname,hostinfo->h_name);
}
}