DllGetVersion 在 Windows 7 下未给出预期结果

发布于 2024-08-10 09:16:44 字数 1283 浏览 4 评论 0原文

我有一些代码尝试测试我的应用程序是否使用主题集运行。下面是 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 技术交流群。

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

发布评论

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

评论(1

傲影 2024-08-17 09:16:44

查看 MSDNDllGetVersion (),听起来这可能不是完成您想要做的事情的最佳方式。由于这不是 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.

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