Is there any way to directly use the Win32Native namespace?
I would like to directly call the method:
Win32Native.SendMessageTimeout(new IntPtr(0xffff), 0x1a, IntPtr.Zero, "Environment", 0, 0x3e8, IntPtr.Zero) == IntPtr.Zero;
as opposed to declaring it:
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern IntPtr SendMessageTimeout(IntPtr hWnd, int Msg, IntPtr wParam, string lParam, uint fuFlags, uint uTimeout, IntPtr lpdwResult);
Is there any chance of that?
I assume you mean the
Microsoft.Win32.Win32Nativeclass. No, you cannot call it, it is internal. You could probably do something with reflection, but that would be even uglier.Microsoft could change the API at any time; via a new Framework version, service pack, etc. Since it is internal, they have no obligation to support it even if they make a change that breaks your application if you were directly calling it.
In short: write the platform invoke yourself.
You should also look at http://pinvoke.net/. This site contains many platform invoke signatures already defined for you.