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
#include "windows.h" | |
#include "Shobjidl.h" | |
// vtable_start 4 | |
MIDL_INTERFACE("42f85136-db7e-439c-85f1-e4075d135fc8") | |
IFileDialog : public IModalWindow | |
{ | |
public: | |
virtual HRESULT STDMETHODCALLTYPE SetFileTypes( | |
/* [in] */ UINT cFileTypes, |
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
// Basic Petzoldian "hello world" Win32 app | |
import 'dart:ffi'; | |
import 'package:ffi/ffi.dart'; | |
import 'package:win32/win32.dart'; | |
final hInstance = GetModuleHandle(nullptr); | |
int mainWindowProc(int hWnd, int uMsg, int wParam, int lParam) { |
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
final result = MessageBox( | |
NULL, | |
TEXT("This is one of those messages that nobody will ever read. They'll " | |
"just click the default button, and about a millisecond later, " | |
"they'll experience a pang of concern as they wonder whether Windows " | |
"was giving them one last opportunity to perform a critical task " | |
"before all their files were wiped.\n\nWhat even is the difference " | |
"between Cancel, Try Again and Continue?"), | |
TEXT('Critical system message'), | |
MB_ICONEXCLAMATION | // Warning |
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
// C signature for Win32 API in kernel32.dll: | |
// BOOL WINAPI SetConsoleCursorPosition( | |
// _In_ HANDLE hConsoleOutput, | |
// _In_ COORD dwCursorPosition | |
// ); | |
typedef nativePrototype = Int32 Function( | |
IntPtr hConsoleOutput, Int32 dwCursorPos); | |
typedef dartPrototype = int Function(int hConsoleOutput, int dwCursorPos); |
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
import 'dart:math' as math; | |
import 'package:flutter/material.dart'; | |
import 'package:flutter/rendering.dart'; | |
import 'package:flutter/gestures.dart'; | |
const double kTwoPi = 2 * math.pi; | |
class SectorConstraints extends Constraints { | |
const SectorConstraints({ |
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
int error() { | |
try { | |
return 0; | |
} finally { | |
print('finally entered'); | |
} | |
} | |
void main() { | |
try { |
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
// struct XrApplicationInfo { | |
// char applicationName[128]; // 128 bytes | |
// uint32_t applicationVersion; // 4 bytes | |
// char engineName[128]; // 128 bytes | |
// uint32_t engineVersion; // 4 bytes | |
// XrVersion apiVersion; // assume this is a uint64_t, i.e. 8 bytes | |
// }; | |
class XrApplicationInfo extends Struct { | |
Pointer<Utf8> get applicationName => addressOf.cast<Utf8>(); |
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
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( |
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
// msgbox.dart | |
// Demonstrates a simple example of calling a Win32 API directly from Dart code. | |
// This sample relies on the ffi package. Download these two files to an empty | |
// directory and run `pub get` to download the ffi package prior to running this | |
// example. | |
import 'dart:ffi'; | |
import 'package:ffi/ffi.dart'; |
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
String numToString(BigInt number) { | |
final buf = StringBuffer(); | |
for (var v = 0; v < 8; v++) { | |
final charCode = (number & BigInt.parse('0xFF' + ('00' * v))) >> v * 8; | |
buf.write(String.fromCharCode(charCode.toInt())); | |
} | |
return buf.toString(); | |
} |