从vb项目调用c ++ dll函数时遇到问题。我有一个C ++ dll函数,其原型如下:
bool registerCallbackOnDataRec(int groupID, void * func);
'func'是一个回调函数指针,需要具有以下签名:
typedef struct
{
DWORD senderIPAddr ;
DWORD numOfBytes ;
BYTE* buffer ;
} ReceivedMessage ;
void DataRecFromServerMcstGroup(ReceivedMessage *msg);
我遇到了问题。我无法
编辑: 在Hans Passant评论之后,我编写了一些VB代码来调用c ++函数。
Public Delegate Sub DataRecFromServerDelegate(ByVal msg As IntPtr)
Declare Function registerCallbackOnDataRec Lib "NetDLL.dll" (ByVal groupID As Integer, ByVal funcPtr As DataRecFromServerDelegate)
Public Structure ReceivedMessage
Public senderIpAddr As UInteger
Public numOfBytes As UInteger
Public buffer() As Byte
End Structure
Private Sub DataRecFromServerMcstGroup(ByVal msgPtr As IntPtr)
If msgPtr <> 0 Then
*** Here i am not able to cast msgPtr into ReceivedMessage object ***
PacketRecordDLL(Msg.numOfBytes, Msg.buffer)
End If
End Sub
...
Dim varFuncPtr As DataRecFromServerDelegate = AddressOf DataRecFromServerMcstGroup
registerCallbackOnDataRec(groupID_Recording, varFuncPtr)
但这不起作用。在此代码中,我无法填补将msgPtr转换为ReceivedMessage对象的代码中的空白。我不确定其余代码是否正确。任何帮助。