Using DwmIsCompositionEnabled (JwaDwmApi) on pre-vista causes error

你说的曾经没有我的故事 提交于 2019-12-08 12:24:36

问题


Been trying to use the following code in order to check if Windows Aero is enabled:

function AeroEnabled: boolean;
var
  enabled: bool;
begin
 // Function from the JwaDwmapi unit (JEDI Windows Api Library)
 DwmIsCompositionEnabled(enabled);
 Result := enabled;

end;

 ...

 if (CheckWin32Version(5,4)) and (AeroEnabled) then
 CampaignTabs.ColorBackground   := clBlack
 else begin
 GlassFrame.Enabled             := False;
 CampaignTabs.ColorBackground   := clWhite;
 end;

However, doing so on a pre-vista machine causes the app to crash because the DWMApi.dll is missing. I've also tried this code however it produces 2 AV's in a row. How can I do this ? I am using Delphi 2010. :)


回答1:


You've got your versions wrong. Vista/2008 server are version 6.0. Your test should be:

CheckWin32Version(6,0)

I believe that you are using Delphi 2010 or later in which case you should simply call the DwmCompositionEnabled function from the built-in Dwmapi unit. This organises the version check and the delayed binding for you. No need for JEDI.


Edit: Text below was written before the question was edited.

Probably the easiest approach is to check the Windows version. You need Win32MajorVersion>=6 (i.e. Vista or 2008 server) in order to call DwmIsCompositionEnabled.

If you were binding yourself then you would call LoadLibrary with DWMApi.dll and if that succeeded you would then call GetProcAddress to bind. If that succeeded you are good. But, as I said, since you aren't handling the binding yourself then a version check is probably the simplest.

So the function would be:

function AeroEnabled: boolean;
var
  enabled: bool;
begin
  if Win32MajorVersion>=6 then begin
    DwmIsCompositionEnabled(enabled);
    Result := enabled;
  end else begin
    Result := False;
  end;
end;

Note, I'm assuming that your library is doing late binding, i.e. explicit linking. If not then you'll need LoadLibrary/GetProcAddress, exactly as is done in @RRUZ's code to which you link.



来源:https://stackoverflow.com/questions/7539812/using-dwmiscompositionenabled-jwadwmapi-on-pre-vista-causes-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!