Hello. I have had peripheral experience with various COM technologies over the years, and I'ver never been comfortable with the motivation for having "class factories" (better referred to as object factories). I understand that they are used to create instances of COM classes but why are they really necessary...what problem do they solve? The reason usually given is that it protects the client from having to know how to construct an instance of a COM class...the client just has to call the well-known method on the IClassFactory of the object factory instance. That's fine but the client still has to know how to construct an instance of the class factory! So it seems to me it just pushes the problem back one level. If a client wants an instance of a particular COM class, it still has to know how to create _some_ COM object specific to the COM class of which it wants an instance. Can anyone enlighten me? Thanks, Dave
Hi Dave, > That's fine but the client still has to know how to construct an > instance of the class factory! So it seems to me it just pushes the > problem back one level. If a client wants an instance of a particular > COM class, it still has to know how to create _some_ COM object > specific to the COM class of which it wants an instance. Class factories are necessary for out-of-process servers. On startup, an out-of-process server registers factories for objects it can create in a system-global table using CoRegisterClassObject. Then, whenever a client does CoGetClassObject for a CLSID, the COM run-time can look it up in said table, and return the factory instance. I guess it works the same way for in-proc servers for symmetry. -- Best Regards, Kim Grsman
Hmm, well that explains that...thanks. I really wish COM books/websites/etc would simply state that rather than trying to present object factories as useful in and of themselves...especially since those books/websites/etc typically start with inproc examples.
Hello Dave, > I really wish COM books/websites/etc would simply state that rather > than trying to present object factories as useful in and of > themselves...especially since those books/websites/etc typically start > with inproc examples. I agree, I didn't get it until last year. DllGetClassObject just seems roundaboutish until you think about CoRegisterClassObject. Also, I think one reason inproc servers use the same mechanism is to allow them to be hosted by surrogate processes. -- Best Regards, Kim Grsman