views:

45

answers:

1

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 RemoteDllSetReceiver(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.

A: 

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

Borjolujo
This should be a comment or edit to your question, not an answer.
Sam Miller
Does that code work?
Alf P. Steinbach
The call in the code seems to work, it doesn´t throw exception, but when the API try to return a notification, the program suddenly exit without showing errors or exceptions. So i can't debug it and see what happend.I think the declaration of the delegate is incorrect, or maybe how i send the delegate to the P/Invoke function (AddressOf).
Borjolujo