DllGetVersion 在 Windows 7 下未给出预期结果
我有一些代码尝试测试我的应用程序是否使用主题集运行。下面是 C# 代码:
internal class NativeMethods
{
[DllImport("comctl32", CharSet = CharSet.Auto, SetLastError = true)]
internal static extern uint DllGetVersion(ref DLLVERSIONINFO pdvi);
[StructLayout(LayoutKind.Sequential)]
internal struct DLLVERSIONINFO
{
public uint cbSize;
public uint dwMajorVersion;
public uint dwMinorVersion;
public uint dwBuildNumber;
public uint dwPlatformID;
}
internal static bool IsThemed()
{
bool retval = false;
if ((Environment.OSVersion.Version.Major >= 5 &&
Environment.OSVersion.Version.Minor >= 1) ||
Environment.OSVersion.Version.Major > 5)
{
bool appThemed = NativeMethods.IsAppThemed();
bool themeActive = NativeMethods.IsThemeActive();
if (appThemed && themeActive)
{
DLLVERSIONINFO dvi = new DLLVERSIONINFO();
dvi.cbSize = (uint)Marshal.SizeOf(dvi);
NativeMethods.DllGetVersion(ref dvi);
retval = (dvi.dwMajorVersion >= 6);
}
}
}
该代码非常适合我在 Windows XP、2003 和 Vista 下的需要。但是,当我在运行 Aero 的 Windows 7 下尝试时,对 DllGetVersion 的调用返回的值小于 6。当我调试应用程序并在调试器(模块窗口)下查看 comctl32 的版本号时,它显示加载的版本号大于6。为什么我的代码返回不同的数字?
谢谢,
诺特
I have some code that attempts to test whether my application is running with the themes set. Here's the C# code:
internal class NativeMethods
{
[DllImport("comctl32", CharSet = CharSet.Auto, SetLastError = true)]
internal static extern uint DllGetVersion(ref DLLVERSIONINFO pdvi);
[StructLayout(LayoutKind.Sequential)]
internal struct DLLVERSIONINFO
{
public uint cbSize;
public uint dwMajorVersion;
public uint dwMinorVersion;
public uint dwBuildNumber;
public uint dwPlatformID;
}
internal static bool IsThemed()
{
bool retval = false;
if ((Environment.OSVersion.Version.Major >= 5 &&
Environment.OSVersion.Version.Minor >= 1) ||
Environment.OSVersion.Version.Major > 5)
{
bool appThemed = NativeMethods.IsAppThemed();
bool themeActive = NativeMethods.IsThemeActive();
if (appThemed && themeActive)
{
DLLVERSIONINFO dvi = new DLLVERSIONINFO();
dvi.cbSize = (uint)Marshal.SizeOf(dvi);
NativeMethods.DllGetVersion(ref dvi);
retval = (dvi.dwMajorVersion >= 6);
}
}
}
This code works great for my needs under Windows XP, 2003 and Vista. However, when I try it under Windows 7, where I'm running Aero, the call to DllGetVersion returns a value less than 6. When I debug my application and look at the version number of comctl32 under the debugger (modules window), it shows a version number greater than 6 is loaded. Why does my code return a different number?
Thanks,
Notre
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看 MSDN 的
DllGetVersion ()
,听起来这可能不是完成您想要做的事情的最佳方式。由于这不是 API 函数,因此可能在 Win7 中发生了某种变化,无法以相同的方式调用。如果您使用的是 WinForms,您可以尝试调用 Application.RenderWithVisualStyles - 听起来它正在做你上面想做的事情。
Looking at MSDN for
DllGetVersion()
, it sounds like this might not be the best way to do what you're trying to do. Since this isn't an API function, it's possible that this changed in Win7 somehow and can't be called in the same way.If you're using WinForms, you could try calling Application.RenderWithVisualStyles - that sounds like it's doing what you're trying to do above.