Select and attach to specific COM EXE instance as COM object

J

Jon Davis

I am working with an application that is compiled as a COM EXE (written in
Delphi 7). I don't know if it's the nature of COM EXE or if it's implemented
in the COM EXE, but when I create a new object based on the COM interface
using C#, it references the first process/instance it finds of this
interface. This is not ideal for me; I would like to create a modal dialog
box that makes the user select which process to "attach" to. Getting a list
of processes isn't a problem, rather it's getting my COM references in the
C# RCW of the COM interface to attach to the preferred COM EXE rather than
the first one it finds.

I asked the developer of the app as to how to "select" which COM instance
you're attaching to, but he said he was busy and hasn't gotten back to me.
However, I tend to believe that this is something that is pretty generic to
COM EXEs, and I was hoping someone out there might know and could give me a
tip on this?

Thanks,
- Jon
 
A

Alvin Bruney - ASP.NET MVP

i don't think that is the case, that sounds like internal code making sure
that there is only one instance. however, without source, i'm just taking a
stab in the dark so you should take that with a large dose of rock salt.

--
Warm Regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The Microsoft Office Web Components Black Book with .NET
Now Available @ www.lulu.com/owc
Professional VSTO 2005 - Wrox/Wiley 2006
Blog: http://msmvps.com/blogs/Alvin/
 
B

Brian Muth

You are confusing COM object instances with COM executable instances. They
are different.

Generally speaking, each client will be allocated their own COM object
whenever they call CoCreateInstance(Ex). Usually the same COM executable
will act as host for all those COM object instances. For obvious reasons,
this is usually desirable for efficiency reasons. There are exceptions to
this scenario. For example, if there are two clients running under different
user accounts and the COM Server executable is set up to run as the
launching user, then COM services will start a second executable in order to
establish a separate security boundary.

There is no direct support from COM to do what you are asking for. However,
I suspect there is a clever way of implementing this (with some considerable
research on your part if you haven't done this before) by building a custom
class factory.

To carry this discussion further, I think it would be helpful if you would
explain why there are multiple COM executables, how this was configured and
why. I suspect there may be a cleaner design and a better solution at hand
if you explained more.

Brian
 
W

Willy Denoyette [MVP]

You can bind to a specific instance using the IRunningObjectTable & IMoniker
interfaces, see using System.Runtime.InteropServices.ComTypes; in MSDN
(version 2 of the Framework!).

Willy.

|I am working with an application that is compiled as a COM EXE (written in
| Delphi 7). I don't know if it's the nature of COM EXE or if it's
implemented
| in the COM EXE, but when I create a new object based on the COM interface
| using C#, it references the first process/instance it finds of this
| interface. This is not ideal for me; I would like to create a modal dialog
| box that makes the user select which process to "attach" to. Getting a
list
| of processes isn't a problem, rather it's getting my COM references in the
| C# RCW of the COM interface to attach to the preferred COM EXE rather than
| the first one it finds.
|
| I asked the developer of the app as to how to "select" which COM instance
| you're attaching to, but he said he was busy and hasn't gotten back to me.
| However, I tend to believe that this is something that is pretty generic
to
| COM EXEs, and I was hoping someone out there might know and could give me
a
| tip on this?
|
| Thanks,
| - Jon
|
|
 
J

Jon Davis

You are confusing COM object instances with COM executable instances. They
are different.

Not at all; C# sees the COM interface, wrapped in the CLR, as an object. I
think you might be confusing my special use of "COM object" with COM
components or server instances.
There is no direct support from COM to do what you are asking for.
However, I suspect there is a clever way of implementing this (with some
considerable research on your part if you haven't done this before) by
building a custom class factory.

If you're certain that COM doesn't support this without hacks then I will
stop researching this.
To carry this discussion further, I think it would be helpful if you would
explain why there are multiple COM executables, how this was configured
and why. I suspect there may be a cleaner design and a better solution at
hand if you explained more.

It's just a shrink-wrapped business application, compiled as an ActiveX EXE,
that supports Active Scripting and I was extending it with .NET by running
my own .NET process and accessing the EXE's COM interfaces. The application
supports multiple instances though--this is useful because each one can
point to a different database or log in as a different user--but the .NET
process I built can only "see" the first one.

I was also trying to "hook" into its interfaces from the Active Scripting
environment using the COM interfaces, but with multiple processes running,
the second instance's script would be confusing its host's COM interface
with the first process.

- Jon
 
J

Jon Davis

There is no direct support from COM to do what you are asking for.
However, I suspect there is a clever way of implementing this (with some
considerable research on your part if you haven't done this before) by
building a custom class factory.

If you're certain that COM doesn't support this without hacks then I will
stop researching this.
To carry this discussion further, I think it would be helpful if you would
explain why there are multiple COM executables, how this was configured
and why. I suspect there may be a cleaner design and a better solution at
hand if you explained more.

It's just a shrink-wrapped business application, compiled as an ActiveX EXE,
that supports Active Scripting and I was extending it with .NET by running
my own .NET process and accessing the EXE's COM interfaces. The application
supports multiple instances though--this is useful because each one can
point to a different database or log in as a different user--but the .NET
process I built can only "see" the first one.

I was also trying to "hook" into its interfaces from the Active Scripting
environment using the COM interfaces, but with multiple processes running,
the second instance's script would be confusing its host's COM interface
with the first process.

- Jon
 
B

Brian Muth

It's just a shrink-wrapped business application, compiled as an ActiveX
EXE, that supports Active Scripting and I was extending it with .NET by
running my own .NET process and accessing the EXE's COM interfaces. The
application supports multiple instances though--this is useful because
each one can point to a different database or log in as a different
user--but the .NET process I built can only "see" the first one.

I'm still confused. Define what you mean by the last phrase: "... the .NET
process can only "see" the first one."

The first what? EXE? or COM instance?

As I said before, you should only have one EXE but that EXE can host
multiple COM instances.

Brian
 
J

Jon Davis

Brian Muth said:
I'm still confused. Define what you mean by the last phrase: "... the .NET
process can only "see" the first one."

The first what? EXE? or COM instance?

Process. (EXE instance.)
As I said before, you should only have one EXE but that EXE can host
multiple COM instances.

As I said before, there already are multiple EXE instances, and third party
EXEs and COM objects must talk to them individually; I'm trying to figure
out how. Come to think of it I think I can implement what I need using
Remoting or Indigo; fortunately, each EXE instance is scriptable.

Jon
 
J

Jon Davis

Willy,

These are interfaces; does the app need to implement these as a starting
point in order to allow for the functionality I seek?

I am not on the dev team that built the app, so that won't work for me. I
suppose I will have to pursue other avenues (remoting, etc), unless you can
assist me further.

Thanks,
Jon
 

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