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 ,WPARAM wParam, LPARAM lParam,BOOL& )
{
this->Fire_onGetUii(tmp);
return 0;
}