如题
我是为了获取计算机名与IP地址,这是大常见的一个方法
我声明的全局外部函数如下:
function int WSAStartup( uint UIVersionRequested, ref s_WSAData lpWSAData ) library "wsock32.dll" alias for "WSAStartupA"
function int WSACleanup( ) library "wsock32.dll"
function int WSAGetLastError( ) library "wsock32.dll"
function int GetHostName( ref string name, int namelen ) library "wsock32.dll" alias for "GetHostNameA"
function string GetHost( string lpszhost, ref blob lpszaddress ) library "PBWS32.dll" alias for "GetHostA"
其中数据结构s_WSAData 定义如下:
unsignedinteger version
unsignedinteger highversion
character description[257]
character systemstatus[129]
unsignedinteger maxsockets
unsignedinteger maxupddg
string vendorinfo
调用程序如下:
s_wsadata l_WSAData
string ls_HostName = space( 128 )
string ls_IpAddress
int li_version = 257
blob{4} lb_HostAddress
if WSAStartUp( li_version, l_WSAData ) = 0 then
if GetHostName( ls_HostName, len( ls_HostName ) ) < 0 then
messagebox( '获取计算机主机名错误', WSAGetLastError( ) )
else
GetHost( ls_HostName, lb_HostAddress ) //获取主机名和IP地址
ls_IpAddress = string(asc(string(blobmid(lb_HostAddress,1,1))),'000') + '.'
ls_IpAddress += string(asc(string(blobmid(lb_hostaddress,2,1))),'000') + '.'
ls_IpAddress += string(asc(string(blobmid(lb_hostaddress,3,1))),'000') + '.'
ls_ipaddress += string(asc(string(blobmid(lb_hostaddress,4,1))),'000')
end if
WSACleanup()
else
messagebox( '获取计算机主机名错误', WSAGetLastError( ) )
end if
gstr_userinfo.hostname = ls_hostname
gstr_userinfo.ipaddress = ls_ipaddress
当执行每个API函数时都报如题的错误。
请各位高手指点迷津,万分感谢!!!!!
------解决方案--------------------
ref 参数不对
------解决方案--------------------
function int WSAStartup( uint UIVersionRequested, ref s_WSAData
lpWSAData ) library "wsock32.dll"
function int WSACleanup() library "wsock32.dll"
function int WSAGetLastError ( ) library "wsock32.dll"
function int gethostname ( ref string name, int namelen ) library "wsock32.dll"
function string GetHost(string lpszhost, ref blob lpszaddress) library 'pbws32.dll'
定义有问题!
你还要有PBWS32.dll
------解决方案--------------------
我用你的代码报错,重新定义就行了!
要行你换个机器试试吧!