Reputation: 5900
How can I create an instance of a class by its CLSID without knowing any of the interfaces it implements.
For example the CLSID "{3ad05575-8857-4850-9277-11b85bdb8e09}"
implements a class being derived from IFileOperation (in Windows 7), but if I didn't know that it derived from it, was there any way for create such object or at least find out which interfaces this CLSID implements ?
Thanks! :-)
Upvotes: 3
Views: 2138
Reputation: 941585
David is right, you can always ask for IUnknown. But you'll hit the wall from there, COM does not provide a way to discover implemented interfaces beyond this if you don't know an IID. Given the possible number of GUID values, there's no practical way to 'try them all'. Nor does it make a lot of sense, if you'd guess an IID correctly by chance, you still have no clue how to properly call the interface method. You don't know what arguments it takes, you don't know what it does. Beware IFormatDiskDrive.
A server that's Automation compatible usually provides a type library. You could dig the interfaces out of that. Not that you'd ever do, you let your compiler do that digging.
But with shell interfaces that are IUnknown based and thus don't implement Automation (like IFileOperation) you have to know what you want to use up front. Might as well pass that IID to CoCreateInstance right away.
Upvotes: 6
Reputation: 612993
I guess you could always just ask for IUnknown
and take it from there.
But I think your question is a bit confused and the way you use certain terminology makes me suspect your basic knowledge of COM is lacking somewhat.
Upvotes: 4