开发者

Convert callback function from C++ to VB.Net

开发者 https://www.devze.com 2023-01-20 18:45 出处:网络
I\'m trying to convert C++ API to VB.Net, but this function is too hard and i don\'t know how make it work.

I'm trying to convert C++ API to VB.Net, but this function is too hard and i don't know how make it work.

Here is the API doc for this function:


void RemoteDllSetReceiv开发者_StackOverflow社区er(void *inst, on_received_buffer_t received_buf_cb);

Sets a callback function to receive notifications from the DLL. The prototype of the callback is:

typedef bool (*on_received_buffer_t)(void* inst, const unsigned char *buffer, unsigned int size);

Where

  • inst is the pointer originally passed to RemoteDllSetReceiver
  • buffer & size contain the notification text as defined in the Remote Protocol.

Note: notifications may arrive in different threads (e.g. network, timer, audio).


I can't imagine what i mus do with on_received_buffer_t, must it be a delegate? Like you can read, this functions returns notifications from the DLL like connection status, user id...

Any help will be appreciated, thanks.


I must add that i'm using Visual Studio 2008 and Compact Framework 3.5. My current work is:

P/Invoke Function:

Private Declare Function RemoteDllSetReceiver Lib "remote_dll.dll" (ByVal inst As IntPtr, ByVal received_buf_cb As on_received_buffer_t) As Integer

Delegate for received_buffer_t

Public Delegate Function on_received_buffer_t(ByVal inst As IntPtr, ByVal buffer() As Byte, ByVal size As Long) As Boolean

And I call it in my code:

RemoteDllSetReceiver(IntPtr.Zero, AddressOf ReceiveMessage)

ReceiveMessage Function:

Public Shared Function ReceiveMessage(ByVal inst As IntPtr, ByVal buffer() As Byte, ByVal size As Long) As Boolean

    MsgBox(buffer.ToString())

End Function

Thanks

0

精彩评论

暂无评论...
验证码 换一张
取 消