I am trying to run a simple windows message pump class under Windows XP using Mono.
When running the following class using mono class1.exe, the app fails to create the hwnd.
Yet running the same class using ms runtime runs perfectly.
Doesnt matter if i compile with mcs or ms compiler - gives same result.
Could it be that the mono jit/mint are not keeping the WNDPROC address fixed?? Not sure - its beyond me.
Can anyone help?
If i can get this to work properly then WOW!
using
System;using
System.Runtime.InteropServices;class
Class1{
static void Main(string[] args){
WNDCLASS wc =
new WNDCLASS();wc.style=0;
wc.lpfnWndProc =
new WNDPROC(MyWndProc);wc.hbrBackground = 6;
wc.lpszClassName = "NativeFormClass";
if (RegisterClass(wc)==0){
Console.WriteLine("Failed to create window class");
}
else{
int hwnd = CreateWindowEx(0, "NativeFormClass", "NativeForm",0x10cf0000,-2147483648, -2147483648, -2147483648, -2147483648,
0, 0,0, 0);
if (hwnd==0){
Console.WriteLine("Failed to create HWND");
}
else{
MSG msgvalue;
while (GetMessage(out msgvalue, 0,0,0)){
TranslateMessage(
ref msgvalue);DispatchMessage(
ref msgvalue);}
Console.WriteLine("Done");
}
}
}
[DllImport("user32", EntryPoint="GetMessageA", CharSet = CharSet.Ansi)]
static extern bool GetMessage(out MSG msgvalue, int hwnd, int minFilter, int maxFilter);[DllImport("user32", EntryPoint="DispatchMessageA", CharSet = CharSet.Ansi)]
static extern int DispatchMessage(ref MSG msgvalue);[DllImport("user32")]
static extern bool TranslateMessage(ref MSG msgValue);[DllImport("user32", EntryPoint="RegisterClassA", CharSet = CharSet.Ansi)]
static extern int RegisterClass(WNDCLASS wc); static int MyWndProc (int hWnd, int msgvalue, int wParam, int lParam){
int retval = 0; switch(msgvalue){
case 2:PostQuitMessage(0);
break; default:retval = DefWindowProc(hWnd, msgvalue, wParam, lParam);
break;}
return retval;}
[StructLayout(LayoutKind.Sequential)]
public struct MSG{
public int hwnd; public int message; public int wParam; public int lParam; public int itime; public int pt_x; public int pt_y;}
[DllImport("user32", EntryPoint="PostQuitMessage")]
static extern void PostQuitMessage(int nExitCode);[DllImport("user32", EntryPoint="DefWindowProcA", CharSet = CharSet.Ansi)]
static extern int DefWindowProc(int hWnd, int msg, int wParam, int lParam);[DllImport("user32", EntryPoint="CreateWindowExA", CharSet =CharSet.Ansi)]
//, CharSet=CharSet.Unicode)] static extern int CreateWindowEx(int dwExStyle, string lpszClassName, string lpszWindowName, int style, int x, int y, int width, int height, int hWndParent, int hMenu, int hInst, int pvParam);[StructLayout(LayoutKind.Sequential)]
public class WNDCLASS{
public int style; public WNDPROC lpfnWndProc; public int cbClsExtra; public int cbWndExtra; public int hInstance; public int hIcon; public int hCursor; public int hbrBackground; public string lpszMenuName; public string lpszClassName;}
public delegate int WNDPROC( int hWnd, int msgvalue, int wParam, int lParam);}
Surf the Web without missing calls!�Get MSN Broadband. Click Here _______________________________________________ Mono-list maillist - [EMAIL PROTECTED] http://lists.ximian.com/mailman/listinfo/mono-list
