从 DLL 向 Vista 中另一个进程的窗口发送消息
我正在为这件事抓狂。 我正在尝试向另一个进程中的窗口发送消息。 调用 SendMessage 或 PostMessage 或 PostThreadMessage 后,我不断收到来自 GetLastError() 的访问被拒绝 (0x5) 的消息。 我试过关闭UAC。 我还通过确保完整性级别在进程之间匹配来考虑 UIPI。 (我用 SysInternals(现在是 MS)的 Process Explorer 进行了检查)我还关闭了 Windows Defender,但没有成功。 我可以从进程内部向窗口发送消息,但是从外部我就得到了 bupkus! 这似乎是某种安全问题,但我不知道它是什么,因为两个进程具有相同的完整性级别(中 - 十进制 8192)
来自发送消息的 DLL 的代码
UINT MsgCode = ::RegisterWindowMessage(_T("MESSAGE_CODING_STRING"));
::ChangeWindowMessageFilter(MsgCode,MSGFLT_ADD);
::PostMessage(hwnd1,MsgCode,(WPARAM)1,(LPARAM)1);
DWORD errorcode = ::GetLastError();
从接收窗口选择的代码
BEGIN_MESSAGE_MAP(CMessageMailBox, CDialog)
ON_REGISTERED_MESSAGE(MsgCode, TextFromApp)
END_MESSAGE_MAP()
// Class Constructor
CMessageMailBox::CMessageMailBox(CWnd* pParent /*=NULL*/)
: CDialog(CMessageMailBox::IDD, pParent){
MsgCode = ::RegisterWindowMessage(_T("MESSAGE_CODING_STRING"));
::ChangeWindowMessageFilter(MsgCode,MSGFLT_ADD);
}
//Message Handler
afx_msg LRESULT CMessageMailBox::TextFromApp(WPARAM wParam,LPARAM lParam){
::MessageBox(NULL,L"message recieved",L"yea!",MB_OK);
return 0L;
}
I am pulling my hair out on this one. I am trying to send a message to a window in another process. I keep getting Access Denied (0x5) from GetLastError() after calling SendMessage or PostMessage or PostThreadMessage. I have tried turning off UAC. I have also accounted for UIPI by ensuring that the Integrity Levels match accross processes. (I checked with Process Explorer from SysInternals, now MS) I also turned off Windows Defender with no luck. I can send a message to the window from inside the process just fine, but from outside I get bupkus! This seems like some sort of security issue but I have no idea what it is as both processes have the same Integrity Level (medium - decimal 8192)
Code from DLL sending the message
UINT MsgCode = ::RegisterWindowMessage(_T("MESSAGE_CODING_STRING"));
::ChangeWindowMessageFilter(MsgCode,MSGFLT_ADD);
::PostMessage(hwnd1,MsgCode,(WPARAM)1,(LPARAM)1);
DWORD errorcode = ::GetLastError();
Selected Code from recieving Window
BEGIN_MESSAGE_MAP(CMessageMailBox, CDialog)
ON_REGISTERED_MESSAGE(MsgCode, TextFromApp)
END_MESSAGE_MAP()
// Class Constructor
CMessageMailBox::CMessageMailBox(CWnd* pParent /*=NULL*/)
: CDialog(CMessageMailBox::IDD, pParent){
MsgCode = ::RegisterWindowMessage(_T("MESSAGE_CODING_STRING"));
::ChangeWindowMessageFilter(MsgCode,MSGFLT_ADD);
}
//Message Handler
afx_msg LRESULT CMessageMailBox::TextFromApp(WPARAM wParam,LPARAM lParam){
::MessageBox(NULL,L"message recieved",L"yea!",MB_OK);
return 0L;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一定是消息吗? 有很多方法可以在不同进程之间进行通信:
Does it have to be a message? There are plenty of ways to communication between different processes:
看起来这是用户界面权限隔离 (UIPI) 的情况(即如果您的 DLL 被加载到另一个进程)
使用 ChangeWindowMessageFilterEx 在接收进程上。 我希望它能起作用
Looks like it is a case of User Interface Privilege Isolation (UIPI) (That is if your DLL is loaded to another process)
Use ChangeWindowMessageFilterEx on the receiving process. I hope it will work