Board index » cppbuilder » Creating COM objects from COM objects, in threads

Creating COM objects from COM objects, in threads

Hi,

I have a number of COM objects. One COM object, which is to be created
from the Client app, creats a thread which needs to create a number of
another  COM objects. These objects must be accessible from the creating
thread and the main thread, once an interface pointer is obtained.

Do I use CoCreateInstance?  if so how? This fails. What threading models
should I use.

Thanks

Mike

 

Re:Creating COM objects from COM objects, in threads


You probably want to use the free threading. With it you don't need to
marshal interface pointers between threads. But the components have to
be careful ( as in multithread-safe )

Alex

Quote
Michael Harrison wrote:

[snip]

Re:Creating COM objects from COM objects, in threads


If you are creating the additional thread in your COM server, you need to
call CoInitiliazeEx(...)
in your new thread before attempting to create your helper COM objects in
that thread.

Unless you can be absolutely sure all your objects will run in the main STA,
(which is not likely), or all your objects run in the MTA, you will need to
marshal the interface pointers across to the calling thread.

If you need further information on how to do this, you can peruse the atl
newsgroup FAQ
which contains great information on threading issues.

Hope this helps you get started.

Quote
Michael Harrison <Mike.Harri...@datong.co.uk> wrote in message

news:38E47B6B.66245951@datong.co.uk...
Quote
> Hi,

> I have a number of COM objects. One COM object, which is to be created
> from the Client app, creats a thread which needs to create a number of
> another  COM objects. These objects must be accessible from the creating
> thread and the main thread, once an interface pointer is obtained.

> Do I use CoCreateInstance?  if so how? This fails. What threading models
> should I use.

> Thanks

> Mike

Other Threads