Angelo Lee's Blog
This is my kingdom .If i don't fight for it ,who will ?

DLLs in Visual C++

http://msdn.microsoft.com/en-us/library/1ez7dh12.aspx

A dynamic-link library (DLL) is an executable file that acts as a shared library of functions. Dynamic linking provides a way for a process to call a function that is not part of its executable code. Multiple applications can simultaneously access the contents of a single copy of a DLL in memory.

Dynamic linking differs from static linking in that it allows an executable module (either a .dll or .exe file) to include only the information needed at run time to locate the executable code for a DLL function. In static linking, the linker gets all of the referenced functions from the static link library and places it with your code into your executable.

Differences Between Applications and DLLs

Even though DLLs and applications are both executable program modules, they differ in several ways. To the end user, the most obvious difference is that DLLs are not programs that can be directly executed. From the system's point of view, there are two fundamental differences between applications and DLLs:

  • An application can have multiple instances of itself running in the system simultaneously, whereas a DLL can have only one instance.

  • An application can own things such as a stack, global memory, file handles, and a message queue, but a DLL cannot.

Kinds of DLLs

If your DLL is using MFC, Visual C++ supports three different DLL development scenarios:

  • Building a regular DLL that statically links MFC

  • Building a regular DLL that dynamically links MFC

  • Building an MFC extension DLL, which always dynamically link MFC

Non-MFC DLLs: Overview

Regular DLLs statically linked to MFC

Regular DLLs dynamically linked to MFC

Extension DLLs: Overview

What is Extension DLLs?

An MFC extension DLL is a DLL that typically implements reusable classes derived from existing Microsoft Foundation Class Library classes. Extension DLLs are built using the dynamic-link library version of MFC (also known as the shared version of MFC). Only MFC executables (either applications or regular DLLs) that are built with the shared version of MFC can use an extension DLL. With an extension DLL, you can derive new custom classes from MFC and then offer this extended version of MFC to applications that call your DLL.

What is the difference between Extension DLL and Regular DLL?

1. Extension DLL only used in MFC applications while Regular
DLL used in MFC and non - MFC applications.

2. Extension DLL are not derived from CWinAppl classes while
Regular DLL is derived from CWinApp class.

3. Extension DLL can export function and classes while in
the case of Regular DLL can export only functions.

Initializing a DLL

http://msdn.microsoft.com/en-us/library/7h0a8139.aspx

Importing and Exporting

http://msdn.microsoft.com/en-us/library/9h658af8.aspx

You can import public symbols into an application or export functions from a DLL using two methods:

  • Use a module definition (.def) file when building the DLL

  • Use the keywords __declspec(dllimport) or __declspec(dllexport) in a function definition in the main application

Linking an Executable to a DLL

An executable file links to (or loads) a DLL in one of two ways:

Search Path Used by Windows to Locate a DLL

With both implicit and explicit linking, Windows first searches for "known DLLs", such as Kernel32.dll and User32.dll. Windows then searches for the DLLs in the following sequence:

  1. The directory where the executable module for the current process is located.

  2. The current directory.

  3. The Windows system directory. The GetSystemDirectory function retrieves the path of this directory.

  4. The Windows directory. The GetWindowsDirectory function retrieves the path of this directory.

  5. The directories listed in the PATH environment variable.

posted on 2013-02-02 00:00  Angelo Lee  阅读(239)  评论(0编辑  收藏  举报