如何从带有ATL的ActiveX获取句柄

如何从带有ATL的ActiveX获取句柄

本文介绍了如何从带有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;
}

推荐答案



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

08-19 14:45