views:

53

answers:

2

I am writing a Win32 DLL library that can be redistributed. I am using different versions of the windows API because I want to support Windows 7 functions, but still have support for Windows 2000 (with some function disabled). What I have currently is MyLib2000.dll, MyLibXP.dll, and MyLibVista.dll, and my application chooses which library to load at runtime. I want a way to have a single DLL (MyLib.dll) that stores the other three in itself and when it's being loaded, it extracts the correct DLL out of itself and loads it.

I know this is not the best way to do this, so suggestions on another method of doing this is welcome.

+1  A: 

Why not just abstract out the OS-version dependencies in a software layer, implemented in terms of something like STLSoft's dl_call() function template suite.

DannyT
+1  A: 

Use delayloading and implement the dliNotePreLoadLibrary notification hook to load the correct version of your DLL. The linker-provided delay load logic will then pull in all the functions from whichever DLL you loaded.

http://msdn.microsoft.com/en-us/library/z9h1h6ty(v=VS.100).aspx

Or use delay-loading and implement your functions to check the OS version before calling any function that could fail to be loaded (since it doesn't exist on the old OS).

Ben Voigt
That looks like the solution to my problem. I'll look into it, but I'd appreciated it if I could see some sample code.
Yifan
This might be the type of sample you are looking for: http://www.codeproject.com/KB/DLL/delayloaddll.aspx
Ben Voigt