Get CLSID by PIA interface Type
Posted
by Charles
on Stack Overflow
See other posts from Stack Overflow
or by Charles
Published on 2010-04-14T02:32:39Z
Indexed on
2010/04/14
2:43 UTC
Read the original article
Hit count: 531
How can I get the CLSID for a given interface within a Primary Interop Assembly? Here's what I'm talking about:
// The c# compiler does some interesting magic.
// The following code ...
var app = new Microsoft.Office.Interop.Outlook.Application();
// ... is compiled like so (disassembled with Reflector):
var app =((Microsoft.Office.Interop.Outlook.Application)
Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid("0006F03A-0000-0000-C000-000000000046"))));
Microsoft.Office.Interop.Outlook.Application
is an interface, and therefore it cannot be instantiated directly. What's interesting here is that c# lets you treat these COM interfaces as if there where classes that you can instantiate with the new
keyword.
What I want to know is, given the System.Type
for a given interface, how can I get the CLSID?
Note: I ultimately want to be able to create an instance given the interface's System.Type
- I don't really care how. I'm assuming here that the easiest way to do this would be to get CLSID given the Type, just as the c# compiler does.
© Stack Overflow or respective owner