Code Examples
  Home arrow Code Examples arrow Page 8 - Dynamic Link Libraries Inside-Out
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
CODE EXAMPLES

Dynamic Link Libraries Inside-Out
By: Digvijay Chauhan
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 56
    2004-09-15

    Table of Contents:
  • Dynamic Link Libraries Inside-Out
  • Advantages and Disadvantages of Using DLLs
  • What Does the DLL Contain?
  • The DLL Entry Point Function: DllMain
  • Types of DLL Linking
  • Resource Only DLLs
  • Dynamic Link Library Redirection
  • Points of Interest
  • Troubleshooting and Common Errors

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Dynamic Link Libraries Inside-Out - Points of Interest


    (Page 8 of 9 )

    Here are a few points that any developer would need to keep in mind:

    • When the system starts a program that uses load-time dynamic linking, it uses the information in the file to locate the names of the required DLL(s).

    Following search sequence will be used to locate DLLs:

    1. The directory from which the application loaded.

    2. The current directory.

    3. The Windows system directory. Use the GetSystemDirectory function to get the path of this directory.

    4. The 16-bit Windows system directory. There is no function that obtains the path of this directory, but it is searched. The name of this directory is System.

    5. The Windows directory. Use the GetWindowsDirectory function to get the path of this directory.

    6. The directories that are listed in the PATH environment variable.

     
    • The DLL is mapped into the virtual address space of the process during its initialization and is loaded into physical memory only when needed.

     
    • DLLs are loaded using LoadLibrary or LoadLibraryEx APIs.


    • Standard search sequence (mentioned above) will be used to locate DLLs unless you decide to redirect the DLL(Win2K only).


    • Two DLLs that have the same base file name and extension but are found in different directories are not considered to be the same DLL.

    • The system calls the entry-point function in the context of the thread that called LoadLibrary or LoadLibraryEx.

    • If the system cannot find the DLL or if the entry-point function returns FALSE, LoadLibrary or LoadLibraryEx returns NULL.

    • The process can use GetProcAddress to get the address of an exported function in the DLL using a DLL module handle returned by either LoadLibrary, LoadLibraryEx, or GetModuleHandle

    • When the DLL module is no longer needed, the process can call FreeLibrary or FreeLibraryAndExitThread.

    • Run-time dynamic linking enables the process to continue running even if a DLL is not available.

    • Run-time dynamic linking can cause problems if the DLL uses the DllMain function to perform initialization for each thread of a process, because the entry-point is not called for threads that existed before LoadLibrary or LoadLibraryEx is called.

    • DLLs can contain global data or local data.

    • The default scope of DLL variables is the same as that of variables declared in the application.
     
    • When a DLL allocates memory using any of the memory allocation functions (GlobalAlloc, LocalAlloc, HeapAlloc, and VirtualAlloc), the memory is allocated in the virtual address space of the calling process and is accessible only to the threads of that process.

    • The thread local storage (TLS) functions enable a DLL to allocate an index for storing and retrieving a different value for each thread of a multithreaded process.

    • Warning:  VC++ compiler supports a syntax that enables you to declare thread-local variables: _declspec(thread). If you use this syntax in a DLL, you will not be able to load the DLL explicitly using LoadLibrary or LoadLibraryEx. If your DLL will be loaded explicitly, you must use the thread local storage functions instead of _declspec(thread).
     
    • GetModuleFileName Retrieves the full path and file name for the file containing the specified module.

    • GetModuleHandle Retrieves a module handle for the specified module. 
     
    • GetModuleHandleEx Retrieves a module handle for the specified module. 
     
    • GetProcAddress Retrieves the address of an exported function or variable from the specified DLL.

    • LoadLibrary Maps the specified executable module into the address space of the calling process.

    • LoadLibraryEx Maps the specified executable module into the address space of the calling process.

    More Code Examples Articles
    More By Digvijay Chauhan


       · hi,Its Ravi Verma from India. This article on dll is really a master piece....
       · hi,Its Ravi Verma from India. This article on dll is really a master piece....
       · hey you indian,you have my job. stop outsourcing now
       · Where are the pictures in this article?Best RegardsHolland
       · I Jon't have a job either
       · Companies hire only talented deserving people......
       · Yes very True,That's why 'I QUIT' and don't have a job. They don't know how to...
       · the article could have been better if mapping of dll to address space have been...
       · Great article, thanks for sharing...
     

    CODE EXAMPLES ARTICLES

    - Handling Animations and Bitmaps Using GDI+ f...
    - Download a Web Page using the WebClient
    - Creating a Chart using Data from a Database ...
    - The Basics of Charting with the MS Chart Con...
    - Searching Body Text with textRange: Enter th...
    - Searching Body Text with textRange: Building...
    - Searching Body Text with textRange, part 1: ...
    - First Steps in Programming
    - Programming in C
    - Quick Introduction to ASF,ASX, and Networkin...
    - SatView: Pointer Perfect, Part 2: Constructi...
    - SatView: Pointer Perfect, Part 1
    - Style Case Studies: Construction Unions
    - Creating an Engine for Games for Windows
    - Style Case Studies: Generic Callbacks





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
    Stay green...Green IT