我的问题,比较棘手
我用VC,做一个DLL,
在VB里调用为什么总是提示,操作非法?
extern "C" _declspec(dllexport) char * GetLocalIp(void)
{
WORD wVersionRequested;
WSADATA wsaData;
char name[255];
char ipad[100];
CString ip;
PHOSTENT hostinfo;
wVersionRequested = MAKEWORD( 2, 0 );
if ( WSAStartup( wVersionRequested, &wsaData ) == 0 )
{
if( gethostname ( name, sizeof(name)) == 0)
{
if((hostinfo = gethostbyname(name)) != NULL)
{
ip = inet_ntoa (*(struct in_addr *)*hostinfo->h_addr_list);
strcpy(ipad, LPCSTR(ip));
return ipad;
}
}
WSACleanup( );
}
return "";
}
这是DLL的内容。
VB内容如下:
Declare Function GetLocalIp Lib "test.DLL" () As String
On Error Resume Next
Dim s As String
s = GetLocalIp
MsgBox Err.Description