1
votes

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.

2
While I've never done it myself, it is possible to get windows to defer to another binary embedded inside the main one given a certain condition (most common use is a unified 32bit/64bit binary, process explorer uses this to run in 64bit mode from a 32bit binary for example).ewanm89
Microsoft seems to call this technique side-by-side assemblies and is documented on MSDN msdn.microsoft.com/en-us/library/ms235531.aspx although most the documentation I seem to find on it seems to specifically refer to using it to create DLL's that encapsulate multiple library versions.ewanm89
Thanks for the comments. You led me right to the correct answer.enriquein

2 Answers

2
votes

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.

1
votes

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.