有一个想法,(高手看看可行否?)
VC编写一个用UDP发送消息的常规DLL,
CWinSockApp类
MySokcet类
在CWinSockApp类中加入一个MySocket类的实例.
BOOL CWinsockApp::InitInstance()
{
if (!AfxSocketInit())
{
AfxMessageBox(IDP_SOCKETS_INIT_FAILED);
return FALSE;
}
return TRUE;
}
DllExport long __stdcall SendMsg(char* buf)
{
theApp.sck=new MySocket();
if(!theApp.sck->Create(4000,SOCK_DGRAM))
{
MessageBox(0,"创建套接字失败","error!",0);
}
if(!theApp.sck->Bind(4000))
{
MessageBox(0,"erro","erro",0);
}
theApp.sck->SendTo(buf,strlen(buf),21,"172.16.13.22");
return 1;
}
然后用SendMsg做接口
在VB中申明:
Private Declare Function SendMsg Lib "E:\VBPro\sock\Winsock.dll" (ByVal str As String) As Long
但是总是有错,为什么?请高手指点,回答有帮助即给分