Question Regarding RCW/COM Interop

F

Frank

IDE: Visual Studio 2005
Language: C#

I am making use of an older COM object in a C# project by adding a
reference to it in my project. I have no problems actually making use
of the COM library the same as is done by previous versions of
software written in unmanaged C++. The only difference is that this
time, I am trying to create multiple instances of the objects
available in the COM library via "new" in the same application (in my
case, the COM library gives me serial connectivity to a specialized
piece of hardware, currently multiple instances of a program are run
to connect multiple pieces of hardware, I would like to connect
multiple instances to the same piece of software). I believe I am only
getting references to an already existing instance, and not a wholly
new and separate object.

In doing some research over the past few days I've discovered that
creating new instances of objects available in my COM library from C#
has the underlying effect of calling CoCreateInstance;
http://msdn.microsoft.com/en-us/library/aa645736(VS.71).aspx, see the
first paragraph of "Creating a COM Object". It is my understanding
that CoCreateInstance will not create a wholly new instance of an
object unless one doesn't exist, and gives the caller a reference to
that object. If one exists then it just passes back a reference to the
currently existing. Am I incorrect in my understanding here?

Is there a way to create new and separate instances of the objects in
my COM library from C#? I guess this would be like calling
CoGetClassObject to create separate instances. Does anyone have any
suggestions?
 
N

not_a_commie

Is your COM object multithreaded (MTA) or single threaded (STA)? Have
you tried creating objects each in their own thread?
 
F

Frank

Is your COM object multithreaded (MTA) or single threaded (STA)? Have
you tried creating objects each in their own thread?

Thanks! It appears that I can create multiple separate instances of
the same object type in the COM library when putting each off into
their own thread, but I haven't yet confirmed that it works correctly.
If I start one and let it connect, then start the other and let it
connect, from what I'm seeing in the serial line capture file the
library creates, both are connected and communicating, but if I try
starting them both up at the same time or close to the same time, then
only the latter one started actual makes a connection. I have some
more testing to do and some serial port monitoring to go in depth
with, but you've definitely got me off to the right start! Thanks
again!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top