COM dll versus plain dll with function exports

Although Microsoft pushed .Net very hard these years, I have not notice any major OS enhancemennts are based on .Net assembly.

Windows Installer is based on DLL.
GDI+, XML parser, DirectX are based on COM.

I tend to believe that Vista UI is based on DLL, but I am not sure. All these are managed code.

COM is nice when building large application consisting of more than a dozen of objects. COM provides nice methods to handle events - otherwise you have to use callbank in a DLL function. When well done, COM provides much better glues between objects.

That being said, COM has a number of issues. The bigest problem is that the learn curve is pretty deep. COM and DLL is like C++ and C.

===========================================

If you have to use Windows and C++, COM is definitely better than C style DLL's if your app is large and complex (i.e. multiple man-years) and you expect it to grow and evolve. The encapsulation and interfaced-based approach of COM removes most dependencies and allows you to modify or completely rewrite COM modules without having to touch other modules. Or substitute modules (like test stub modules) later with different ones again without touching any other code. That's especially useful in a multi-developer shop where you don't want new changes requiring older, proven code to have to be altered or even recompiled.

It's also great for multiprocess or multithreaded systems where you want to quickly make new code without worrying about thread safety.

The networking ability also makes it very easy to do client/server or peer-to-peer using regular C++ method calls without worrying about low level network code. You can call a C++ method running on another process or another computer on the network the same as a regular C++ method call. The parameters get translated and converted for you.

It has its quirks (mostly with multithreading and cross-process calls) and the learning curve is a little steep, but once you learn it, it's extremely powerful. I've used it since 2000 on very complex projects and can give multiple anecdotal examples of how it saved us lots of time and literally millions. 

If somebody in the shop already knows it fairly well and can answer occasional questions, others on the team can get up to effective speed over about six months of learning by using. Learning the rest of the quirks and strange errors continues over a couple more years of use. Otherwise if everyone is new to COM, it may take a little longer to learn it and that should be a consideration.

If your project is small and fairly simple though (e.g. one man year), or it's one-off and you don't expect to grow it later, regular DLL's are probably better just to keep it simple.

你可能感兴趣的:(C++,function,dll,dependencies,installer,multithreading)