Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Marshaling a ActiveX so that i can PostMessage(..) from a 2nd Thread

Status
Not open for further replies.

Karl Blessing

Programmer
Feb 25, 2000
2,936
US
the following line always gives me an Invalid Page Fault<br>
<br>
PostMessage(pCtrl-&gt;m_hWnd,WM_THREADFIREEVENT,NULL,NULL);<br>
<br>
I read on a site somewhere, when trying to fire an event from a second thread, you need to <br>
1) CoInitialize() the thread firing the event<br>
2) Marshal the Interface fireing the event<br>
this would sound easy enough if i knew how to marshal the event<br>
<br>
here are the following that might help<br>
...<br>
CEvent PrintJob;<br>
CEvent PrintDie;<br>
/////////////////////////////////////////////////////////////////////////////<br>
// CVPNMixCtrl::CVPNMixCtrl - Constructor<br>
LONG ThreadProc(LPVOID pParam);<br>
CVPNMixCtrl::CVPNMixCtrl()<br>
{<br>
InitializeIIDs(&IID_DVPNMix, &IID_DVPNMixEvents);<br>
m_server.xnetclient = &m_client;<br>
m_server.PrintJob = &PrintJob;<br>
<br>
DWORD dwID;<br>
HANDLE threadHandle = CreateThread(NULL,NULL,(LPTHREAD_START_ROUTINE)ThreadProc,(LPVOID)this,NULL, &dwID);<br>
}<br>
(thats the constructor above of the main control, it starts the new thread, as you notice i have some pointers to CEvent object, the reason being, is when the m_server wants to fire an event, it triggers the CEvent, which causes the second thread to post a message to the control, so that it fires the event now to show you the actual thread)<br>
<br>
LONG ThreadProc(LPVOID pParam)<br>
{<br>
/*this set of stuff of Coinit.. and so on , i recently added<br>
hoping that it would fix my problems*/<br>
typedef HRESULT (__stdcall *FPCOMINITIALIZE)(void*, DWORD) ;<br>
FPCOMINITIALIZE pCoInitializeEx = <br>
reinterpret_cast&lt;FPCOMINITIALIZE&gt;(<br>
::GetProcAddress:):GetModuleHandle(&quot;ole32&quot;), &quot;CoInitializeEx&quot;)) ;<br>
HRESULT hr = pCoInitializeEx(0, 0x0) ;<br>
if (SUCCEEDED(hr))<br>
{<br>
CVPNMixCtrl *pCtrl = (CVPNMixCtrl*) pParam;<br>
HANDLE hLoopEvent[1];<br>
hLoopEvent[0] = PrintJob; hLoopEvent[1] = PrintDie;<br>
bool keeprunning = TRUE;<br>
while(keeprunning)<br>
{<br>
int result = ::WaitForMultipleObjects(2,hLoopEvent, FALSE, INFINITE); <br>
switch(result)<br>
{<br>
case 0:<br>
PostMessage(pCtrl-&gt;m_hWnd,WM_THREADFIREEVENT,NULL,NULL);<br>
PrintJob.ResetEvent();<br>
break;<br>
case 1:<br>
PrintDie.ResetEvent();<br>
keeprunning = FALSE;<br>
break;<br>
}<br>
}<br>
CoUninitialize() ;<br>
}<br>
return TRUE;<br>
}<br>
<br>
(ok this above, it sends the PostMessage, whcih is the line that gives me the IPF error, and now to show you the function that is run on the control itself when the Custom message is received)<br>
<br>
LRESULT CVPNMixCtrl::OnFireEventForThread(WPARAM wParam, LPARAM lParam)<br>
{<br>
FirePrintAval(); //The ActiveX FireEVent function<br>
return TRUE;<br>
}<br>
<br>
If you have any idea on how i can get pastt the PostMessage giving me a Invalid Page Fault, let me know, or better yet<br>
if you know how to get a function inside of m_server object to be able to link to the FirePrintAval() function, so that i dont have to loop around or create a second thread on top, that would be great too. <br>
<br>
<br>
<p>Karl<br><a href=mailto:kb244@bellsouth.net>kb244@bellsouth.net</a><br><a href= </a><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top