|
| using RegisterClassEx |
|
|
|
|
| Messages |
|
Related Types |
This message was discovered on microsoft.public.dotnet.framework.interop.
| Eric Bouchard |
Hello !
Is there anyway to call RegisterClassEx function in user32.lib with managed code ?
[DllImport("USER32")] private static extern int RegisterClassEx(ref WNDCLASSEX wcex);
public delegate int WNDPROC(IntPtr hWnd, uint uMessage, UIntPtr wPraram, IntPtr lParam);
[StructLayout(LayoutKind.Sequential)] public class WNDCLASSEX { public uint cbSize = 48; public uint style = 0; [MarshalAs(UnmanagedType.FunctionPtr)] public WNDPROC lpfnWndProc; public int cbClsExtra = 0; public int cbWndExtra = 0; public IntPtr hInstance = IntPtr.Zero; public IntPtr hIcon = IntPtr.Zero; public IntPtr hCursor = IntPtr.Zero; public IntPtr hbrBackground = IntPtr.Zero; [MarshalAs(UnmanagedType.LPTStr)] public string lpszMenuName = null; [MarshalAs(UnmanagedType.LPTStr)] public string lpszClassName = null; public IntPtr hIconSm = IntPtr.Zero; }
and when I call RegisterClassEx, a non zero value is retured, and GetLastError is 126 (The specified module could not be found.)
can anyone help me ?
|
|
|
| |
|
| |
| |
| Mattias Sjögren |
Eric,
[Original message clipped]
Of course there is :-)
[Original message clipped]
wcex should only be a ref parameter if WNDCLASSEX is defined as a value type (struct). When you make it a reference type (class), you should change it to a by value parameter, decorated with [MarshalAs(UnmanagedType.LPStruct)].
> public uint cbSize = 48;
Magic numbers are bad! ;-) I suggest you use Marshal.SizeOf instead.
[Original message clipped]
You can't rely on what GetLastError returns in managed code. Instead, you should add SetLastError=true to the function's DllImport attribute, and then check the error code with Marshal.GetLastWin32Error after the call.
Mattias
=== Mattias Sjögren [MVP] mattias @ mvps.org http://www.msjogren.net/dotnet/ Please reply only to the newsgroup.
|
|
|
| |
|
| |
|
|
|
|
|
|
|
|
BootFX
Reliable and powerful .NET application framework. |
|
|
|
|
|
|