468,248 Members | 1,528 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,248 developers. It's quick & easy.

COM Server boject

Hi.
I would like to create an instance of a COM server from C# code.
I now use the System.Runtime.InteropServices.Marshal.GetActiveOb ject()
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!
Nov 16 '05 #1
3 1692
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]
- mv*@spam.guard.caspershouse.com

"znappa" <zn****@discussions.microsoft.com> wrote in message
news:ED**********************************@microsof t.com...
Hi.
I would like to create an instance of a COM server from C# code.
I now use the System.Runtime.InteropServices.Marshal.GetActiveOb ject()
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!

Nov 16 '05 #2
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 [.NET/C# MVP]" wrote:
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]
- mv*@spam.guard.caspershouse.com

"znappa" <zn****@discussions.microsoft.com> wrote in message
news:ED**********************************@microsof t.com...
Hi.
I would like to create an instance of a COM server from C# code.
I now use the System.Runtime.InteropServices.Marshal.GetActiveOb ject()
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!


Nov 16 '05 #3
Check if your server is running and start him using Process.Start if he
ain't.

Willy.

"znappa" <zn****@discussions.microsoft.com> wrote in message
news:B5**********************************@microsof t.com...
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 [.NET/C# MVP]" wrote:
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]
- mv*@spam.guard.caspershouse.com

"znappa" <zn****@discussions.microsoft.com> wrote in message
news:ED**********************************@microsof t.com...
> Hi.
> I would like to create an instance of a COM server from C# code.
> I now use the System.Runtime.InteropServices.Marshal.GetActiveOb ject()
> 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!


Nov 16 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Nathan Sokalski | last post: by
5 posts views Thread by Grim Reaper | last post: by
14 posts views Thread by Developer | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by kermitthefrogpy | last post: by
reply views Thread by zattat | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.