3

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! :-)

2 Answers 2

6

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.

Sign up to request clarification or add additional context in comments.

2 Comments

It does make sense to query for IDispatch to see if the object is automation compatible. If it is you can then discover methods and properties using IDispatch. However even in this case you have no way of knowing all of the interfaces the object might support.
No, that still doesn't work. IDispatch::GetIdOfNames() lets you discover methods and properties. But that still requires having a name first. ITypeLib is available to discover type info. But requires a type library, covered in my answer.
4

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.