Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / August 2003

Tip: Looking for answers? Try searching our database.

GetObject and C#

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Magne Ryholt - 28 Aug 2003 10:09 GMT
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).
Vadim Melnik - 28 Aug 2003 12:29 GMT
Hi,

> I have a .exe application which exposes several COM
> In VB 6.0 I can instantiate a class by using Set myClass = GetObject(path,
> ...
> Now I try to do the same in C#, but I cannot find out how.

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.
Magne Ryholt - 28 Aug 2003 13:17 GMT
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.
> Hi,
>
[quoted text clipped - 11 lines]
> Regards,
> Vadim.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.