0

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!

Community
  • 1
  • 1
Raj
  • 263
  • 1
  • 2
  • 14
  • If your DLL will only ever be used in one program, just statically link it. – Ryan Bemrose Jul 24 '16 at 05:42
  • 1
    You'll discover the drawbacks easily enough. The primary benefit of COM is language and runtime independence. That doesn't sound like much of a feature if it is written in C++ and only used from a C++ program. But it actually is, C++ does not have an ABI. You can use your DLL from a program that was built with any C++ compiler, using arbitrary compile options. You won't get the benefit of that immediately, only later. – Hans Passant Jul 24 '16 at 08:22

1 Answers1

3

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.

Community
  • 1
  • 1
dxiv
  • 16,984
  • 2
  • 27
  • 49