Skip to content

Instantly share code, notes, and snippets.

View toptensoftware's full-sized avatar

Brad Robinson toptensoftware

View GitHub Profile
// Call a 16-bit window procedure
public IntPtr CallWndProc16from32(uint pfnProc, IntPtr hWnd, uint message, IntPtr wParam, IntPtr lParam, bool dlgProc)
{
// Put it into structure
var msg32 = new Win32.MSG()
{
hWnd = hWnd,
message = message,
wParam = wParam,
lParam = lParam,
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;
class hwnd_copy : Postable
{
public override void To32(Machine machine, ref Win16.MSG msg16, ref Win32.MSG msg32)
{
msg32.wParam = HWND.Map.To32(msg16.wParam);
msg32.lParam = (IntPtr)(int)msg16.lParam;
}
public override void To16(Machine machine, ref Win32.MSG msg32, ref Win16.MSG msg16)
{
abstract class Callable : Base
{
public override bool ShouldBypass(Machine machine, ref Win32.MSG msg)
{
return false;
}
public abstract uint Call32from16(
Machine machine, bool hook, bool dlgproc,
ref Win16.MSG msg16, ref Win32.MSG msg32,
abstract class Postable : Base
{
public override bool ShouldBypass(Machine machine, ref Win32.MSG msg)
{
return false;
}
public abstract void To32(Machine machine, ref Win16.MSG msg16, ref Win32.MSG msg32);
public abstract void To16(Machine machine, ref Win32.MSG msg32, ref Win16.MSG msg16);
}
class MessageMap
{
public MessageSemantics.Base LookupMessage32(IntPtr hWnd, uint message32, out ushort message16)
public MessageSemantics.Base LookupMessage16(IntPtr hWnd, ushort message16, out uint message32)
}
abstract class MessageSemantics.Base
{
public abstract bool ShouldBypass(Machine machine, ref Win32.MSG msg);
}
// Wrap a 16-bit virtual window procedure in a managed delegate that
// when invoked will call the virtual proc.
public IntPtr GetWndProc32(uint lpfnWndProc)
{
if (lpfnWndProc == 0)
return IntPtr.Zero;
// Check if already wrapped
IntPtr wndProc32 = WndProcMap.To32(lpfnWndProc);
if (wndProc32!=IntPtr.Zero)
// Call a Win32 window procedure from 16-bit code
public uint CallWndProc32from16(IntPtr pfnProc32, ushort hWnd16, ushort message16, ushort wParam16, uint lParam16)
// Call a 16-bit window procedure from Win32 code
public IntPtr CallWndProc16from32(uint pfnProc16, IntPtr hWnd32, uint message32, IntPtr wParam32, IntPtr lParam32)
[MappedType]
public struct HDC
{
// Win32 handle value
public IntPtr value;
// The map
public static HandleMap Map = new HandleMap();
// Methods required by MappedType's
public class HandleMap
{
// Map between environments
public IntPtr To32(ushort handle16)
public ushort To16(IntPtr handle32)
// Remove destroyed handles
public void Destroy32(IntPtr handle32);
public void Destroy16(ushort handle16);