Click to See Complete Forum and Search --> : Multithreading in DCOM - Urgent!! Urgent!!


S P Shukla
May 7th, 1999, 02:27 AM
Please help me urgently --


Server:
I have a STA DCOM Server with an interface say IServer which export a method say StartPlay().

Client:

Now I would like to call this method in two threads, but failed. The way I am doing is like this -

MyProject()
{
// Store the interface pointer in m_pServer from calling CoCreateInstanceEx()
HRESULT hRes = CoMarshalInterThreadInterfaceInStream(IID_IServer, m_pServer, (LPSTREAM *) & m_pStream);

// Create the thread two times
for(int i=0; i<2; i++)
{
CreateThread(NULL, 0, StartPlayWrapper, NULL, 0, &dwThreadID);
}

}

StartPlayWrapper()
{
HRESULT hRes = CoInitialize(NULL);
IServer *pServer = NULL;
hRes = CoUnMarshalInterface( m_pStream, IID_IServer, (void **)&pServer);

// Till here no problem comes, but calling the StartPlay() method is not envoking.
// No Error message comes

pServer->StartPlay(); // Ignore this statament while debugging.
}
I am releasing the stream.

Could any of you please help me to encounter this problem?? Its very urgent for me.
The document says to use Messageloop. What's should be do to come out from this problem.

Thanks in advanced
Shukla

mdwilliams
May 7th, 1999, 09:42 AM
I used the funcion CoGetInterfaceAndReleaseStream to unmarshall the interface and release the stream... you might give that a try.

-- Matt

May 10th, 1999, 07:51 PM
hi,
The call to unmarshall will fail for the second thread because u are using a single stream for storing the marshalled pointer and passing the same stream to both the threads.try this one...

MyProject()
{
// Create the thread two times
for(int i=0; i<2; i++)
{
HRESULT hRes = CoMarshalInterThreadInterfaceInStream(IID_IServer, m_pServer, (LPSTREAM *) & m_pStream);
CreateThread(NULL, 0, StartPlayWrapper,m_pStream, 0, &dwThreadID);
}
}
DWORD StartPlayWrapper(LPVOID lpVoid)
{
HRESULT hRes = CoInitialize(NULL);
IServer *pServer = NULL;
hRes = CoUnMarshalInterface((IStream*)lpVoid, IID_IServer, (void **)&pServer);

// Till here no problem comes, but calling the StartPlay() method is not envoking.
// No Error message comes

pServer->StartPlay(); // Ignore this statament while debugging.
}
-RajM(MohanR@bsci.com)