开发者

DllGetVersion not giving expected results under Windows 7

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 dwMinorVersi开发者_运维技巧on;
    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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜