[Mono-list] Win32 API problems
A Rafael D Teixeira
rafaelteixeirabr@hotmail.com
Fri, 14 Jun 2002 13:42:18 -0300
>From: Paolo Molaro <lupus@ximian.com>
>
>On 06/13/02 Adiraj, Sarat wrote:
> > [DllImport("user32")]
> > public static extern int MessageBoxA(int hWnd,
> > String pText ,
> > String pCaption ,
> > int uType);
>
>What is the signature of the MessageBoxA() function in C code?
>There may be two issues:
>1) we currently marshal strings as utf8 char*. MessageBoxA() for all I
>know may want UTF-16 (though I guess the 'A' is for ASCII?).
MessageBoxA accepts 8-bit ANSI (with MBCS = Multibyte Character Set ),
MessageBoxW accepts 16-bit UTF-16
BUT you should follow this example:
<SNIP>
using System.Runtime.InteropServices;
public class Win32
{
[DllImport("user32.dll", CharSet=CharSet.Auto)]
public static extern int MessageBox(int hWnd, String text,
String caption, uint type);
}
</SNIP>
And let the marshaller do the string type matching or translation, by
looking at the Charset property of the DllImportAttribute.
Or if really needed:
<SNIP>
public class Win32
{
[DllImport("user32.dll", CharSet=CharSet.Ansi)]
public static extern int MessageBoxA(int hWnd, String text,
String caption, uint type);
}
</SNIP>
I tested both in VS.NET
>2) The call convention: we call the P/Invoke function with th cdecl call
>convention by default. It may be that MessageBoxA() uses another
>convention.
>
AFAIK, the calling convention of every Win32 API is __stdcall (function pops
its parameters from stack), except for a few APIs with a variable number of
parameters (MSVC automatically call them as __cdecl). There´s also some
name-mangling
int MessageBoxA(int hWnd, String text,
String caption, uint type)
is decorated as
_MessageBoxA@16
The '16'-part is because it expects 16 bytes to be pushed in the stack for
its parameters...
Happy hackings...
Rafael Teixeira
Brazilian Developer
_________________________________________________________________
MSN Photos is the easiest way to share and print your photos:
http://photos.msn.com/support/worldwide.aspx