// 获取本机IP地址方法:
#include "winsock.h"
#pragma comment(lib, "ws2_32.lib ")// pragma -- 这个关键字,老是记不住,
CString strIP;//strIP -->ip地址!
WORD wVersionRequested;
WSADATA wsaData;
char name[200];
memset(name,0,200);
PHOSTENT hostinfo;
wVersionRequested = MAKEWORD( 2, 0 );
if ( WSAStartup( wVersionRequested, &wsaData ) == 0 )
{
if( gethostname ( name, sizeof(name)) == 0)
{
if((hostinfo = gethostbyname(name)) != NULL)
{
strIP= inet_ntoa (*(struct in_addr *)*hostinfo->h_addr_list);
}
}
WSACleanup( );
}