请教应用小程序
题目:编辑程序,将本机ip自动嵌入桌面11.doc文件。语言不限。
[解决办法]
//---------------------------------------
//获得本机的全部IP地址
AnsiString __fastcall ReadLocalAddress(void)
{
struct hostent *thisHost;
struct in_addr in;
WSADATA wsaData;
char MyName[80];
AnsiString IpAddress;
IpAddress="";//"当前本机[ TCP/IP ]列表: ";
try
{
WSAStartup(MAKEWORD(2,0),&wsaData);
gethostname(MyName,80);
thisHost=gethostbyname(MyName);
memset(&in,sizeof(in),0);
int i = -1;
while (thisHost->h_addr_list[i+1] != NULL)
{
i++;
in.s_addr=*((unsigned long *)thisHost->h_addr_list[i]);
IpAddress=IpAddress+/*"["+IntToStr(i)+"]_"+*/inet_ntoa(in)+",";
}
WSACleanup();
}
catch(...)
{
WSACleanup();
}
//::Sleep(2000);
return IpAddress;
}
//---------------------------------------
参考