Skip to content

Instantly share code, notes, and snippets.

@aoirint
Last active March 8, 2023 02:00
Show Gist options
  • Save aoirint/d63de2cc3e75f17fab994f91fc011f69 to your computer and use it in GitHub Desktop.
Save aoirint/d63de2cc3e75f17fab994f91fc011f69 to your computer and use it in GitHub Desktop.
import 'dart:ffi';
import 'dart:io';
import 'package:ffi/ffi.dart';
import 'package:win32/win32.dart';
const CTRL_CLOSE_EVENT = 2;
final _handlerRoutine = Pointer.fromFunction<Uint32 Function(Uint32)>(consoleCtrlHandler, 0);
Future<void> executePostProcess() async {
await File('Hello.txt').create();
}
int consoleCtrlHandler(int event) {
if (event == CTRL_CLOSE_EVENT) {
// TODO: executePostProcessを呼び出す(see: https://github.com/dart-lang/sdk/issues/37022)
return 1;
}
return 0;
}
void main() {
// Ctrl-C による中断を無効化する
SetConsoleCtrlHandler(nullptr, 1);
// 終了処理を行うための Ctrl-C ハンドラーを登録する
SetConsoleCtrlHandler(_handlerRoutine, 1);
// メッセージループを開始する
var msg = calloc<MSG>();
while (GetMessage(msg, 0, 0, 0) != 0) {
TranslateMessage(msg);
DispatchMessage(msg);
}
free(msg);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment