SendMessage return value
-
Hello, i'm using SendMessage winapi function in my program like this:
[DllImport("user32.dll", SetLastError=true, EntryPoint="SendMessage", CharSet=CharSet.Auto)] public static extern IntPtr SendMessage( IntPtr hWnd, [MarshalAs(UnmanagedType.U4)] int Msg, long wParam, int lParam);
So i'm executing it and i want to use the returned value. But it seems that the returned value is a pointer. How can i get the value? The code is like this:IntPtr hWnd = FindWindow("Winamp v1.x", null); IntPtr lResult = SendMessage(hWnd, WM_WA_IPC, 0, IPC_GETEQDATA);
-- modified at 9:38 Thursday 6th October, 2005 -
Hello, i'm using SendMessage winapi function in my program like this:
[DllImport("user32.dll", SetLastError=true, EntryPoint="SendMessage", CharSet=CharSet.Auto)] public static extern IntPtr SendMessage( IntPtr hWnd, [MarshalAs(UnmanagedType.U4)] int Msg, long wParam, int lParam);
So i'm executing it and i want to use the returned value. But it seems that the returned value is a pointer. How can i get the value? The code is like this:IntPtr hWnd = FindWindow("Winamp v1.x", null); IntPtr lResult = SendMessage(hWnd, WM_WA_IPC, 0, IPC_GETEQDATA);
-- modified at 9:38 Thursday 6th October, 2005 -
Hello, i'm using SendMessage winapi function in my program like this:
[DllImport("user32.dll", SetLastError=true, EntryPoint="SendMessage", CharSet=CharSet.Auto)] public static extern IntPtr SendMessage( IntPtr hWnd, [MarshalAs(UnmanagedType.U4)] int Msg, long wParam, int lParam);
So i'm executing it and i want to use the returned value. But it seems that the returned value is a pointer. How can i get the value? The code is like this:IntPtr hWnd = FindWindow("Winamp v1.x", null); IntPtr lResult = SendMessage(hWnd, WM_WA_IPC, 0, IPC_GETEQDATA);
-- modified at 9:38 Thursday 6th October, 2005I found my problem. It is in the SendMessage declaration. The parameters should be IntPtr instead long and int:
[DllImport("user32.dll", SetLastError=true, EntryPoint="SendMessage", CharSet = CharSet.Auto)] public static extern IntPtr SendMessage( IntPtr hWnd, [MarshalAs(UnmanagedType.U4)] int Msg, IntPtr wParam, IntPtr lParam);
-
I found my problem. It is in the SendMessage declaration. The parameters should be IntPtr instead long and int:
[DllImport("user32.dll", SetLastError=true, EntryPoint="SendMessage", CharSet = CharSet.Auto)] public static extern IntPtr SendMessage( IntPtr hWnd, [MarshalAs(UnmanagedType.U4)] int Msg, IntPtr wParam, IntPtr lParam);
Small correction: You _can_ use int. The only thing that was causing troubles was the
long
declaration, since longs in .NET are 8 byte and not 4 like WPARAM. Oh, and the [MarshalAs...] declaration is superfluous, btw. Regards, mav