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