English 中文(简体)
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 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

最佳回答

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.

问题回答

暂无回答




相关问题
Why running a service as Local System is bad on windows?

I am trying to find out the difference between difference service account types. I tumbled upon this question. The answer was because it has powerful access to local resources, and Network Service ...

Programmatically detect Windows cluster configuration?

Does anyone know how to programatically detect that a Windows server is part of a cluster? Further, is it possible to detect that the server is the active or passive node? [Edit] And detect it from ...

get file icon for Outlook appointment (.msg)

I ve read Get File Icon used by Shell and the other similar posts - and already use SHFileInfo to get the associated icon for any given extension, and that works great. However, Outlook uses ".msg" ...

Identifying idle state on a windows machine

I know about the GetLastInputInfo method but that would only give me the duration since last user input - keyboard or mouse. If a user input was last received 10 minutes ago, that wouldn t mean the ...

Terminating a thread gracefully not using TerminateThread()

My application creates a thread and that runs in the background all the time. I can only terminate the thread manually, not from within the thread callback function. At the moment I am using ...

热门标签