Skip to content

Instantly share code, notes, and snippets.

@toptensoftware
Created October 19, 2016 03:08
Show Gist options
  • Select an option

  • Save toptensoftware/0be3db0021661daec318d1d685315d89 to your computer and use it in GitHub Desktop.

Select an option

Save toptensoftware/0be3db0021661daec318d1d685315d89 to your computer and use it in GitHub Desktop.
MessageBox using reflection for parameters
// The real API method imported from Windows
[DllImport(“user32.dll”)]
static extern uint MessageBox(IntPtr hWndParent, string msg, string title, uint options);
// Implementation method exported to 16-bit code
[EntryPoint(0x0001)]
public ushort MessageBox(ushort hWndParent, string msg, string title, ushort options)
{
// No more messing around with the VM stack for parameters
// nor with the ax register for the return value. Nice!
return (ushort)MessageBox(IntPtr.Zero, msg, title, (uint)options);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment