Hi,

if i get two class (CLS_ID) in my COM server, should i implement two class factory ?


there's must be a better solution to IClassFactory interface to
check a flag to create the suitable object ?


cheers,
Posted on 2002-02-21 12:53:31 by Sabeel
When the client needs a COM interface, it calls CoGetClassObject which in turn calls DllGetClassObject. Two parameters of both of these calls are the GUID of the class (CLSID) that supports this interface, and the GUID of the interface (IID) you need.

Thus, the dll code that creates the class factory has the information of which specific class factory to create, that is, a factory that makes classes with the matching CLSID.

You should test the CLSID passed in to see if it matches the classes your dll supports. You should NOT test the IID, since thats what QueryInterface is for. So IClassFactory creates a plain vanila class with some unknown interface, then QIs it for the required IID.

Hey, thats like creating an Unknown object that supports an IUnknown interface. Gee, I wonder if that is why the only thing you know for sure about an interface is named UNKNOWN.

How you do this test is up to you. Colib happens to use a tabulated list of ClassItem structures stuck together to form the ClassMap, each ClassItem contains a CLSID. So by walking the table, when a matching CLSID is found, all the info to create that class is available. For no matching CLSID, a fail code is returned.

Nothing is sacred about this method, you can write any implimentation you wish.
Posted on 2002-02-21 23:14:44 by Ernie
i know thoses little thinggies, what i want it's just to know if
i need to have two class factory.

i can always have a method named init(), or whatever else
in my classfactory called by DllgetClassObject(), it will pass the required CLSID, then the init() method will store this clsid, and
basing on that, the ClassFacorty will know which object it will
create.

all i want, is, if it wasn't another technique to do that ?
Posted on 2002-02-23 04:16:05 by Sabeel
That would work fine.
Posted on 2002-02-23 10:22:06 by Ernie