You could query for IPersist
, and GetClassID on it.
That gets you the CLSID
. Then call ProgIDFromCLSID:
The pinvoke declaration is here.
That gets you the ProgID.
EDIT:
To query for an interface, you just do a cast in C#:
IPersist p = myObj as IPersist;
if (p != null)
{
// phew, it worked...
}
Behind the scenes, this is what is actually happening, as shown here in C++:
IUnknown *pUnk = // ... get object from somewhere
IPersist *pPersist = 0;
if (SUCCEEDED(pUnk->QueryInterface(IID_IPersist, (void **)&pPersist)))
{
// phew, it worked...
}
(But no one bothers with writing that stuff by hand these days, as a smart pointer can pretty much simulate the C# experience.)