DllGetVersion在Windows 7下没有给出预期的结果

时间:2009-11-09 20:43:25

标签: windows dll themes version

我有一些代码试图测试我的应用程序是否与主题集一起运行。这是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。为什么我的代码会返回不同的数字?

谢谢,

巴黎

1 个答案:

答案 0 :(得分:0)

DllGetVersion()查看{{1}},听起来这可能不是您尝试做的最佳方式。由于这不是API函数,因此可能会以某种方式在Win7中进行更改,并且无法以相同方式调用。

如果你正在使用WinForms,你可以尝试拨打MSDN - 这听起来像是在做你正在尝试做的事情。