.Net COM Interop

G

Guest

Is there an equivalent function of __uuidof(IMyIface) in COM interop support
library that would let me extract the GUID of an Interface exposed via COM
interop in C# ??
 
N

Nicholas Paldino [.NET/C# MVP]

Rahul,

No, there isn't, but you can easily write a simple function which will
get the ID from the interface. The type itself should be decorated with the
Guid attribute.

So, once you get the Type instance for the interface, you can call
GetCustomAttributes, passing the type of the GuidAttribute, and then once
you get the return value, you can get the Value property of the attribute to
get the string version of the Guid (which you can then convert to a Guid
instance).
 
J

John Duval

Is there an equivalent function of __uuidof(IMyIface) in COM interop support
library that would let me extract the GUID of an Interface exposed via COM
interop in C# ??

Hi Rahul,
You can get the GuidAttribute:

Attribute[] attribs =
Attribute.GetCustomAttributes(typeof(IMyInterface),
typeof(GuidAttribute));
GuidAttribute guid = attribs[0] as GuidAttribute;
// guid.Value contains your result

John
 
M

Mattias Sjögren

Hi Rahul,
You can get the GuidAttribute:

Attribute[] attribs =
Attribute.GetCustomAttributes(typeof(IMyInterface),
typeof(GuidAttribute));
GuidAttribute guid = attribs[0] as GuidAttribute;
// guid.Value contains your result


Or just check typeof(IMyInterface).GUID - less typing :)


Mattias
 
J

John Duval

Hi Rahul,
You can get the GuidAttribute:
Attribute[] attribs =
Attribute.GetCustomAttributes(typeof(IMyInterface),
typeof(GuidAttribute));
GuidAttribute guid = attribs[0] as GuidAttribute;
// guid.Value contains your result

Or just check typeof(IMyInterface).GUID - less typing :)

Mattias

Typing builds character. :)

Thanks, I didn't know about that one. I didn't expect Type to have a
GUID property, but there it is!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top