Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

COM vs non-COM DLL

Tags:

vb.net

dll

com

The majority of my experience is with high level languages like Java and VB.NET. I do have some experience with C++ (at university).

I understand the difference between a COM DLL and a DLL produced by a .NET compiler. I don't fully understand the difference between a COM DLL and a Windows DLL generated by the C and C++ compiler.

I want to use C++ DLL in a .NET program. I have managed to get this working. My question is specifically: What is the difference between a DLL produced by C++ and a DLL produced by VB6 (COM based).

I have spent an hour Googling this and looking on MSDN. I though I would find my answer without having to ask a question, but I have not.

like image 874
w0051977 Avatar asked Oct 01 '12 20:10

w0051977


2 Answers

There's a giant difference between the two. The list is too long to reproduce accurately in an SO post, I'll try to hit the highlights:

  • A C++ DLL must export every function or class it wants to make available to the client code. A COM DLL only exports 4 functions with well-known names and behavior
  • An application that uses a C++ DLL must describe that DLL's interface at link time, a COM server is bound at runtime
  • 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. The registry is used at runtime to locate the DLL
  • A COM server doesn't have to be a DLL. It can be anything, including a seperate process on the same machine or an executable located on another machine half-way around the world. The client code is oblivious to where it is located

Specific to the Automation subset of COM:

  • A COM server is usable by any language that supports COM. Which in Windows is just about any of them.

The last bullet is possibly what trips you up about thinking that you understand the difference between a COM dll and a .NET dll. They have nothing at all in common, but .NET is pretty good and inter-operating with COM servers. The Tlbimp.exe utility is quite adept at papering over the differences.

like image 64
Hans Passant Avatar answered Oct 23 '22 02:10

Hans Passant


Com is a binary standard that allows applications to utilize binary modules interchangeable any language can produce com complaint library's as long as they meet the com standard. So what the diffidence is depends some com library's will be native machine code some may be manged and running through an interpreter. What com is really meant to do is bridge the usability gap between the oop style that c++ had at the source level to the prebuilt binary world.

like image 23
rerun Avatar answered Oct 23 '22 02:10

rerun