如何通过 C++ VB.NET 程序的回调函数?
我正在尝试将回调函数从 C++ dll 传递到 VB.NET 应用程序。 这是我当前的 C++ 代码:
void DLL_EXPORT registerEvent( void (*callBackFunction)(string str),string str)
{
callBackFunction(str);
}
void test(string str)
{
MessageBoxA(0,str.c_str(), "",MB_OK);
}
LRESULT CALLBACK keyHandler(int nCode, WPARAM wParam, LPARAM lParam)
{
...
registerEvent(&test, txt); //txt = the text received after user input with some additions
return CallNextHookEx(hookHandle, nCode,
wParam, lParam);
}
这是在 C++ dll 内部工作的(使用正确的文本调用消息框) 但我想用文本“触发”VB 应用程序中的测试过程,以使用 VB Messagebox 为例。
这是我当前的 VB.NET 代码:
Public Delegate Sub Callback(ByVal str As String)
Private Declare Sub registerEvent Lib "path\mycppdll.dll" _
(ByVal cb As Callback, ByVal str As String)
Dim cb As New Callback(AddressOf CallBackFunc)
Public Sub CallBackFunc(ByVal str As String)
'this should be the equivalent of the "test" proc in c++ but it's not triggered
End Sub
我想我错过了一些东西??! 任何帮助将不胜感激!
I'm trying to pass a callback function from a C++ dll to a VB.NET application.
Here is my current C++ code :
void DLL_EXPORT registerEvent( void (*callBackFunction)(string str),string str)
{
callBackFunction(str);
}
void test(string str)
{
MessageBoxA(0,str.c_str(), "",MB_OK);
}
LRESULT CALLBACK keyHandler(int nCode, WPARAM wParam, LPARAM lParam)
{
...
registerEvent(&test, txt); //txt = the text received after user input with some additions
return CallNextHookEx(hookHandle, nCode,
wParam, lParam);
}
This is working inside the C++ dll (the messagebox is called with the correct text)
But i'd like to "trigger" the test procedure in the VB application with the text to use the VB Messagebox for example.
Here is my current VB.NET code :
Public Delegate Sub Callback(ByVal str As String)
Private Declare Sub registerEvent Lib "path\mycppdll.dll" _
(ByVal cb As Callback, ByVal str As String)
Dim cb As New Callback(AddressOf CallBackFunc)
Public Sub CallBackFunc(ByVal str As String)
'this should be the equivalent of the "test" proc in c++ but it's not triggered
End Sub
I think i'm missing something ??!
Any help will be appreciated !
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
C++ 代码必须具有
extern C
链接,否则 VB 代码将无法看到它。将相关声明包含在标头中The C++ code must have
extern C
linkage or the VB code won't be able to see it. Wrap the relevant declarations in the header with