Skip to content

Instantly share code, notes, and snippets.

@timsneath
Last active June 16, 2020 21:21
Show Gist options
  • Save timsneath/dcefb6f8fc03cdab7530d84e256b350a to your computer and use it in GitHub Desktop.
Save timsneath/dcefb6f8fc03cdab7530d84e256b350a to your computer and use it in GitHub Desktop.
Code fragment for embedding. See https://gist.github.com/timsneath/181092c75864001ca37b1b1495b9b396 for a full example that you can run.
typedef MessageBoxNative = Int32 Function(
IntPtr hWnd, Pointer<Utf16> lpText, Pointer<Utf16> lpCaption, Int32 uType);
typedef MessageBoxDart = int Function(
int hWnd, Pointer<Utf16> lpText, Pointer<Utf16> lpCaption, int uType);
final user32 = DynamicLibrary.open('user32.dll');
final win32MessageBox =
user32.lookupFunction<MessageBoxNative, MessageBoxDart>('MessageBoxW');
void showMessageBox(String message, String caption) => win32MessageBox(
0, // No owner window
Utf16.toUtf16(message), // Message
Utf16.toUtf16(caption), // Window title
0 // OK button only
);
showMessageBox('Test Message', 'Window Caption'); // call just like any other Dart function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment