Solved

About COM and DLLs

Posted on 2000-05-02
5
258 Views
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.
0
Comment
Question by:mcli8
  • 2
  • 2
5 Comments
 
LVL 1

Accepted Solution

by:
ZivKatzir earned 100 total points
ID: 2768768
Hi,
 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

0
 
LVL 1

Expert Comment

by:Ik_Khan_Pk
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
0
 

Author Comment

by:mcli8
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?
0
 

Author Comment

by:mcli8
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?
0
 
LVL 1

Expert Comment

by:ZivKatzir
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.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

759 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now