积极答复者
SendMessage返回1400错误(无效的窗口句柄)

问题
-
进程A和B都需要向进程C通过WM_COPYDATA发送消息,C的句柄HWND在启动时存储于数据中以供A和B获取。
A和B发送消息方法如下
LRESULT result = ::SendMessage(hProxyWnd, WM_COPYDATA, (WPARAM) 0, (LPARAM) &strctToPass);
但是A能够顺利将信息发送到C,但是B却不能,通过WSAGetLastError ()发现返回的都是1400错误代码,即无效的窗口句柄,但是B的句柄和A获取的是一模一样的,为何A能发送成功而B不能?
这个问题比较挠头,大家有没有比较好的思路来调试/解决这个问题。
不胜感激!
答案
-
任务管理器里面可以看到,sessionID列默认不显示,需要手动添加
The following is signature, not part of post
Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
Visual C++ MVP- 已标记为答案 Eazhang 2010年9月2日 6:40
全部回复
-
HWND只在当前session有效。检查你的进程是否在同一个桌面。
The following is signature, not part of post
Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
Visual C++ MVP -
用GetLastError看看,WSAGetLastError 是socket的,和你的问题没关系
The following is signature, not part of post
Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
Visual C++ MVP -
服务和桌面程序不是在一个桌面上,你不能在桌面程序和服务程序之间共享窗口句柄。用RPC、Socket、命名管道之类可以跨session的通讯方式吧。
The following is signature, not part of post
Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
Visual C++ MVP -
可能可以,取决于桌面应用程序的session是不是和服务的session一致。
The following is signature, not part of post
Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
Visual C++ MVP -
嗯,如果是第一个从物理终端登录的用户的话,是的
The following is signature, not part of post
Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
Visual C++ MVP -
HWND只在当前session有效。同一个用户可以登录多个session。
The following is signature, not part of post
Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
Visual C++ MVP -
任务管理器里面可以看到,sessionID列默认不显示,需要手动添加
The following is signature, not part of post
Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
Visual C++ MVP- 已标记为答案 Eazhang 2010年9月2日 6:40