从 C++ 转换回调函数到 VB.Net

发布于 2024-09-28 13:58:17 字数 613 浏览 5 评论 0原文

我正在尝试将 C++ API 转换为 VB.Net,但这个功能太难了,我不知道如何使其工作。

以下是该函数的 API 文档:


void RemoteDllSetReceiver(void *inst, on_received_buffer_t received_buf_cb);

设置回调函数以接收来自 DLL 的通知。回调的原型是:

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

其中

  • 指针
  • inst是最初传递给RemoteDllSetReceiver buffer &的 。 size 包含远程协议中定义的通知文本。

注意:通知可能会到达不同的线程(例如网络、计时器、音频)。


我无法想象我必须对 on_received_buffer_t 做什么,它必须是委托吗?正如您所读到的,该函数从 DLL 返回通知,例如连接状态、用户 ID...

任何帮助将不胜感激,谢谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

机场等船 2024-10-05 13:58:17

我必须补充一点,我正在使用 Visual Studio 2008 和 Compact Framework 3.5。我当前的工作是:

P/Invoke 函数:

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

received_buffer_t 的委托

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

我在代码中调用它:

RemoteDllSetReceiver(IntPtr.Zero, AddressOf ReceiveMessage)

ReceiveMessage 函数:

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

    MsgBox(buffer.ToString())

End Function

谢谢

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文