dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: COM General Question

  1. #1
    Join Date
    Nov 2019
    Posts
    2

    Question COM General Question

    Hello Gurus!

    I'm new to threaded COM in VC++ and have been reading up on it. I haven't yet found a site that generally describes what to call from which thread (main or worker) in what order. Please correct where I have misunderstood:

    Main Thread
    1) Begin the worker thread suspended with AfxBeginThread(...,CREATE_SUSPENDED).
    2) Call CoMarshalInterThreadInterfaceInStream( pTheCOMIID,(IUnknown*)pPointerToTheCOMObject, &(pPointerToMyIStream) );
    3) Resume the Thread to get it started.

    Worker Thread (when started)
    4) Call CoInitialize( NULL );
    5) Call CoGetInterfaceAndReleaseStream( pPointerToMyIStream, pTheCOMIID,(void**)nullPointer );
    6) Let the worker thread complete...
    7) Call CoUninitialize();

    Is this generally correct or am I doing things out of order and/or missing some important steps (including cleanup)? I'm pretty well grounded in threading but COM is still new to me, so any guidance is appreciated. Thanks!

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,176

    Re: COM General Question

    Nit sure what you are trying to do. Are you trying to call a COM object from a client app?

  3. #3
    Join Date
    Feb 2017
    Posts
    483

    Re: COM General Question

    Quote Originally Posted by mjxnjx2019 View Post
    I'm new to threaded COM in VC++ and have been reading up on it.
    Note that concurrency is part of the C++ language since version 11. It means you don't need to utilize OS specific subsystems to write concurrent applications unless that's what you want of course.

  4. #4
    Join Date
    Nov 2019
    Posts
    2

    Re: COM General Question

    Quote Originally Posted by Arjay View Post
    Nit sure what you are trying to do. Are you trying to call a COM object from a client app?
    Yes, I am trying to connect to a COM object, but No, this is not a client app. The COM object is a third-party webservice that is listening for requests from the client apps. Whenever a new request comes in the "Server App" (which is what I am working on) shows whom has connected and what data they passed. It's sort of like a dashboard if you want to think of it that way.

    Would the order of commands I have described be correct in this scenario?

  5. #5
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,176

    Re: COM General Question

    Quote Originally Posted by mjxnjx2019 View Post
    Yes, I am trying to connect to a COM object, but No, this is not a client app. The COM object is a third-party webservice that is listening for requests from the client apps. Whenever a new request comes in the "Server App" (which is what I am working on) shows whom has connected and what data they passed. It's sort of like a dashboard if you want to think of it that way.

    Would the order of commands I have described be correct in this scenario?
    By your use of CoMarshalInterThreadInterfaceInStream, it looks like you are creating the COM object in one thread and attempting to use it in another thread.

    If that is the case, i would simplify things by either 1) creating the COM object in the main thread or 2) creating the COM object in the worker thread.

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)