Click here to Skip to main content
15,901,122 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to use a code in my MFC application that it works only in win vista and higher, because it needs a dll file that it's not in winXP.

This is my code:
C++
if ( ... ) //  check win 7 or Vista
DwmIsCompositionEnabled();

It works fine in win 7, but my problem is when I run the application in XP, in run time and before the code that checked the OS, it breaks with this error:

"This application has failed to start because dwmapi.dll was not found. Re-Installing the application may fix the problem."

Is there any idea?
Posted
Updated 13-Nov-11 22:59pm
v3

Try using the GetVersionEx()[^] function to verify the OS version. I think you will also need to modify your executable so that dwmapi is not linked in to the program but loaded dynamically once you have determined that you are on the correct OS.
 
Share this answer
 
v2
Comments
Minoo Khazeni 16-Nov-11 0:26am    
Of course I'm using GetVersionEx, but for brief I used ... in the code above. I can't understand what you mean by "you will also need to modify your executable..." . please explain more.
Richard MacCutchan 16-Nov-11 3:43am    
I'm not sure what more there is to explain. If this DLL does not exist on some OS versions then you need to ensure that it is not linked in to your executable file. You need to load it dynamically using the LoadLibrary() function.
Albert Holguin 10-Dec-11 9:29am    
Yep, have to do it dynamically... +5... Great advice.
You can use WMI Query to fetch OS detials from system. the following article will help to do same.

Making WMI Queries In C++[^]
 
Share this answer
 
It was because of "dwmapi.lib" that I put in Additional Dependencies. When I run the application in Win XP, it wants to find "dwmapi.lib" as the first step, so it breaks.
Now I used another way:
C#
if ( ... ) //  check win 7 or Vista
   hLib = LoadLibrary( L"dwmapi.dll" );
   GetProcAddress( hLib, "DwmIsCompositionEnabled" );
.
.
.
 
Share this answer
 
Comments
Albert Holguin 10-Dec-11 9:28am    
Yep, you have to load it dynamically at run-time instead of statically... it's the only way to do it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900