0

Long story short, trying to build a 'Smoke Tester' application. I'd like to be able to dynamically be given "Hey, this COM assembly (guid, progid) should exist" and attempt to create the COM object via ProgId or guid.

I know how to [ComImport] classes, but instead I'm looking to do this programatically. Is this possible?

John
  • 921
  • 1
  • 9
  • 24
  • It is *only* possible to create them programmatically. What on Earth are you asking? You specify the CLSID guid *or* the ProgId, not both. Use Activator.CreateInstance(), passing the type returned by either Type.GetTypeFromProgID() or Type.GetTypeFromCLSID(). Do try to avoid "System.ReformatDisk", if you don't know what it does then it probably does something you don't want. – Hans Passant Apr 20 '17 at 16:25
  • ROFL - I meant that I'd like to create from GUID *or* ProgID, depending upon what is handed to me via the interface. GetTypeFromProgID + CreateInstance is what I was looking for, thanks! – John Apr 20 '17 at 16:32

1 Answers1

4

Call Activator.CreateInstance(Type.GetTypeFromProgID("progid")) (or Type.GetTypeFromCLSID).

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964