1

We have a legacy WinForms app written at the times of .NET 1.x and may need to change the code that checks whether the app is rendered with the OS visual styles for the reason described below. The current function that does this work looks like this:

private bool IsComCtl6
{
    get
    {
        if (!fIsComCtl6Initialized)
        {
            IntPtr hMod = NativeMethods.LoadLibrary("comctl32.dll");
            if (hMod != IntPtr.Zero)
            {
                IntPtr lptrDLLVersion = NativeMethods.GetProcAddress(hMod, "DllGetVersion");
                if (lptrDLLVersion != IntPtr.Zero)
                {
                    hMod = NativeMethods.LoadLibrary("uxtheme.dll");
                    if (hMod != IntPtr.Zero)
                    {
                        NativeMethods.DllVersionInfo dvi = new NativeMethods.DllVersionInfo();
                        dvi.cbSize = Marshal.SizeOf(typeof(NativeMethods.DllVersionInfo));
                        if (NativeMethods.DllGetVersion(ref dvi) == NativeMethods.S_OK)
                            fIsComCtl6 = (!fCheckAppThemed || dvi.dwMajorVersion >= 6) && NativeMethods.IsThemeActive() && NativeMethods.IsAppThemed();
                    }
                }
            }
            fIsComCtl6Initialized = true;
        }
        return fIsComCtl6;
    }
}

NativeMethods in this code is a class that contains P-Invoke declarations for all referenced WinAPI functions and constants.

We want to avoid platform-independent calls in this code as, it seems, they are not compatible with the latest releases of the Mono platform. Is there a better and shorter way to check what we need without OS native calls? It would be nice if we can do that solely with native .NET classes. The minimal version of supported .NET should be 2.0 or even 3.5.

TecMan
  • 2,743
  • 2
  • 30
  • 64
  • 1
    I think Application.RenderWithVisualStyles is exactly this check with no WinApi call needed, however i dont know if it is implemented correctly in mono. – Felix Almesberger Jan 10 '18 at 21:18
  • @feal, if Google showed me the correct implementation of the [Application](https://github.com/mono/mono/blob/master/mcs/class/System.Windows.Forms/System.Windows.Forms/Application.cs) class in Mono, there should be no problems with using it in Linux. – TecMan Jan 11 '18 at 16:09

0 Answers0