Search code examples
c++dllcom

COM dll over C++ dll


if I need to build a dll only to be consumed by c++ applicaton. what is the benefit or drawback (in terms of performance or any) if I go for creating COM dll.

I have gone through this LINK It didn't answer my question well.

Thanks!


Solution

  • The answers in the link you posted (COM vs non-COM DLL) address the major relevant points. If that didn't answer my question well then you should consider framing the question more narrowly.

    A couple more notes in addition to the ones touched already in the other topic.

    • A C++ DLL being consumed (only) by other C++ code can expose full C++ interfaces. See for example Using dllimport and dllexport in C++ Classes: You can declare C++ classes with the dllimport or dllexport attribute. These forms imply that the entire class is imported or exported..

      In contrast, a COM DLL can only publish COM interfaces, which are language neutral and less friendly to C++. See for example What Is a COM Interface? .

    • Related to the previous point, a DLL C++ interface is very strongly coupled with any C++ code that uses it. With rare exceptions, this means that both the DLL and the client code need to be compiled with the same compiler, and same version thereof. Also, whenever DLL exported classes change (including private changes), potentially all client code needs to be recompiled.

      In contrast, a COM interface is an ABI contract (What is Application Binary Interface (ABI)?) far more loosely coupled with the client code. Essentially, as long as the published interfaces don't change, DLL code can change at will without requiring client recompiles.

    As far as performance, that's premature to compare and impossible to second-guess without a lot more specifics. The C++ vs. COM interfaces have wildly different semantics and capabilities.