检查 DWM/Aero 是否已启用,并将该代码保存在 2000/XP/Vista/7 的同一二进制文件中

发布于 2024-08-02 04:43:44 字数 472 浏览 2 评论 0原文

我知道这个标题没什么意义,主要是因为很难用一行话解释清楚。情况如下:

我有一个程序,其二进制文件针对 Windows 2000 及更高版本。现在,我继续添加一些代码来检查用户是否在 Vista/7 下运行,如果是,则检查是否启用了 Aero/DWM。基于此,我将禁用一些与该特定平台无关的内容,并启用一些其他功能。我的主要问题是,为了从 Visual C++ 2008 调用 DwmIsCompositionEnabled,我必须添加 dwmapi.lib 文件并针对它进行编译。在 Vista 或 7 以外的任何操作系统中运行二进制文件都会出现“无法找到组件。应用程序无法启动,因为未找到 dwmapi.dll”错误。当然,这种情况是预料之中的,因为 DWM 是新的并且不适用于旧平台。

那么我的问题是:我是否有可能以某种方式设法实现这一目标?适用于所有操作系统版本的一个二进制文件并包含 DWM 检查代码?该程序是在Visual Studio 2008、Visual C++下使用MFC编写的。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

南风起 2024-08-09 04:43:44

结果我可以告诉链接器延迟加载 dwmapi.dll。

我要感谢 ewanm89,因为他说的一些话引起了我的共鸣,并引导我走上了寻找实际答案的道路。

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.

零度℉ 2024-08-09 04:43:44

正常的解决方案是使用 LoadLibrary() 和 GetProcAddress()。两者都可以在程序启动后完成。但 DelayLoad 解决方案仍然+1,它在幕后为您做同样的事情。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文