Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the advantage of using COM over a plain DLL?

Tags:

c++

com

Assume that you work only in the C++ world (cross-language interop is not required). What advantages/inconvenients do you see in using COM instead of a plain basic DLL? Do you think using COM is worth the trouble if you are not going to use the interface from different languages?

like image 282
Martin Cote Avatar asked Jun 12 '09 14:06

Martin Cote


People also ask

What is the difference between DLL and COM DLL?

COM is a component model while DLL is a dynamically linked library (and also the file extension often used for such binaries). So they are kinda hard to compare. A DLL can contain implementation for COM objects. And you can certainly create COM objects in C# if you want.

Is DLL and COM are same?

I found that COM DLL is kind of built upon the traditional DLL infrastructure. When we build COM DLLs, we still rely on the traditional DLL export methods to lead us to the internal COM co-classes. If COM is for component reusing at the binary level, I think the traditional DLL can achieve the same thing.

What is a COM DLL?

A COM component allows you to provide implementations to interfaces which may be called from different languages across process and machine boundaries. A regular DLL allows you to export C++ classes and functions which can be used by other DLLs/EXEs also written in C++ and built with the same compiler.

What is non COM DLL?

An application that uses a C++ DLL must allow Windows to find the DLL at startup time, usually by having the DLL in the same directory as the EXE or on the Path. A COM DLL is found without the client app specifying where it is located.


2 Answers

Everybody is mentioning things that are in COM's plus column. I'll mention a couple of detractions.

  • When you implement your system using COM, you need to register the COM 'servers' (be they in-proc or out-of-proc) at setup and unregister them at uninstall. This could increase the complexity of your setup system slightly and tends to require a reboot unless the user carefully tears down running processes first.

  • COM is slow compared to other standard ways of doing the same thing. This comment will probably generate a lot of hate and maybe some downvotes, but the fact of the matter is that at some point you will need to marshall data, and that is expensive.

  • According to the Rules of COM, once an interface has been published it can never be changed. That in itself is not a negative, and you might even argue that it forces you to do thorough design before shipping the interface. But the truth is there's no such thing as never, and in production code interfaces change. You will undoubtedly need to either add methods or change the signatures of existing methods. In order to accomplish this you have to either break the rules of COM -- which has bad effects -- or follow the rules of COM which are more complicated than just adding a parameter to a function like you would with a astraight DLL.

like image 112
John Dibling Avatar answered Oct 12 '22 23:10

John Dibling


COM can be useful in plain old C++ for:

  • Interprocess communication
  • Plugin architectures
  • Late binding scenarios
  • "Much, much, more..." (tm)

That said, if you don't need it, don't use it.

like image 20
ConsultUtah Avatar answered Oct 13 '22 01:10

ConsultUtah