Click here to Skip to main content
15,885,014 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
vc
#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;
}
Posted
Updated 3-Nov-10 0:43am
v2

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[^]
 
Share this answer
 
v2
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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900