ホーム › UI.WindowsAndMessaging › PostQuitMessage
PostQuitMessage
関数WM_QUITを投函しメッセージループ終了を要求する。
シグネチャ
// USER32.dll
#include <windows.h>
void PostQuitMessage(
INT nExitCode
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| nExitCode | INT | in | アプリケーションの終了コードです。この値は WM_QUIT メッセージの wParam パラメーターとして使用されます。 |
戻り値の型: void
公式ドキュメント
スレッドが終了 (quit) を要求したことをシステムに通知します。通常、WM_DESTROY メッセージへの応答として使用されます。
解説(Remarks)
PostQuitMessage 関数は、スレッドのメッセージ キューに WM_QUIT メッセージをポストし、ただちに制御を返します。この関数は、スレッドが将来のいずれかの時点で終了を要求していることをシステムに通知するだけです。
スレッドがメッセージ キューから WM_QUIT メッセージを取得したら、メッセージ ループを抜け、システムに制御を返す必要があります。システムに返される終了値は、WM_QUIT メッセージの wParam パラメーターでなければなりません。
Examples
例については、Posting a Message を参照してください。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// USER32.dll
#include <windows.h>
void PostQuitMessage(
INT nExitCode
);[DllImport("USER32.dll", ExactSpelling = true)]
static extern void PostQuitMessage(
int nExitCode // INT
);<DllImport("USER32.dll", ExactSpelling:=True)>
Public Shared Sub PostQuitMessage(
nExitCode As Integer ' INT
)
End Sub' nExitCode : INT
Declare PtrSafe Sub PostQuitMessage Lib "user32" ( _
ByVal nExitCode As Long)
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
PostQuitMessage = ctypes.windll.user32.PostQuitMessage
PostQuitMessage.restype = None
PostQuitMessage.argtypes = [
ctypes.c_int, # nExitCode : INT
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('USER32.dll')
PostQuitMessage = Fiddle::Function.new(
lib['PostQuitMessage'],
[
Fiddle::TYPE_INT, # nExitCode : INT
],
Fiddle::TYPE_VOID)#[link(name = "user32")]
extern "system" {
fn PostQuitMessage(
nExitCode: i32 // INT
);
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("USER32.dll")]
public static extern void PostQuitMessage(int nExitCode);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USER32_PostQuitMessage' -Namespace Win32 -PassThru
# $api::PostQuitMessage(nExitCode)#uselib "USER32.dll"
#func global PostQuitMessage "PostQuitMessage" sptr
; PostQuitMessage nExitCode
; nExitCode : INT -> "sptr"#uselib "USER32.dll"
#func global PostQuitMessage "PostQuitMessage" int
; PostQuitMessage nExitCode
; nExitCode : INT -> "int"; void PostQuitMessage(INT nExitCode)
#uselib "USER32.dll"
#func global PostQuitMessage "PostQuitMessage" int
; PostQuitMessage nExitCode
; nExitCode : INT -> "int"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
user32 = windows.NewLazySystemDLL("USER32.dll")
procPostQuitMessage = user32.NewProc("PostQuitMessage")
)
// nExitCode (INT)
r1, _, err := procPostQuitMessage.Call(
uintptr(nExitCode),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // voidprocedure PostQuitMessage(
nExitCode: Integer // INT
); stdcall;
external 'USER32.dll' name 'PostQuitMessage';result := DllCall("USER32\PostQuitMessage"
, "Int", nExitCode ; INT
, "Int") ; return: void●PostQuitMessage(nExitCode) = DLL("USER32.dll", "int PostQuitMessage(int)")
# 呼び出し: PostQuitMessage(nExitCode)
# nExitCode : INT -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "user32" fn PostQuitMessage(
nExitCode: i32 // INT
) callconv(std.os.windows.WINAPI) void;proc PostQuitMessage(
nExitCode: int32 # INT
) {.importc: "PostQuitMessage", stdcall, dynlib: "USER32.dll".}pragma(lib, "user32");
extern(Windows)
void PostQuitMessage(
int nExitCode // INT
);ccall((:PostQuitMessage, "USER32.dll"), stdcall, Cvoid,
(Int32,),
nExitCode)
# nExitCode : INT -> Int32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
void PostQuitMessage(
int32_t nExitCode);
]]
local user32 = ffi.load("user32")
-- user32.PostQuitMessage(nExitCode)
-- nExitCode : INT
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('USER32.dll');
const PostQuitMessage = lib.func('__stdcall', 'PostQuitMessage', 'void', ['int32_t']);
// PostQuitMessage(nExitCode)
// nExitCode : INT -> 'int32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("USER32.dll", {
PostQuitMessage: { parameters: ["i32"], result: "void" },
});
// lib.symbols.PostQuitMessage(nExitCode)
// nExitCode : INT -> "i32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
void PostQuitMessage(
int32_t nExitCode);
C, "USER32.dll");
// $ffi->PostQuitMessage(nExitCode);
// nExitCode : INT
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;
public interface User32 extends StdCallLibrary {
User32 INSTANCE = Native.load("user32", User32.class);
void PostQuitMessage(
int nExitCode // INT
);
}@[Link("user32")]
lib LibUSER32
fun PostQuitMessage = PostQuitMessage(
nExitCode : Int32 # INT
) : Void
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef PostQuitMessageNative = Void Function(Int32);
typedef PostQuitMessageDart = void Function(int);
final PostQuitMessage = DynamicLibrary.open('USER32.dll')
.lookupFunction<PostQuitMessageNative, PostQuitMessageDart>('PostQuitMessage');
// nExitCode : INT -> Int32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
procedure PostQuitMessage(
nExitCode: Integer // INT
); stdcall;
external 'USER32.dll' name 'PostQuitMessage';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "PostQuitMessage"
c_PostQuitMessage :: Int32 -> IO ()
-- nExitCode : INT -> Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let postquitmessage =
foreign "PostQuitMessage"
(int32_t @-> returning void)
(* nExitCode : INT -> int32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library user32 (t "USER32.dll"))
(cffi:use-foreign-library user32)
(cffi:defcfun ("PostQuitMessage" post-quit-message :convention :stdcall) :void
(n-exit-code :int32)) ; INT
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $PostQuitMessage = Win32::API::More->new('USER32',
'void PostQuitMessage(int nExitCode)');
# my $ret = $PostQuitMessage->Call($nExitCode);
# nExitCode : INT -> int
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
公式の関連項目
- f PeekMessageW — キューを調べメッセージを取得する(Unicode、非ブロッキング)。
- f PostMessageW — メッセージをキューに投函し即時に戻る(Unicode)。