Groups | Blog | Home
all groups > dotnet interop > august 2003 >

dotnet interop : GetObject and C#


Magne Ryholt
8/28/2003 11:09:23 AM
I have a .exe application which exposes several COM
In VB 6.0 I can instantiate a class by using Set myClass = GetObject(path,
progid) where path is the path on harddisk to a file (actually a .INI file
in this case) and progid is the progid in registry.
The .exe was not running, but was started at the GetObject call and
This works fine.

Now I try to do the same in C#, but I cannot find out how.
I have tried using method GetObject in class Interaction of
assembly/namespace Microsoft.VisualBasic, but get an exception:
"An unhandled exception of type 'System.IO.FileNotFoundException' occurred
in microsoft.visualbasic.dll"
even if the strings for pathname and class (progid) are exactly the same in
the C# case as the VB 6.0 case (of course added @ before the path string to
interpret backslashes literally).

Are the strings interpreted differently between the VB 6.0 GetObject
function and Interaction.GetObject method ?

Is there a good way to do the same in C# without using Microsoft.VisualBasic
assembly ? (which is actually intended for backwards compatibility I
beleive).

Magne Ryholt
8/28/2003 2:17:11 PM
Vadim
Thanks for your answer.
I must admit that I know very little about monikers.
I guess that if the file has extension e.g. .XLS it would not be any problem
(because there is an association between XLS extension and the excel
program.
In my case i would bind to a .INI file and I don't want to make this kind of
association, so I also need to give some info about the object (class id,
prog id etc.)

Note that the .exe file (hosting the object I try to instantiate) is not
running prior to my calls, therefore cannot use GetActiveObject I guess.
Also note that I tried with the Microsoft.VisualBasic.Interaction.GetObject
(from C#), but got exception as mentioned before

Are you able to give me more specific help on how to use the BindToMoniker
method etc. in my case ?

I forgot to inform that in my C# project I set up a wrapper (RCW) to the exe
file (the exe file is also actually a "full" application with GUI etc.) by
reference in Visual Studio
When I tried (successfully) with VB 6.0, I also referred to the same exe
file in project references.
[quoted text, click to view]

Vadim Melnik
8/28/2003 2:29:16 PM
Hi,

[quoted text, click to view]

Does Marshal.BindToMoniker help? Also
Microsoft.VisualBasic.Interaction.GetObject static function is available for
C#, internally it uses the same
Marshal.BindToMoniker/Marshal.GetActiveObject API.

...
Regards,
Vadim.

AddThis Social Bookmark Button