Last active
March 8, 2023 02:00
-
-
Save aoirint/d63de2cc3e75f17fab994f91fc011f69 to your computer and use it in GitHub Desktop.
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: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