我有一个Visual Basic应用程序(.NET),我已经设置了所有注册消息并发送它们的声明:
Private Const WM_DELETE_EVENT_STRING As String = "WM_xxx_DELETE_EVENT"
Private Const WM_INSERT_EVENT_STRING As String = "WM_xxx_INSERT_EVENT"
Private Shared WM_DELETE_EVENT As UInteger = Posting.PostingFunctions.RegisterWindowMessage(WM_DELETE_EVENT_STRING)
Private Shared WM_INSERT_EVENT As UInteger = Posting.PostingFunctions.RegisterWindowMessage(WM_INSERT_EVENT_STRING)
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Private Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As UInteger, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr
End Function
<DllImport("user32.dll", CharSet:=CharSet.Auto)> _
Private Shared Function RegisterWindowMessage(ByVal lpString As String) As UInteger
End Function
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Private Shared Function FindWindow(ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
End Function
我发布的句柄是IntPtr类型。我通过使用:
从调用过程中提供它 strNumber.Format(_T("%d"), theApp.GetMainWnd()->GetSafeHwnd());
WritePrivateProfileString(_T("Settings"), _T("HwndExternalApp"), strNumber, strINI);
我所做的是在VB进程中从INI文件中读取它:
m_hExternalApp = CLng((oIni.IniReadValueInt("Settings", "HwndExternalApp"))
我的调用过程是MDI应用程序。我将相同的两条注册消息添加到CMainFrame类。
最后,这是我调用VB进程的方式:
<snipped out CreateProcess code>
DWORD WaitResult;
do
{
WaitResult = MsgWaitForMultipleObjects(1,
// only 1 wait object
&processInformation.hProcess, // worker thread
FALSE, // stop if any
INFINITE, // no timeout
QS_ALLINPUT);
if (WaitResult == WAIT_OBJECT_0 + 1)
{
// Handle windows message
MSG Msg;
while (PeekMessage(&Msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
}
} while (WaitResult == WAIT_OBJECT_0 + 1);
ASSERT(WaitResult == WAIT_OBJECT_0);
我确认VB处理程序实际上被解雇了,但是C ++应用程序似乎并没有处理它们。所以:
我在这里深水,不知道我哪里出错了。
感谢您的帮助。
安德鲁