Topaz Filer: if you use e-mail for business, we can save you money and decrease your risk.
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 ?

Reply to this message...
Vote that this is a GOOD answer...
 
Auto-following on Twitter
Ubuntu and XP on one “desktop”
 
    
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.
Reply to this message...
Vote that this is a GOOD answer...
 
Outlook interop - stopping user properties appearing on Outlook message print
Seriously, why is “cut and paste” majorly newsworthy???
 
 
System.IntPtr
System.Runtime.InteropServices.LayoutKind
System.Runtime.InteropServices.Marshal
System.Runtime.InteropServices.UnmanagedType
System.UIntPtr




Ad
BootFX
Reliable and powerful .NET application framework.
Recession Busting Bespoke Software
Get through the recession by investing in bespoke software to decrease costs and create commercial opportunities.
Other DN247 Network Sites
.NET 247
SQL Server Wins
Old Skool Developer
 
Copyright © AMX Software Ltd 2008-2009. Portions copyright © Matthew Baxter-Reynolds 2001-2009. All rights reserved.
Contact Us - Terms of Use - Privacy Policy - .NET 247 is a member of the DN247 Network - 4.0.30129.1734