Created
November 12, 2016 23:04
-
-
Save toptensoftware/1760dd3e91cb3561ac0ad375b27c6f26 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class copy_string : Callable | |
| { | |
| public override uint Call32from16(Machine machine, bool hook, bool dlgproc, ref Win16.MSG msg16, ref Win32.MSG msg32, Func<IntPtr> callback) | |
| { | |
| unsafe | |
| { | |
| var str = machine.ReadString(msg16.lParam); | |
| fixed (char* psz = str) | |
| { | |
| msg32.wParam = (IntPtr)msg16.wParam; | |
| msg32.lParam = (IntPtr)psz; | |
| return (uint)(callback()); | |
| } | |
| } | |
| } | |
| public override IntPtr Call16from32(Machine machine, bool hook, bool dlgproc, ref Win32.MSG msg32, ref Win16.MSG msg16, Func<uint> callback) | |
| { | |
| // Get the string | |
| string text = null; | |
| if (msg32.lParam != IntPtr.Zero) | |
| { | |
| text = Marshal.PtrToStringUni(msg32.lParam); | |
| } | |
| // Allocate string | |
| var ptr = machine.SysAllocString(text); | |
| msg16.wParam = msg32.wParam.Loword(); | |
| msg16.lParam = ptr; | |
| // Call | |
| var retv = callback(); | |
| // Cleanup | |
| machine.SysFree(ptr); | |
| return (IntPtr)retv; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment