XP系统插上摄像头后 程序中自动获取的ip错误, 看拔掉摄像头,获取IP地址如何?? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 问题解决了,就是在XP系统上,插上摄像头的时候,获取ip的结果会有错误,过滤掉就行了CString AutoGetIP(){ WORD wVersionRequested; WSADATA wsaData; char name[255]; CString ip; PHOSTENT hostinfo; wVersionRequested = MAKEWORD( 2, 2); CString strIP; vector<CString> vecStrIP; int a=-1,b=-1,c=-1,d=-1; if ( WSAStartup( wVersionRequested, &wsaData ) == 0 ) { if( gethostname ( name, sizeof(name)) == 0) { if((hostinfo = gethostbyname(name)) != NULL) { ip = inet_ntoa (*(struct in_addr *)*hostinfo->h_addr_list); in_addr **ppAddr=(in_addr**)hostinfo->h_addr_list; in_addr *pAddr; //AllocConsole(); while (pAddr=*(ppAddr++)) { a=pAddr->S_un.S_un_b.s_b1; b=pAddr->S_un.S_un_b.s_b2; c=pAddr->S_un.S_un_b.s_b3; d=pAddr->S_un.S_un_b.s_b4; if (a==0) { a=-1;b=-1;c=-1;d=-1; continue; } break; } } } WSACleanup( ); } ip.Format("%d.%d.%d.%d",a,b,c,d); return ip;} 怎么开始学习MFC Vs2005怎么设置bug提示是英文的 ZwQueryObject 自绘CComboBox的问题~~ 用什么方法能获得当前连接得本地IP 如何对文件夹进行压缩及解压? 透明效果的制作!? 谁知道hilbert置乱算法 请教一个clistview的问题! 如何在vc中获取鼠标的位置啊? 自绘按钮类无法输出按钮文字 VLC播放器和directshow类型播放器
{
WORD wVersionRequested;
WSADATA wsaData;
char name[255];
CString ip;
PHOSTENT hostinfo;
wVersionRequested = MAKEWORD( 2, 2);
CString strIP;
vector<CString> vecStrIP;
int a=-1,b=-1,c=-1,d=-1;
if ( WSAStartup( wVersionRequested, &wsaData ) == 0 )
{
if( gethostname ( name, sizeof(name)) == 0)
{
if((hostinfo = gethostbyname(name)) != NULL)
{
ip = inet_ntoa (*(struct in_addr *)*hostinfo->h_addr_list);
in_addr **ppAddr=(in_addr**)hostinfo->h_addr_list;
in_addr *pAddr;
//AllocConsole();
while (pAddr=*(ppAddr++))
{
a=pAddr->S_un.S_un_b.s_b1;
b=pAddr->S_un.S_un_b.s_b2;
c=pAddr->S_un.S_un_b.s_b3;
d=pAddr->S_un.S_un_b.s_b4;
if (a==0)
{
a=-1;b=-1;c=-1;d=-1;
continue;
}
break;
}
}
}
WSACleanup( );
}
ip.Format("%d.%d.%d.%d",a,b,c,d);
return ip;
}