通过以下示例,InstallShield可以用WINSOCK获取IP地址,可将以下文件保存为tcpip.rul
#define WSADESCRIPTION_LEN 256
#define WSASYS_STATUS_LEN 128
typedef
WSAData
begin
INT wVersion;
INT wHighVersion;
char szDescription[WSADESCRIPTION_LEN+1];
char szSystemStatus[WSASYS_STATUS_LEN+1];
short iMaxSockets;
short iMaxUdpDg;
POINTER lpVendorInfo;
end;
WSAData structWSAData;
WSAData POINTER pWSAData;
typedef HostEnt
begin
POINTER ph_name;
POINTER ph_aliases;
short h_addrtype;
short h_length;
POINTER ph_addr_list;
end;
HostEnt structHostEnt;
HostEnt POINTER pHostEnt;
SHORT nlen;
NUMBER nIPNetAddr;
NUMBER nVersion;
STRING szMsg;
STRING szDefault;
STRING szURL;
STRING szPath;
NUMBER nRC;
NUMBER nRC2;
STRING szHostName;
STRING szMYIPAddr;
POINTER pWinSockReturn;
typedef IPName
begin
STRING szIPAddr[100];
end;
IPName LocalIPName;
IPName POINTER pLocalIPName;
typedef IPAddrList
begin
POINTER pIPAddr;
end;
IPAddrList structIPAddrList;
IPAddrList POINTER pIPAddrList;
typedef IPAddPtr
begin
LONG nIPAddr;
end;
IPAddPtr structIPAddPtr;
IPAddPtr POINTER pIPAddPtr;
POINTER pIN_Addr_Struct;
prototype POINTER wsock32.gethostbyname(BYREF STRING);
prototype POINTER wsock32.gethostname(BYREF STRING, NUMBER);
prototype POINTER wsock32.WSAStartup(INT, POINTER);
prototype POINTER wsock32.inet_ntoa( NUMBER);
prototype POINTER wsock32.WSACleanup();
prototype int wsock32.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;
本文地址:http://com.8s8s.com/it/it29129.htm