Win32 API - Problems with SENDMESSAGE
-
Hello, I have a problem with this code. Signature error, but why?
using System; using System.Collections.Generic; using System.Text; using System.Runtime.InteropServices; using System.Windows.Forms; namespace EnumerateSingle { public struct EditStream { public long dwCookie; public long dwError; public Delegate pfnCallback; } class RichEditC { public const long WM_USER = 0x400; public const long EM_STREAMIN = (WM_USER + 73); public const long EM_STREAMOUT = (WM_USER + 74); public const long SF_TEXT = 0x1 ; public const long SF_RTF = 0x2; public const long SF_RTFNOOBJS = 0x3; public const long SF_TEXTIZED = 0x4; public const long SF_UNICODE = 0x10; public const long SF_USECODEPAGE = 0x20; public const long SF_NCRFORNONASCII = 0x40; public delegate long RTFCallback(long dwCookie, long pbBuff, long cb, long pcb); public string buffText; [DllImport("User32.dll")] public static extern long SendMessage(long hWnd, long wMsg, long wParam, ref EditStream lParam); [DllImport("User32.dll")] public static extern void CopyMemory(object Destination, object source, long length); public static long EditStreamCallback(long dwCookie, long pbBuff, long cb, long pcb) { StringBuilder buff = new StringBuilder((int)cb); switch(dwCookie) { case 999: { CopyMemory(buff, pbBuff, cb); pcb = cb; return 0; } default: { return -1; } } } } }
And the Clientcode:private void button3_Click(object sender, EventArgs e) { RichEditC.RTFCallback myRtfCallback = new RichEditC.RTFCallback(RichEditC.EditStreamCallback); EditStream es = new EditStream(); es.dwCookie = 999; es.pfnCallback = myRtfCallback; //Error------------------------------------------------------------------------> RichEditC.SendMessage(0x80524, RichEditC.EM_STREAMOUT, RichEditC.SF_TEXT, ref es); } public long FARPROC(long pfn) { return pfn;
-
Hello, I have a problem with this code. Signature error, but why?
using System; using System.Collections.Generic; using System.Text; using System.Runtime.InteropServices; using System.Windows.Forms; namespace EnumerateSingle { public struct EditStream { public long dwCookie; public long dwError; public Delegate pfnCallback; } class RichEditC { public const long WM_USER = 0x400; public const long EM_STREAMIN = (WM_USER + 73); public const long EM_STREAMOUT = (WM_USER + 74); public const long SF_TEXT = 0x1 ; public const long SF_RTF = 0x2; public const long SF_RTFNOOBJS = 0x3; public const long SF_TEXTIZED = 0x4; public const long SF_UNICODE = 0x10; public const long SF_USECODEPAGE = 0x20; public const long SF_NCRFORNONASCII = 0x40; public delegate long RTFCallback(long dwCookie, long pbBuff, long cb, long pcb); public string buffText; [DllImport("User32.dll")] public static extern long SendMessage(long hWnd, long wMsg, long wParam, ref EditStream lParam); [DllImport("User32.dll")] public static extern void CopyMemory(object Destination, object source, long length); public static long EditStreamCallback(long dwCookie, long pbBuff, long cb, long pcb) { StringBuilder buff = new StringBuilder((int)cb); switch(dwCookie) { case 999: { CopyMemory(buff, pbBuff, cb); pcb = cb; return 0; } default: { return -1; } } } } }
And the Clientcode:private void button3_Click(object sender, EventArgs e) { RichEditC.RTFCallback myRtfCallback = new RichEditC.RTFCallback(RichEditC.EditStreamCallback); EditStream es = new EditStream(); es.dwCookie = 999; es.pfnCallback = myRtfCallback; //Error------------------------------------------------------------------------> RichEditC.SendMessage(0x80524, RichEditC.EM_STREAMOUT, RichEditC.SF_TEXT, ref es); } public long FARPROC(long pfn) { return pfn;
Try tagging the struct with [StructLayout(LayoutKind.Sequential)] maybe?