1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

SetConsoleCtrlHandlerで登録したハンドラ関数を実行するスレッド

Last updated at Posted at 2016-01-23

Windows APIのSetConsoleCtrlHandler()で登録したハンドラ関数が呼び出される際、メインスレッドとは別のスレッドが新たに生成されて実行されます。以下、確認用のコード。

ConsoleCtrlTest.c
#include <stdio.h>
#include <windows.h>

BOOL WINAPI HandlerRoutine(__in DWORD dwCtrlType);

int main(int argc, CHAR *argv[])
{
    SetConsoleCtrlHandler(HandlerRoutine, TRUE);

    printf("main : %d\n", GetCurrentThreadId());

    for(;;);

    return 0;
}

BOOL WINAPI HandlerRoutine(DWORD dwCtrlType)
{
    printf("HanlerRoutine : %d\n", GetCurrentThreadId());

    return FALSE;
}

#参考文献

  1. MSDN : SetConsoleCtrlHandler 関数
1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?