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 / June 2005

Tip: Looking for answers? Try searching our database.

c# equivalent of __uuidof

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
John - 02 Jun 2005 11:04 GMT
Hi,

I'm porting a c++ test harness for a COM layer to c# to help extend my
knowledge of interop and c#.

I've got a quick question for which I have one answer using late
binding but it feels ugly and there must be a better way but I'm
failing to figure it out.

Anyway the problem:

I have some c++ code in which I need to know the GUID of the coclass of
a COM object.
In c++ this is trivial because of being able to use the __uuidof
function and the fact that the Coclass ID is exposed in the files that
MIDL generates.

Now when I attempt to translate this to c# using the interop assembly
that tlbimp.exe generates I run into a problem because the coclass
GUIDs are not exposed.

The best I have achieved so far is this:

IFoo TempFoo = new FooClass();
Type FooType = Type.GetTypeFromHandle(Type.GetTypeHandle( TempFoo ));
Guid FooCoclassID = FooType.GUID;

This feels so wrong and I know uses a)late binding and b) creates an
unnecessary COM object.

All the Interop resources I have read seem to define and interface or
coclass IDs by hand if they are used.  This strikes me as unwanton use
of "magic numbers" which makes me stamp my feet and shout "there must
be a better way"!

Any ideas?
John
John - 02 Jun 2005 11:41 GMT
Solved the problem using the typeof operator.

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.