0

We have a rather old COM-like component wuth a set of rather complex interfaces. Those interfaces are quite problematic to marshal, so we don't register anything in registry but instead export a CreateMainObject() function from the component DLL that retrieves a IMainObject pointer and IMainObject interface has a huge set of other functions.

This way the client never calls CoCreateInstance()- instead it calls LoadLibraryEx()/GetProcAddress() and then invokes CreateMainObject() function. No marshalling can ever be done since COM doesn't actually enter the scene - all actions are performed by directly calling methods on those objects. Everything is very fast but of course not thread-safe and wn't work in a COM+ surrogate.

Is there a term for such usage of COM interfaces?

1 Answer 1

1

The term you seek is "incorrect", as in "This is an incorrect usage of COM interfaces".

Why not register ICreateMainObject derived from IUnknown (or IDispatch if you prefer) with one method, ICreateMainObject::CreateMainObject, then use this method to instantiate your object using valid COM semantics.

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

4 Comments

That's a bit harsh, isn't it? I don't think there's anything in the COM spec which says you have to use the COM registry. Nor does he describe anything which implies any violation of COM semantics, as far as I can see.
@Chris Dickson: First, if the client uses DLL entry points, why not go all the way and make a .h/.lib pair and use the DLL as a dynamic library, why add COM overhead? Second, how are other clients supposed to use the class, like .Net interrop? And finally: where is the COM infrastructure set up? Who calls CoInitializeEx and CoInitializeSecurity in this model? Is the object an STA or an MTA? Do the interfaces need to be marshaled between threads or not? How are new versions of the IMainObject discovered at runtime? Does this arrangement work with SxS?
@Chris Dickson: not to mention that proper registration-free COM and Activation already exists: msdn.microsoft.com/en-us/library/ms973913.aspx
I'd agree it's arguable he's not really using COM at all... but I assumed he meant he was just using COM IUnknown AddRef/Release/QI paradigm to dynamic link via interface vtables and control object lifetime rather than create a tighter binary coupling a la .h/.lib. He seems to have accepted that he can't get the benefit of any of the COM services like apartment thread-safety/remoting/security context propagation. He was just looking for a name for his model & I thought your response a bit patronising.

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.