COM vs non-COM DLL

2019-02-12 17:48发布

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.

标签: vb.net dll com
2条回答
贼婆χ
2楼-- · 2019-02-12 18:27

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.

查看更多
混吃等死
3楼-- · 2019-02-12 18:39

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.

查看更多
登录 后发表回答