Those still using COM know that COM components must be registered in the Windows Registry to be workable. Sometimes this may not be acceptable. Sometimes you might want to run an application that may be using many COM DLLs, but don’t want or can’t (because of some policies) to register the components. Sometimes you want to run an application on some client’s machine without any setup. Can this be done? Off the bat, that seems impossible. But there is actually a way.
What I’ve done in a project (it was done a few years back) was this: when the main executable runs, it registers itself as a COM surrogate using ::CoRegisterSurrogate. After that it walks a list of all CLSIDs that are expected, loads the corresponsing DLL using the usual ::LoadLibrary and calls ::CoRegisterClassObject with a generic class factory and the REGCLS_SURROGATE flag. this makes the generic class factory (a simple class implementing IClassFactory) the universal creator.
Now, every time some code (in the EXE or in another DLL!) calls the usual ::CoCreateInstance (or CComPtr<> equivalents, or even a VB DLL calling CreateObject or New), the generic class factory returns the correct instance based on the requested CLSID.
I have used this method successfully for my company’s purpose – send demo CDs that require no installation and no registration.
If anyone is interested in the actual code, let me know and I’ll post it.
Like Don Box said: “COM is Love!” , but (I add) “sometimes a surrogate is needed”