【发布时间】:2011-11-29 00:13:37
【问题描述】:
我正在尝试将回调函数从 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 消息框为例。
这是我当前的 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
我想我错过了什么??! 任何帮助将不胜感激!
【问题讨论】:
标签: c++ vb.net delegates callback