Click here to Skip to main content
13,398,338 members (37,871 online)
Click here to Skip to main content
Add your own
alternative version


30 bookmarked
Posted 11 Jan 2003

Delay Loading DLLs

, 11 Jan 2003
Rate this:
Please Sign up or sign in to vote.
Easy to use library which let you use different compilers, to optimize-compile your DLL for different processors


This is a easy to use library which let you use different compilers, to optimize-compile your DLL for different processors.


Move all the to be optimized classes and functions to a DLL, and the DelayLoader library will automatically import all the functions from the fastest (for this processor available) DLL. 

There are 4 projects included:

  • DelayDLL, a library project which is the one to use in your own workspaces
  • MainDLL, a sample DLL which exports a function
  • Test, a sample DLL which exports a function
  • MainMFC, a sample project which makes uses of the projects above, no fancy MessageBox, just step through with debugger to see which DLL  is loaded. A
    output is done, so you can easily see which DLL is currently loaded

The library is based on the Delay loading of DLL. So we start loading the DLL when it is needed for the first time. No LoadLibrary and GetProcAdress functions need to be called, The Delay Loading from Microsoft takes care of this.

With a specific hooking mechanism we can force our app to load a different DLL than compile-time was programmed. We could even get the adress of a different named function. The DelayDLL.dll should be loaded by the MainMFC program, but because we run this program on my Athlon MP the DelayDLL.Athlon.dll file is loaded.

This hook makes it very easy when we build a program which should make use of processor specific optimizations. The UnloadDelayedDLL( LPSTR ) method can unload a DLL at runtime, to free up memory, for if you don't have 1Gb of RAM like me :-p

Hope this is useful for you guys.

How to use

  • Add the DelayDll project to your workspace.
  • Set a dependency for your project to this project, the library will automatically be linked against your exe.
    Add the precompiled library delaydll.lib to your DLL's configuration.
  • Add a new file to your project, so you can easy change / add new DLLs (See below.)
  • Make a copy of the configuration
  • Build->Configuration
  • Select the DLL-project you want to optimize,

You could only add a copy of Win32 Release, and call it w32 Athlon Rls. Or also make a copy of the win32 Debug, and call it w32 Athlon Dbg. The only thing you have to change in the project settings, is on the link tab, the Output name, to MainDLL.Athlon.dll for example.

And of course you should select another compiler, for this configuration ( using the Codeplay Compiler Controller Plug-in ). Or make some assembler files yourself and use them for this configuration. For now only compile the .c files using VectorC, so not the complete project. ( no cpp support yet ). Of course you can also use the Intel compiler to create optimized DLLs.

Here is an example of file to be added to your project, which will make use of the optimized DLLs.

// <START OF FILE : MyDelayDlls.cpp>
/*         Sample .cpp file, to include in your executable        */
#include "..\DelayDll\DelayDll.h"

// Tell delay loader to call my hook function

/*Which DLLs should be Delay loaded  */
// Use Upper and Lower case letters, exactly the same as in de DLL 
// Project ,Thanks to MS DelayLoader :-(
#pragma comment(linker, "/DelayLoad:Test.dll")
#pragma comment(linker, "/DelayLoad:MainDLL.dll")

// Descriptor for Test.dll
// value nr,Description
// 1InUse, always 1, for the last in line, use 0, so library known array 
//  is ended.
// 2DllName, use this if your optimized DLL has a complete 
// different name than your original DLL
// 3DllExtension, if you use an extension, Original:Test.dll, 
// Optimized:Test.Pentium.dll
// 4Optimized for Processor, A PIV dll, will not be loaded on a PIII
// 5Used Compiler, not used, but maybe we ever want to know this??

DLLDescriptor TestDLL[] = 

// Descriptor for another DLL
DLLDescriptor MainDLL[] = 

// Only these DelayLoaded DLL will be checked for there Optimized versions
// value nr,Description
// 1Dll name, (case sensitive)
// 2Use this Descriptor struct 
// ( All DLLs, could have the same Descriptor struct, 
// ONLY when Extensionname is 
//  used and not a fullname )

DLLCollection pDelayLoadedDLLs[] = 
  "Test.dll", TestDLL,   // Tries to load first : Test.Pentium.dll, then Test.dll
  "Test2.dll", TestDLL,  // Tries to load first : Test2.Pentium.dll, then Test2.dll
  "MainDLL.dll", MainDLL,// Tries to load first : MainPIV.dll, then MainDLL.Athlon.dll, 
                         // then MainDLL.PII.dll, then MainDLL.dll


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Software Developer (Senior)
Netherlands Netherlands
I'm a 31 year old full-time programmer ('76).
(Currently: Lead Software System Designer)

You may also be interested in...

Comments and Discussions

GeneralVisual Studio 2005 support Pin
ETA5-Aug-07 3:24
memberETA5-Aug-07 3:24 
GeneralDelay loading a dll from a dll Pin
Dan Verret4-Oct-04 6:04
memberDan Verret4-Oct-04 6:04 
General.h from .lib Pin
bfadi2-Mar-03 15:16
memberbfadi2-Mar-03 15:16 
GeneralRe: .h from .lib Pin
ETA3-Mar-03 8:41
memberETA3-Mar-03 8:41 
GeneralRe: .h from .lib Pin
bfadi3-Mar-03 9:36
memberbfadi3-Mar-03 9:36 
GeneralRe: .h from .lib Pin
ETA3-Mar-03 10:29
memberETA3-Mar-03 10:29 
GeneralRe: .h from .lib Pin
bfadi4-Mar-03 8:21
memberbfadi4-Mar-03 8:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.180216.1 | Last Updated 12 Jan 2003
Article Copyright 2003 by ETA
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid