I'm trying to call the MessageBox function in the WineLib libuser32.so The attached Class1.cs file works on WinXP (using native user32.dll), but fails on mono (linux)
I found that if I compile Class1.cs on mono (linux) it does not create
the same method-definition.
There seems to be problems (at least) with the DllImport.CharSet and
DllImport.ExactSpelling attributes.
>From my Class1.cs-file:
class Win32Methods{
//mcs & csc il: .method public hidebysig static pinvokeimpl("user32"
ansi)
[DllImport("user32",
CharSet=CharSet.Ansi,ExactSpelling=false,CallingConvention=CallingConven
tion.StdCall)]
public extern static int MessageBox(IntPtr hWnd, string text, string
caption, int type);
//csc il: .method public hidebysig static pinvokeimpl("user32" unicode)
//mcs il: .method public hidebysig static pinvokeimpl("user32" nomangle
ansi)
[DllImport("user32",
CharSet=CharSet.Unicode,ExactSpelling=false,CallingConvention=CallingCon
vention.StdCall)]
public extern static int MessageBoxW(IntPtr hWnd, string text, string
caption, int type);
//mcs & csc il: .method public hidebysig static pinvokeimpl("user32"
ansi)
[DllImport("user32",
CharSet=CharSet.Ansi,ExactSpelling=false,CallingConvention=CallingConven
tion.StdCall)]
public extern static int MessageBoxA(IntPtr hWnd, string text, string
caption, int type);
}
class Win32Methods2{
//csc: .method public hidebysig static pinvokeimpl("user32" nomangle
ansi)
//mcs: .method public hidebysig static pinvokeimpl("user32" ansi)
[DllImport("user32",
CharSet=CharSet.Ansi,ExactSpelling=true,CallingConvention=CallingConvent
ion.StdCall)]
public extern static int MessageBox(IntPtr hWnd, string text, string
caption, int type);
}
-----------------------------
Output running mono on linux:
-----------------------------
** (process:11827): WARNING **: Failed to load function MessageBox from
user32
** (process:11827): WARNING **: Failed to load function MessageBox from
user32
err:heap:HEAP_GetPtr Invalid heap 00000000!
err:heap:HEAP_GetPtr Invalid heap 00000000!
Failure calling Win32Methods.MessageBoxW System.NullReferenceException
A null value was found where an object instance was
requiredSystem.NullReference
Exceptionin (unmanaged) Win32Api.Win32Methods:MessageBoxW ()
in <0x0004a> Win32Api.Class1:Main (string[])
Failure calling Win32Methods.MessageBoxA System.NullReferenceException
A null value was found where an object instance was
requiredSystem.NullReference
Exceptionin (unmanaged) Win32Api.Win32Methods:MessageBoxA ()
in <0x000bf> Win32Api.Class1:Main (string[])
Failure calling Win32Methods.MessageBox System.NotImplementedException
The requested feature is not yet
implementedSystem.NotImplementedExceptionin (un
managed) Win32Api.Win32Methods:MessageBox ()
in <0x00134> Win32Api.Class1:Main (string[])
Failure calling Win32Methods2.MessageBox System.NotImplementedException
The requested feature is not yet
implementedSystem.NotImplementedExceptionin (un
managed) Win32Api.Win32Methods2:MessageBox ()
in <0x001a9> Win32Api.Class1:Main (string[])
------------------------
Output running on WinXP:
------------------------
Failure calling Win32Methods2.MessageBox
System.EntryPointNotFoundException: Unable to find an entry point named
MessageBox in DLL user32.
at Win32Api.Win32Methods2.MessageBox(IntPtr hWnd, String text, String
caption
, Int32 type)
at Win32Api.Class1.Main(String[] args) in
d:\dev\steinar\forms\winforms\class
1.cs:line 46
------------------------
This failure is expected because DllImport.ExactSpelling = true
Any help appreciated.
Steinar Herland
Class1.cs
Description: Class1.cs
