RegisterAppStateChangeNotification
関数アプリの状態変更通知コールバックを登録する。
シグネチャ
// api-ms-win-core-psm-appnotify-l1-1-0.dll
#include <windows.h>
DWORD RegisterAppStateChangeNotification(
PAPPSTATE_CHANGE_ROUTINE Routine,
void* Context, // optional
PAPPSTATE_REGISTRATION* Registration
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| Routine | PAPPSTATE_CHANGE_ROUTINE | in | アプリがサスペンド状態に入る、またはサスペンド状態から復帰するときに呼び出されるコールバック関数へのポインター。この関数の詳細については PAPPSTATE_CHANGE_ROUTINE を参照してください。 |
| Context | void* | inoptional | サスペンド状態への移行時または復帰時にアプリが使用する、アプリ固有のコンテキスト情報。通常は "this" ポインターです。 |
| Registration | PAPPSTATE_REGISTRATION* | out | この関数が正常に返ると、このパラメーターは登録を識別するために使用できる値へのポインターのアドレスを受け取ります。この値を保存し、UnregisterAppStateChangeNotification で使用してください。 |
戻り値の型: DWORD
公式ドキュメント
アプリが、ライブラリがサスペンド状態に入る、またはサスペンド状態から復帰することを通知されるためのコールバック関数を登録できるようにします。
戻り値
標準的な Win32 ステータスコード。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// api-ms-win-core-psm-appnotify-l1-1-0.dll
#include <windows.h>
DWORD RegisterAppStateChangeNotification(
PAPPSTATE_CHANGE_ROUTINE Routine,
void* Context, // optional
PAPPSTATE_REGISTRATION* Registration
);[DllImport("api-ms-win-core-psm-appnotify-l1-1-0.dll", ExactSpelling = true)]
static extern uint RegisterAppStateChangeNotification(
IntPtr Routine, // PAPPSTATE_CHANGE_ROUTINE
IntPtr Context, // void* optional
out IntPtr Registration // PAPPSTATE_REGISTRATION* out
);<DllImport("api-ms-win-core-psm-appnotify-l1-1-0.dll", ExactSpelling:=True)>
Public Shared Function RegisterAppStateChangeNotification(
Routine As IntPtr, ' PAPPSTATE_CHANGE_ROUTINE
Context As IntPtr, ' void* optional
<Out> ByRef Registration As IntPtr ' PAPPSTATE_REGISTRATION* out
) As UInteger
End Function' Routine : PAPPSTATE_CHANGE_ROUTINE
' Context : void* optional
' Registration : PAPPSTATE_REGISTRATION* out
Declare PtrSafe Function RegisterAppStateChangeNotification Lib "api-ms-win-core-psm-appnotify-l1-1-0" ( _
ByVal Routine As LongPtr, _
ByVal Context As LongPtr, _
ByRef Registration As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
RegisterAppStateChangeNotification = ctypes.windll.LoadLibrary("api-ms-win-core-psm-appnotify-l1-1-0.dll").RegisterAppStateChangeNotification
RegisterAppStateChangeNotification.restype = wintypes.DWORD
RegisterAppStateChangeNotification.argtypes = [
ctypes.c_void_p, # Routine : PAPPSTATE_CHANGE_ROUTINE
ctypes.POINTER(None), # Context : void* optional
ctypes.c_void_p, # Registration : PAPPSTATE_REGISTRATION* out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('api-ms-win-core-psm-appnotify-l1-1-0.dll')
RegisterAppStateChangeNotification = Fiddle::Function.new(
lib['RegisterAppStateChangeNotification'],
[
Fiddle::TYPE_VOIDP, # Routine : PAPPSTATE_CHANGE_ROUTINE
Fiddle::TYPE_VOIDP, # Context : void* optional
Fiddle::TYPE_VOIDP, # Registration : PAPPSTATE_REGISTRATION* out
],
-Fiddle::TYPE_INT)#[link(name = "api-ms-win-core-psm-appnotify-l1-1-0")]
extern "system" {
fn RegisterAppStateChangeNotification(
Routine: *const core::ffi::c_void, // PAPPSTATE_CHANGE_ROUTINE
Context: *mut (), // void* optional
Registration: *mut isize // PAPPSTATE_REGISTRATION* out
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("api-ms-win-core-psm-appnotify-l1-1-0.dll")]
public static extern uint RegisterAppStateChangeNotification(IntPtr Routine, IntPtr Context, out IntPtr Registration);
"@
$api = Add-Type -MemberDefinition $sig -Name 'api-ms-win-core-psm-appnotify-l1-1-0_RegisterAppStateChangeNotification' -Namespace Win32 -PassThru
# $api::RegisterAppStateChangeNotification(Routine, Context, Registration)#uselib "api-ms-win-core-psm-appnotify-l1-1-0.dll"
#func global RegisterAppStateChangeNotification "RegisterAppStateChangeNotification" sptr, sptr, sptr
; RegisterAppStateChangeNotification Routine, Context, varptr(Registration) ; 戻り値は stat
; Routine : PAPPSTATE_CHANGE_ROUTINE -> "sptr"
; Context : void* optional -> "sptr"
; Registration : PAPPSTATE_REGISTRATION* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "api-ms-win-core-psm-appnotify-l1-1-0.dll" #cfunc global RegisterAppStateChangeNotification "RegisterAppStateChangeNotification" sptr, sptr, var ; res = RegisterAppStateChangeNotification(Routine, Context, Registration) ; Routine : PAPPSTATE_CHANGE_ROUTINE -> "sptr" ; Context : void* optional -> "sptr" ; Registration : PAPPSTATE_REGISTRATION* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "api-ms-win-core-psm-appnotify-l1-1-0.dll" #cfunc global RegisterAppStateChangeNotification "RegisterAppStateChangeNotification" sptr, sptr, sptr ; res = RegisterAppStateChangeNotification(Routine, Context, varptr(Registration)) ; Routine : PAPPSTATE_CHANGE_ROUTINE -> "sptr" ; Context : void* optional -> "sptr" ; Registration : PAPPSTATE_REGISTRATION* out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; DWORD RegisterAppStateChangeNotification(PAPPSTATE_CHANGE_ROUTINE Routine, void* Context, PAPPSTATE_REGISTRATION* Registration) #uselib "api-ms-win-core-psm-appnotify-l1-1-0.dll" #cfunc global RegisterAppStateChangeNotification "RegisterAppStateChangeNotification" intptr, intptr, var ; res = RegisterAppStateChangeNotification(Routine, Context, Registration) ; Routine : PAPPSTATE_CHANGE_ROUTINE -> "intptr" ; Context : void* optional -> "intptr" ; Registration : PAPPSTATE_REGISTRATION* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; DWORD RegisterAppStateChangeNotification(PAPPSTATE_CHANGE_ROUTINE Routine, void* Context, PAPPSTATE_REGISTRATION* Registration) #uselib "api-ms-win-core-psm-appnotify-l1-1-0.dll" #cfunc global RegisterAppStateChangeNotification "RegisterAppStateChangeNotification" intptr, intptr, intptr ; res = RegisterAppStateChangeNotification(Routine, Context, varptr(Registration)) ; Routine : PAPPSTATE_CHANGE_ROUTINE -> "intptr" ; Context : void* optional -> "intptr" ; Registration : PAPPSTATE_REGISTRATION* out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
api_ms_win_core_psm_appnotify_l1_1_0 = windows.NewLazySystemDLL("api-ms-win-core-psm-appnotify-l1-1-0.dll")
procRegisterAppStateChangeNotification = api_ms_win_core_psm_appnotify_l1_1_0.NewProc("RegisterAppStateChangeNotification")
)
// Routine (PAPPSTATE_CHANGE_ROUTINE), Context (void* optional), Registration (PAPPSTATE_REGISTRATION* out)
r1, _, err := procRegisterAppStateChangeNotification.Call(
uintptr(Routine),
uintptr(Context),
uintptr(Registration),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction RegisterAppStateChangeNotification(
Routine: Pointer; // PAPPSTATE_CHANGE_ROUTINE
Context: Pointer; // void* optional
Registration: Pointer // PAPPSTATE_REGISTRATION* out
): DWORD; stdcall;
external 'api-ms-win-core-psm-appnotify-l1-1-0.dll' name 'RegisterAppStateChangeNotification';result := DllCall("api-ms-win-core-psm-appnotify-l1-1-0\RegisterAppStateChangeNotification"
, "Ptr", Routine ; PAPPSTATE_CHANGE_ROUTINE
, "Ptr", Context ; void* optional
, "Ptr", Registration ; PAPPSTATE_REGISTRATION* out
, "UInt") ; return: DWORD●RegisterAppStateChangeNotification(Routine, Context, Registration) = DLL("api-ms-win-core-psm-appnotify-l1-1-0.dll", "dword RegisterAppStateChangeNotification(void*, void*, void*)")
# 呼び出し: RegisterAppStateChangeNotification(Routine, Context, Registration)
# Routine : PAPPSTATE_CHANGE_ROUTINE -> "void*"
# Context : void* optional -> "void*"
# Registration : PAPPSTATE_REGISTRATION* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "api-ms-win-core-psm-appnotify-l1-1-0" fn RegisterAppStateChangeNotification(
Routine: ?*anyopaque, // PAPPSTATE_CHANGE_ROUTINE
Context: ?*anyopaque, // void* optional
Registration: [*c]isize // PAPPSTATE_REGISTRATION* out
) callconv(std.os.windows.WINAPI) u32;proc RegisterAppStateChangeNotification(
Routine: pointer, # PAPPSTATE_CHANGE_ROUTINE
Context: pointer, # void* optional
Registration: ptr int # PAPPSTATE_REGISTRATION* out
): uint32 {.importc: "RegisterAppStateChangeNotification", stdcall, dynlib: "api-ms-win-core-psm-appnotify-l1-1-0.dll".}pragma(lib, "api-ms-win-core-psm-appnotify-l1-1-0");
extern(Windows)
uint RegisterAppStateChangeNotification(
void* Routine, // PAPPSTATE_CHANGE_ROUTINE
void* Context, // void* optional
ptrdiff_t* Registration // PAPPSTATE_REGISTRATION* out
);ccall((:RegisterAppStateChangeNotification, "api-ms-win-core-psm-appnotify-l1-1-0.dll"), stdcall, UInt32,
(Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Int}),
Routine, Context, Registration)
# Routine : PAPPSTATE_CHANGE_ROUTINE -> Ptr{Cvoid}
# Context : void* optional -> Ptr{Cvoid}
# Registration : PAPPSTATE_REGISTRATION* out -> Ptr{Int}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
uint32_t RegisterAppStateChangeNotification(
void* Routine,
void* Context,
intptr_t* Registration);
]]
local api-ms-win-core-psm-appnotify-l1-1-0 = ffi.load("api-ms-win-core-psm-appnotify-l1-1-0")
-- api-ms-win-core-psm-appnotify-l1-1-0.RegisterAppStateChangeNotification(Routine, Context, Registration)
-- Routine : PAPPSTATE_CHANGE_ROUTINE
-- Context : void* optional
-- Registration : PAPPSTATE_REGISTRATION* out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('api-ms-win-core-psm-appnotify-l1-1-0.dll');
const RegisterAppStateChangeNotification = lib.func('__stdcall', 'RegisterAppStateChangeNotification', 'uint32_t', ['void *', 'void *', 'intptr_t *']);
// RegisterAppStateChangeNotification(Routine, Context, Registration)
// Routine : PAPPSTATE_CHANGE_ROUTINE -> 'void *'
// Context : void* optional -> 'void *'
// Registration : PAPPSTATE_REGISTRATION* out -> 'intptr_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
// コールバック(関数ポインタ)は koffi.proto/koffi.register で型を定義して渡す(素の void* では JS 関数を渡せない)。const lib = Deno.dlopen("api-ms-win-core-psm-appnotify-l1-1-0.dll", {
RegisterAppStateChangeNotification: { parameters: ["pointer", "pointer", "pointer"], result: "u32" },
});
// lib.symbols.RegisterAppStateChangeNotification(Routine, Context, Registration)
// Routine : PAPPSTATE_CHANGE_ROUTINE -> "pointer"
// Context : void* optional -> "pointer"
// Registration : PAPPSTATE_REGISTRATION* out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t RegisterAppStateChangeNotification(
void* Routine,
void* Context,
intptr_t* Registration);
C, "api-ms-win-core-psm-appnotify-l1-1-0.dll");
// $ffi->RegisterAppStateChangeNotification(Routine, Context, Registration);
// Routine : PAPPSTATE_CHANGE_ROUTINE
// Context : void* optional
// Registration : PAPPSTATE_REGISTRATION* out
// 構造体/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 Api-ms-win-core-psm-appnotify-l1-1-0 extends StdCallLibrary {
Api-ms-win-core-psm-appnotify-l1-1-0 INSTANCE = Native.load("api-ms-win-core-psm-appnotify-l1-1-0", Api-ms-win-core-psm-appnotify-l1-1-0.class);
int RegisterAppStateChangeNotification(
Callback Routine, // PAPPSTATE_CHANGE_ROUTINE
Pointer Context, // void* optional
LongByReference Registration // PAPPSTATE_REGISTRATION* out
);
}@[Link("api-ms-win-core-psm-appnotify-l1-1-0")]
lib Libapi-ms-win-core-psm-appnotify-l1-1-0
fun RegisterAppStateChangeNotification = RegisterAppStateChangeNotification(
Routine : Void*, # PAPPSTATE_CHANGE_ROUTINE
Context : Void*, # void* optional
Registration : LibC::SSizeT* # PAPPSTATE_REGISTRATION* out
) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef RegisterAppStateChangeNotificationNative = Uint32 Function(Pointer<Void>, Pointer<Void>, Pointer<IntPtr>);
typedef RegisterAppStateChangeNotificationDart = int Function(Pointer<Void>, Pointer<Void>, Pointer<IntPtr>);
final RegisterAppStateChangeNotification = DynamicLibrary.open('api-ms-win-core-psm-appnotify-l1-1-0.dll')
.lookupFunction<RegisterAppStateChangeNotificationNative, RegisterAppStateChangeNotificationDart>('RegisterAppStateChangeNotification');
// Routine : PAPPSTATE_CHANGE_ROUTINE -> Pointer<Void>
// Context : void* optional -> Pointer<Void>
// Registration : PAPPSTATE_REGISTRATION* out -> Pointer<IntPtr>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function RegisterAppStateChangeNotification(
Routine: Pointer; // PAPPSTATE_CHANGE_ROUTINE
Context: Pointer; // void* optional
Registration: Pointer // PAPPSTATE_REGISTRATION* out
): DWORD; stdcall;
external 'api-ms-win-core-psm-appnotify-l1-1-0.dll' name 'RegisterAppStateChangeNotification';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "RegisterAppStateChangeNotification"
c_RegisterAppStateChangeNotification :: Ptr () -> Ptr () -> Ptr CIntPtr -> IO Word32
-- Routine : PAPPSTATE_CHANGE_ROUTINE -> Ptr ()
-- Context : void* optional -> Ptr ()
-- Registration : PAPPSTATE_REGISTRATION* out -> Ptr CIntPtr
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let registerappstatechangenotification =
foreign "RegisterAppStateChangeNotification"
((ptr void) @-> (ptr void) @-> (ptr intptr_t) @-> returning uint32_t)
(* Routine : PAPPSTATE_CHANGE_ROUTINE -> (ptr void) *)
(* Context : void* optional -> (ptr void) *)
(* Registration : PAPPSTATE_REGISTRATION* out -> (ptr intptr_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library api-ms-win-core-psm-appnotify-l1-1-0 (t "api-ms-win-core-psm-appnotify-l1-1-0.dll"))
(cffi:use-foreign-library api-ms-win-core-psm-appnotify-l1-1-0)
(cffi:defcfun ("RegisterAppStateChangeNotification" register-app-state-change-notification :convention :stdcall) :uint32
(routine :pointer) ; PAPPSTATE_CHANGE_ROUTINE
(context :pointer) ; void* optional
(registration :pointer)) ; PAPPSTATE_REGISTRATION* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $RegisterAppStateChangeNotification = Win32::API::More->new('api-ms-win-core-psm-appnotify-l1-1-0',
'DWORD RegisterAppStateChangeNotification(LPVOID Routine, LPVOID Context, LPVOID Registration)');
# my $ret = $RegisterAppStateChangeNotification->Call($Routine, $Context, $Registration);
# Routine : PAPPSTATE_CHANGE_ROUTINE -> LPVOID
# Context : void* optional -> LPVOID
# Registration : PAPPSTATE_REGISTRATION* out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# コールバック(関数ポインタ)は Perl sub を直接渡せません。Win32::API::Callback を使用してください。関連項目
公式の関連項目
- f UnregisterAppStateChangeNotification — アプリ状態変更通知の登録を解除する。