CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    May 1999
    Posts
    1

    Multithreading in DCOM - Urgent!! Urgent!!

    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


  2. #2
    Join Date
    May 1999
    Posts
    19

    Re: Multithreading in DCOM - Urgent!! Urgent!!

    I used the funcion CoGetInterfaceAndReleaseStream to unmarshall the interface and release the stream... you might give that a try.

    -- Matt


  3. #3
    Guest

    Re: Multithreading in DCOM - Urgent!! Urgent!!

    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([email protected])


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured