About COM and DLLs

Posted on 2000-05-02
Medium Priority
Last Modified: 2013-12-14
Can anybody tell me what's the difference between EXE and DLL's in C++?

Also, how to identity a COM object?
Please give some examples if possible.
Question by:mcli8
  • 2
  • 2

Accepted Solution

ZivKatzir earned 300 total points
ID: 2768768
 the basic difference is in the way the operating system treats the two files. When a EXE is loaded into memory it recives from the OP a address space, meaning that every variable, function or source code line stays somwhere in the same virtual memory portion.

Reading between the lines you will understand that runing the same EXE several times will create several proccesses each using a different address space.

This is not so when looking at a DLL. A DLL is loaded into memory only once (the first time it is called by any proccess) then it is MAPPED into the address space of each proccess who uses it. This means that only one memroy portion is actualy ocupied but in every proccess there is a pointer to that same memroy portion.

If the DLL containes any DLL scope variables they are the only part of the DLL which is actually being created in every proccess.

Now you will probably ask, so what so good about it ? The answer is in the difference between a regular library and a DLL. A regular library is compiled with the project which uses it, meaning when the project is compiled to an EXE it containes a copy of the library. The direct result is more disk space in use and more memory occupied when the proccess runs.

On the other hand when using a dll only a link to the library is saved with the project, and when running the dll can be loaded and removed at need.

This approach to DLLs is not unique to VC. This the the Windows conception.
When looking close at a DLL written in VC you will discover it containes a DllMain function instead of main and some other functions which deals with counting how many users a DLL has at a certain point of time. Those function enable the operating system to unload the DLL when it is no longer in use. VC wizard creates these functions for you.

Now about COM objects. Compiling a COM object into a DLL is the moast elegant way to make it evailable to many proccess without taking extra resources.

one thing more - there is a very detailed article in msdn about dll's called : DLLs for Beginners by Debabrata Sarma


Expert Comment

ID: 2768778
Some time DLL's also contains the exe extension, but the main difference is that an exe is a complete program not any reusage of the functions that it is using, but dlls are the collection of compiled function that you can use according to your requirement exactly according to your code.
COM Object can not be called without their interface, You can identity a COM with its interface as IDirectDraw4 is an interface to get the current display mode

Author Comment

ID: 2769338
Thanks to ZivKatzir.
But I still don't understand how to use a COM Object from the user's point of view, can anybody give more detail on that or illustrate using an example?

Author Comment

ID: 2769348
Thanks to ZivKatzir.
But I still don't understand how to use a COM Object from the user's point of view, can anybody give more detail on that or illustrate using an example?

Expert Comment

ID: 2769414
Hi, again.
 I don't realy get what you do not understand. Though I'll try and give you a short description of what is a COM object. If this is not what you meant please refine your question.

A COM object is an object which can let it's container learn it's capabilties at run time. Meaning a COM container can use a series of known methods of the object in order to gradualy learn about all what a specific object is capable of.

From the user point of view this is extreamly comfortable. For instance if I create a COM object I can then put it inside a HTML page and let it be viewed by InternetExplorer with no further programing. (this is possible since I.E. is an ActiveX/COM container)

The same way if you write a C project you can use a COM object written by me over a different OS with no effort, you just add it to user project and let the class wizard wrap it with a class for you.

The exact way in which this magical object shipping is made possible is somewhat more complex but if that what you want I will lead you to the documentation.

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question