Code Examples
  Home arrow Code Examples arrow Page 3 - 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 
Dedicated Servers 
Moblin 
JMSL Numerical Library 
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 / 55
    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 - What Does the DLL Contain?


    (Page 3 of 9 )

    The DLLs usually contain code, data and resources. Code is stored on read-only sections so that it can be shared among the requesting applications, but the case with data in the DLLs is different. Each requesting application gets its private copy of data segments unless one explicitly marks them as shared. There may be resource-only DLLs too that we’re going to discuss shortly.

    The code section contains classes or standalone (unrelated) functions that you want to expose through the DLL. In case of classes you’ve all the functionality and data bound into one entity already, but with standalone related functions you may have some shared global data too. All of this is defined in one or more source files but finally packaged as one DLL. Classes and functions that are available to the applications using the DLL are called exports from the DLL. If your DLL uses functions from other DLLs, then those are called as imports to the DLL. A free useful utility that allows you view exported and imported functions from a DLL or EXE file is freely available from www.dependencywalker.com. Below is a snapshot of the same displaying exports from the WinScard.dll.

     

    DLL

     
    Figure 1: Function Exports of a Windows System DLL

    Exporting Classes and Functions from the DLL

    To make the code you’ve compiled in a DLL, you must explicitly export it so that other applications may use it. There are two ways to do so:

    • By creating a module definition (.DEF) file and use the .DEF file when building the DLL. This approach also facilitates exporting functions by ordinal rather than by name, which is the default. You’ll need to specify the /DEF while you use the linker to build the DLL.

    • By using the keyword __declspec (dllexport) in the function's definition. In case you wish to export classes, you’ll place this keyword after the class keyword. A complier specific name mangling technique is used to mangle member function names and other exports. If you specify C linkage by using the extern “C” keyword, then name mangling won’t be performed.

    Let's say you’ve a function Foo(Type1 a,Type2 b) and you wish to export it from the DLL you’re writing, so you just append __declspec(dllexport) keyword before the function name or write a module definition file with the following contents:

    LIBRARY FooLib
    EXPORTS
        Foo private  @1

    Here the last line tells the linker (you’ve to do so with a /DEF switch) to export the function.

    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 3 hosted by Hostway