COM Server boject

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi.
I would like to create an instance of a COM server from C# code.
I now use the System.Runtime.InteropServices.Marshal.GetActiveObject()
function to get the running instance (but this implies that there is an
instance running). But I would like to check (at the start of my code) wether
there is a running instance and if not, start one. I'm not to familiar with
COM, so "best practise" hints would be nice!
 
znappa,

In order to do this, you are going to have to check the running object
table of the machine. The running object table is a list of com servers
that are identified with a unique moniker (name).

In order to get the running object table, you will have to define the
GetRunningObjectTable function so that you can call it through the P/Invoke
layer. Once you call that, it should return (through a parameter) an
implementation of UCOMIRunningObjectTable, an interface found in the
System.Runtime.InteropServices namespace. You can then call GetObject on
that interface to get an object based on its name.

Hope this helps.
 
Thanks for your reply, but how do I start an instance of the COM server (if
it's not in the ROT)? When I declare an instance of the object in my C# code,
this object want show up in the ROT, and then I can't use GetActiveObject().
Is there a way to start the COM server object so it will show up in the ROT?

Nicholas Paldino said:
znappa,

In order to do this, you are going to have to check the running object
table of the machine. The running object table is a list of com servers
that are identified with a unique moniker (name).

In order to get the running object table, you will have to define the
GetRunningObjectTable function so that you can call it through the P/Invoke
layer. Once you call that, it should return (through a parameter) an
implementation of UCOMIRunningObjectTable, an interface found in the
System.Runtime.InteropServices namespace. You can then call GetObject on
that interface to get an object based on its name.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

znappa said:
Hi.
I would like to create an instance of a COM server from C# code.
I now use the System.Runtime.InteropServices.Marshal.GetActiveObject()
function to get the running instance (but this implies that there is an
instance running). But I would like to check (at the start of my code)
wether
there is a running instance and if not, start one. I'm not to familiar
with
COM, so "best practise" hints would be nice!
 
Check if your server is running and start him using Process.Start if he
ain't.

Willy.

znappa said:
Thanks for your reply, but how do I start an instance of the COM server
(if
it's not in the ROT)? When I declare an instance of the object in my C#
code,
this object want show up in the ROT, and then I can't use
GetActiveObject().
Is there a way to start the COM server object so it will show up in the
ROT?

Nicholas Paldino said:
znappa,

In order to do this, you are going to have to check the running
object
table of the machine. The running object table is a list of com servers
that are identified with a unique moniker (name).

In order to get the running object table, you will have to define the
GetRunningObjectTable function so that you can call it through the
P/Invoke
layer. Once you call that, it should return (through a parameter) an
implementation of UCOMIRunningObjectTable, an interface found in the
System.Runtime.InteropServices namespace. You can then call GetObject on
that interface to get an object based on its name.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

znappa said:
Hi.
I would like to create an instance of a COM server from C# code.
I now use the System.Runtime.InteropServices.Marshal.GetActiveObject()
function to get the running instance (but this implies that there is an
instance running). But I would like to check (at the start of my code)
wether
there is a running instance and if not, start one. I'm not to familiar
with
COM, so "best practise" hints would be nice!
 
Back
Top