C++ – Checking if DWM/Aero is enabled, and having that code live in the same binary for 2000/XP/Vista/7

aerocdwm

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.

Best Answer

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.