.NET 客户端 - MFC 常规 DLL 和用户定义的消息
更新:这是一个 .NET 客户端调用常规 DLL。我还有另一个扩展 DLL,它导出一些类并在常规 DLL 中使用。
我有一个第三方 DLL,它接受 WindowHandle 和用户定义的消息作为参数,并开始向传递的窗口发送消息,但我没有看到任何消息发送到我的窗口。下面是 API 调用格式:
StartMessaging(<WindowHandle>,WM_MESSAGE_API);
我需要一个常规的 MFC 常规 DLL,它将创建一个隐藏的 CFrameWnd 窗口,仅用于接收消息。 我还在 DLL 的所有入口点使用 AFX_MANAGE_STATE()。
我的 CFrameWnd 派生类中的构造函数代码:
Create(NULL,"MYWINDOW"); hWndFrame = this->m_hWnd;
消息映射:
LRESULT CMyDerivedWnd::OnMsgApi( WPARAM wParam, LPARAM lParam )
{
OutputDebugString("OnMsgApi");
return (LRESULT)0;
}
我的主类,其中调用 StartMessaging: 在构造函数中,我实例化 CFrameWnd 对象:
myDerivedWnd = new CMyDerivedWnd(this);
然后调用 InitiateMessaging:
void CMain::InitiateMessaging()
{
TCHAR szBuf[80];
::GetWindowText(myDerivedWnd->m_hWnd,szBuf,80);
OutputDebugString((LPSTR)(LPCTSTR)szBuf); //This displays MYWINDOW
StartMessaging(myDerivedWnd->m_hWnd,WM_MESSAGE_API);
}
我的 GetWindowText 函数返回正确的窗口名称,但我无法在此类中捕获 WM_MESSAGE_API 消息。 我也尝试过使用扩展 DLL 但结果相同。
UPDATE: This is a .NET Client making a call to the regular DLL. I have also got another extension DLL which exports some class and is used in the regular DLL.
I have got a third party DLL which takes a WindowHandle and a user defined message as a parameter and starts sending messages to the passed on window, but I don't see any message coming to my window. Below is API call format:
StartMessaging(<WindowHandle>,WM_MESSAGE_API);
I needed a regular MFC Regular DLL which will create a hidden CFrameWnd window just for receiving the messages.
I am also using AFX_MANAGE_STATE() at all the entry point to the DLL.
Constructor code in my CFrameWnd derived class:
Create(NULL,"MYWINDOW");
hWndFrame = this->m_hWnd;
Message Maps:
LRESULT CMyDerivedWnd::OnMsgApi( WPARAM wParam, LPARAM lParam )
{
OutputDebugString("OnMsgApi");
return (LRESULT)0;
}
My Main class where the StartMessaging is called:
In Constructor I instantiate the CFrameWnd object:
myDerivedWnd = new CMyDerivedWnd(this);
and then InitiateMessaging is called:
void CMain::InitiateMessaging()
{
TCHAR szBuf[80];
::GetWindowText(myDerivedWnd->m_hWnd,szBuf,80);
OutputDebugString((LPSTR)(LPCTSTR)szBuf); //This displays MYWINDOW
StartMessaging(myDerivedWnd->m_hWnd,WM_MESSAGE_API);
}
My GetWindowText function returns the correct Window name, but I am unable to trap WM_MESSAGE_API message in this class.
I have also tried using extension DLL but same result.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我发现了问题,但还没有答案。它是 C# 端的线程,导致事件未显示。如果对 C++ Interop 的调用位于主线程上,则事件有效,但我需要在单独的线程上进行调用。我打算发布另一个问题来寻找答案。
I found the problem, not the answer yet. It was threading on C# side causing the event not to show up.If the call to C++ Interop is on the main thread, event works, but I need the call to be on a separate thread. I am planning to post another question to find an answer.