tags:

views:

394

answers:

2

I know the title makes little sense, mostly because it's hard to explain in just one line. So here's the situation:

I have a program who's binary is targeted at Windows 2000 and newer. Now, I went ahead and added some code to check if the user is running under Vista/7, and if so then check if Aero/DWM is enabled. Based on this I'll disable some stuff that isn't relevant to that particular platform, and enable some other features. My main problem is that in order to call DwmIsCompositionEnabled from Visual C++ 2008 I have to add the dwmapi.lib file and compile against it. Running the binary in anything other than Vista or 7 gives the "Unable to locate component. The application failed to start because dwmapi.dll was not found" error. This, of course, is expected to happen since DWM is new and not available for older platforms.

My question is then: will it be possible for me to somehow manage to pull this off? One binary for all OS versions AND include that DWM check code? This program was written under Visual Studio 2008, Visual C++ using MFC.

+1  A: 

Turns out I can just tell the linker to delayload the dwmapi.dll.

I'd like to thank ewanm89 because something he said sort of resonated and led me down the path to finding the actual answer.

enriquein
Yeah, as I slept I wondered if you could just load the dll on the condition and not need a second binary...
ewanm89
As you slept! Impressive.
Paul Lammertsma
A: 

The normal solution is to use LoadLibrary() and GetProcAddress(). Both can be done after your program started. But still +1 for the DelayLoad solution, which does the same for you behind the scenes.

MSalters