通过以下示例,InstallShield可以用WINSOCK获取IP地址,可将以下文件保存为tcpip.rul
#defineWSADESCRIPTION_LEN256
#defineWSASYS_STATUS_LEN128
typedef
WSAData
begin
INTwVersion;
INTwHighVersion;
charszDescription[WSADESCRIPTION_LEN+1];
charszSystemStatus[WSASYS_STATUS_LEN+1];
shortiMaxSockets;
shortiMaxUdpDg;
POINTERlpVendorInfo;
end;
WSADatastructWSAData;
WSADataPOINTERpWSAData;
typedefHostEnt
begin
POINTERph_name;
POINTERph_aliases;
shorth_addrtype;
shorth_length;
POINTERph_addr_list;
end;
HostEntstructHostEnt;
HostEntPOINTERpHostEnt;
SHORTnlen;
NUMBERnIPNetAddr;
NUMBERnVersion;
STRINGszMsg;
STRINGszDefault;
STRINGszURL;
STRINGszPath;
NUMBERnRC;
NUMBERnRC2;
STRINGszHostName;
STRINGszMYIPAddr;
POINTERpWinSockReturn;
typedefIPName
begin
STRINGszIPAddr[100];
end;
IPNameLocalIPName;
IPNamePOINTERpLocalIPName;
typedefIPAddrList
begin
POINTERpIPAddr;
end;
IPAddrListstructIPAddrList;
IPAddrListPOINTERpIPAddrList;
typedefIPAddPtr
begin
LONGnIPAddr;
end;
IPAddPtrstructIPAddPtr;
IPAddPtrPOINTERpIPAddPtr;
POINTERpIN_Addr_Struct;
prototypePOINTERwsock32.gethostbyname(BYREFSTRING);
prototypePOINTERwsock32.gethostname(BYREFSTRING,NUMBER);
prototypePOINTERwsock32.WSAStartup(INT,POINTER);
prototypePOINTERwsock32.inet_ntoa(NUMBER);
prototypePOINTERwsock32.WSACleanup();
prototypeintwsock32.WSAGetLastError();
program
pWSAData=&structWSAData;
nRC=UseDLL("wsock32.dll");
pWSAData->wHighVersion=1;
pWSAData->wVersion=1;
nVersion=0x02000002;//0x01000001
pWinSockReturn=WSAStartup(nVersion,pWSAData);
pWinSockReturn=gethostname(szHostName,100);
pHostEnt=gethostbyname(szHostName);
nlen=pHostEnt->h_length;
pIPAddPtr=pHostEnt->ph_addr_list;
pIPAddPtr=*pIPAddPtr;
nIPNetAddr=*pIPAddPtr;
//nIPNetAddr=pIPAddPtr->nIPAddr;
pLocalIPName=inet_ntoa(nIPNetAddr);
szMYIPAddr=pLocalIPName->szIPAddr;
MessageBox(szMYIPAddr,INFORMATION);
WSACleanup();
exit;