如何从带有ATL的ActiveX获取句柄 [英] How to get a HANDLE from a ActiveX with ATL

查看:104
本文介绍了如何从带有ATL的ActiveX获取句柄的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用vs2008(ATL9.0)项目开发一个ActiveX,该ActiveX不包含任何形式或控件.我想通过postmessagesendmessage从子流程向主流程发送消息,但是该功能需要主流程的句柄.我想获取主流程句柄,并使用 hCurrModul=GetModuleHandle(NULL);函数进行处理,但获取的值对possmessage无效.
我的基本代码:
添加消息图
xxxxctrl.h

I am developing an ActiveX with vs2008 (ATL9.0) project, the ActiveX didn''t contain any form or control. I want to send a message from a subprocess to the main process by postmessage or sendmessage, but the function needs a handle for the main process. I want to get the main process handle and I use hCurrModul=GetModuleHandle(NULL);function to process, but get the value is invalid to possmessage.
My base code :
Add the message map
xxxxctrl.h

#define WM_GETUII WM_APP+101 //operate success
.
.
BEGIN_MSG_MAP(CRMU9xCtrl)
      MESSAGE_HANDLER(WM_GETUII, OnGetUiiResult)
END_MSG_MAP()


.
.
子流程功能:


.
.
Subprocess function:

unsigned int __stdcall CRMU9xCtrl::threadReadUii(void * pThis)//
{
 for(int i=0;i<1000,i++)
 { 
    .....

 }
    HWND hwndMain =(HWND)pThis;  
    ::SendMessage(hwndMain,WM_GETUII,(WPARAM)0,sendMsg);
}



主进程开始线程:



Main process begin thread:

STDMETHODIMP CRMU9xCtrl::_RMUConnect(BSTR sPort, BYTE crcFlag, LONG* hCom)
{
 ...
hthread=(HANDLE)_beginthreadex(NULL, 0, &CRMU9xCtrl::threadReadUii, (LPVOID)this, 0, &threadID );
...
}



消息映射功能:



Message maping function:

OnGetUiiResult(UINT /*uMsg*/,WPARAM wParam, LPARAM lParam,BOOL& /*bHandled*/)
{
    this->Fire_onGetUii(tmp);
    return 0;
}

推荐答案

由于那里没有窗口,所以没有HWND.您需要执行什么操作才能使用PostThreadMessage.请参阅 http://msdn.microsoft.com/en-us/library/ms644946( VS.85).aspx [
Since there is no window there, there''s no HWND. What you need to do us to use PostThreadMessage. See http://msdn.microsoft.com/en-us/library/ms644946(VS.85).aspx[^]


我找到了解决该问题的解决方案.我使用cwindowimpl并创建了一个disvisibel窗口.来自子线程的句柄
I has found a solution to solve the quesstion.i use the cwindowimpl and creat a disvisibel windows .i post a message to the window''s handle from sub thread


这篇关于如何从带有ATL的ActiveX获取句柄的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆