PC Review


Reply
Thread Tools Rate Thread

COM Server boject

 
 
=?Utf-8?B?em5hcHBh?=
Guest
Posts: n/a
 
      10th Feb 2005
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!
 
Reply With Quote
 
 
 
 
Nicholas Paldino [.NET/C# MVP]
Guest
Posts: n/a
 
      10th Feb 2005
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 Removed)

"znappa" <(E-Mail Removed)> wrote in message
news:ED406A16-7627-4716-95F9-(E-Mail Removed)...
> 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!



 
Reply With Quote
 
=?Utf-8?B?em5hcHBh?=
Guest
Posts: n/a
 
      10th Feb 2005
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]
> - (E-Mail Removed)
>
> "znappa" <(E-Mail Removed)> wrote in message
> news:ED406A16-7627-4716-95F9-(E-Mail Removed)...
> > 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!

>
>
>

 
Reply With Quote
 
Willy Denoyette [MVP]
Guest
Posts: n/a
 
      10th Feb 2005
Check if your server is running and start him using Process.Start if he
ain't.

Willy.

"znappa" <(E-Mail Removed)> wrote in message
news:B58C3FA1-E47F-46D0-BB99-(E-Mail Removed)...
> 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]
>> - (E-Mail Removed)
>>
>> "znappa" <(E-Mail Removed)> wrote in message
>> news:ED406A16-7627-4716-95F9-(E-Mail Removed)...
>> > 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!

>>
>>
>>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
An error has occurred while establishing a connection to the server.When connecting to SQL Server 2005, this failure may be caused by the factthat under the default settings SQL Server does not allow remote connections. mina Microsoft VB .NET 0 8th Oct 2008 07:12 AM
An error has occurred while establishing a connection to the server.When connecting to SQL Server 2005, this failure may be caused by the factthat under the default settings SQL Server does not allow remote connections. mina Microsoft Dot NET 0 8th Oct 2008 07:11 AM
Help. Getting a An error has occurred while establishing a connectionto the server. When connecting to SQL Server 2005, this failure may be causedby the fact that under the default settings SQL Server does not allow remote aboutjav.com@gmail.com Microsoft ASP .NET 0 3rd May 2008 01:43 PM
Mirroring a Windows 2000 Server so that the backup server takes over when the main server fails Karl Strausser Microsoft Windows 2000 Setup 1 28th Sep 2005 01:43 AM
How do i change this connect string to support a SQL Server 2000 running on port 8832 User ID=car;Password=rat;Server=abc.def.hij;Initial Catalog=foobar i tried Server=abc.def.hij:8823 and Server=abc.def.hij;port=8823 neither of these work Daniel Microsoft Dot NET Framework 1 16th Dec 2004 09:55 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:29 PM.