Win32 API 日本語リファレンス
ホームSystem.Power › PowerRegisterSuspendResumeNotification

PowerRegisterSuspendResumeNotification

関数
サスペンドおよびレジューム通知の受信を登録する。
DLLPOWRPROF.dll呼出規約winapi対応OSwindows8.0

シグネチャ

// POWRPROF.dll
#include <windows.h>

WIN32_ERROR PowerRegisterSuspendResumeNotification(
    REGISTER_NOTIFICATION_FLAGS Flags,
    HANDLE Recipient,
    void** RegistrationHandle
);

パラメーター

名前方向説明
FlagsREGISTER_NOTIFICATION_FLAGSinこのパラメーターは DEVICE_NOTIFY_CALLBACK である必要があります。
RecipientHANDLEinこのパラメーターは DEVICE_NOTIFY_SUBSCRIBE_PARAMETERS 構造体へのポインターです。この場合、コールバック関数は DeviceNotifyCallbackRoutine です。Callback 関数が実行されると、発生したイベントの種類を示す Type パラメーターが設定されます。指定され得る値には PBT_APMSUSPENDPBT_APMRESUMESUSPENDPBT_APMRESUMEAUTOMATIC があります。詳細については Power Management Events を参照してください。Setting パラメーターはサスペンド/再開通知では使用されません。
RegistrationHandlevoid**out登録へのハンドルです。通知の登録を解除するにはこのハンドルを使用します。

戻り値の型: WIN32_ERROR

公式ドキュメント

システムがサスペンドまたは再開されたときに通知を受け取るための登録を行います。

戻り値

呼び出しが成功した場合は ERROR_SUCCESS(ゼロ)を返し、失敗した場合は非ゼロの値を返します。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

// POWRPROF.dll
#include <windows.h>

WIN32_ERROR PowerRegisterSuspendResumeNotification(
    REGISTER_NOTIFICATION_FLAGS Flags,
    HANDLE Recipient,
    void** RegistrationHandle
);
[DllImport("POWRPROF.dll", ExactSpelling = true)]
static extern uint PowerRegisterSuspendResumeNotification(
    uint Flags,   // REGISTER_NOTIFICATION_FLAGS
    IntPtr Recipient,   // HANDLE
    IntPtr RegistrationHandle   // void** out
);
<DllImport("POWRPROF.dll", ExactSpelling:=True)>
Public Shared Function PowerRegisterSuspendResumeNotification(
    Flags As UInteger,   ' REGISTER_NOTIFICATION_FLAGS
    Recipient As IntPtr,   ' HANDLE
    RegistrationHandle As IntPtr   ' void** out
) As UInteger
End Function
' Flags : REGISTER_NOTIFICATION_FLAGS
' Recipient : HANDLE
' RegistrationHandle : void** out
Declare PtrSafe Function PowerRegisterSuspendResumeNotification Lib "powrprof" ( _
    ByVal Flags As Long, _
    ByVal Recipient As LongPtr, _
    ByVal RegistrationHandle As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

PowerRegisterSuspendResumeNotification = ctypes.windll.powrprof.PowerRegisterSuspendResumeNotification
PowerRegisterSuspendResumeNotification.restype = wintypes.DWORD
PowerRegisterSuspendResumeNotification.argtypes = [
    wintypes.DWORD,  # Flags : REGISTER_NOTIFICATION_FLAGS
    wintypes.HANDLE,  # Recipient : HANDLE
    ctypes.c_void_p,  # RegistrationHandle : void** out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('POWRPROF.dll')
PowerRegisterSuspendResumeNotification = Fiddle::Function.new(
  lib['PowerRegisterSuspendResumeNotification'],
  [
    -Fiddle::TYPE_INT,  # Flags : REGISTER_NOTIFICATION_FLAGS
    Fiddle::TYPE_VOIDP,  # Recipient : HANDLE
    Fiddle::TYPE_VOIDP,  # RegistrationHandle : void** out
  ],
  -Fiddle::TYPE_INT)
#[link(name = "powrprof")]
extern "system" {
    fn PowerRegisterSuspendResumeNotification(
        Flags: u32,  // REGISTER_NOTIFICATION_FLAGS
        Recipient: *mut core::ffi::c_void,  // HANDLE
        RegistrationHandle: *mut *mut ()  // void** out
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("POWRPROF.dll")]
public static extern uint PowerRegisterSuspendResumeNotification(uint Flags, IntPtr Recipient, IntPtr RegistrationHandle);
"@
$api = Add-Type -MemberDefinition $sig -Name 'POWRPROF_PowerRegisterSuspendResumeNotification' -Namespace Win32 -PassThru
# $api::PowerRegisterSuspendResumeNotification(Flags, Recipient, RegistrationHandle)
#uselib "POWRPROF.dll"
#func global PowerRegisterSuspendResumeNotification "PowerRegisterSuspendResumeNotification" sptr, sptr, sptr
; PowerRegisterSuspendResumeNotification Flags, Recipient, RegistrationHandle   ; 戻り値は stat
; Flags : REGISTER_NOTIFICATION_FLAGS -> "sptr"
; Recipient : HANDLE -> "sptr"
; RegistrationHandle : void** out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "POWRPROF.dll"
#cfunc global PowerRegisterSuspendResumeNotification "PowerRegisterSuspendResumeNotification" int, sptr, sptr
; res = PowerRegisterSuspendResumeNotification(Flags, Recipient, RegistrationHandle)
; Flags : REGISTER_NOTIFICATION_FLAGS -> "int"
; Recipient : HANDLE -> "sptr"
; RegistrationHandle : void** out -> "sptr"
; WIN32_ERROR PowerRegisterSuspendResumeNotification(REGISTER_NOTIFICATION_FLAGS Flags, HANDLE Recipient, void** RegistrationHandle)
#uselib "POWRPROF.dll"
#cfunc global PowerRegisterSuspendResumeNotification "PowerRegisterSuspendResumeNotification" int, intptr, intptr
; res = PowerRegisterSuspendResumeNotification(Flags, Recipient, RegistrationHandle)
; Flags : REGISTER_NOTIFICATION_FLAGS -> "int"
; Recipient : HANDLE -> "intptr"
; RegistrationHandle : void** out -> "intptr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	powrprof = windows.NewLazySystemDLL("POWRPROF.dll")
	procPowerRegisterSuspendResumeNotification = powrprof.NewProc("PowerRegisterSuspendResumeNotification")
)

// Flags (REGISTER_NOTIFICATION_FLAGS), Recipient (HANDLE), RegistrationHandle (void** out)
r1, _, err := procPowerRegisterSuspendResumeNotification.Call(
	uintptr(Flags),
	uintptr(Recipient),
	uintptr(RegistrationHandle),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // WIN32_ERROR
function PowerRegisterSuspendResumeNotification(
  Flags: DWORD;   // REGISTER_NOTIFICATION_FLAGS
  Recipient: THandle;   // HANDLE
  RegistrationHandle: Pointer   // void** out
): DWORD; stdcall;
  external 'POWRPROF.dll' name 'PowerRegisterSuspendResumeNotification';
result := DllCall("POWRPROF\PowerRegisterSuspendResumeNotification"
    , "UInt", Flags   ; REGISTER_NOTIFICATION_FLAGS
    , "Ptr", Recipient   ; HANDLE
    , "Ptr", RegistrationHandle   ; void** out
    , "UInt")   ; return: WIN32_ERROR
●PowerRegisterSuspendResumeNotification(Flags, Recipient, RegistrationHandle) = DLL("POWRPROF.dll", "dword PowerRegisterSuspendResumeNotification(dword, void*, void*)")
# 呼び出し: PowerRegisterSuspendResumeNotification(Flags, Recipient, RegistrationHandle)
# Flags : REGISTER_NOTIFICATION_FLAGS -> "dword"
# Recipient : HANDLE -> "void*"
# RegistrationHandle : void** out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "powrprof" fn PowerRegisterSuspendResumeNotification(
    Flags: u32, // REGISTER_NOTIFICATION_FLAGS
    Recipient: ?*anyopaque, // HANDLE
    RegistrationHandle: ?*anyopaque // void** out
) callconv(std.os.windows.WINAPI) u32;
proc PowerRegisterSuspendResumeNotification(
    Flags: uint32,  # REGISTER_NOTIFICATION_FLAGS
    Recipient: pointer,  # HANDLE
    RegistrationHandle: pointer  # void** out
): uint32 {.importc: "PowerRegisterSuspendResumeNotification", stdcall, dynlib: "POWRPROF.dll".}
pragma(lib, "powrprof");
extern(Windows)
uint PowerRegisterSuspendResumeNotification(
    uint Flags,   // REGISTER_NOTIFICATION_FLAGS
    void* Recipient,   // HANDLE
    void** RegistrationHandle   // void** out
);
ccall((:PowerRegisterSuspendResumeNotification, "POWRPROF.dll"), stdcall, UInt32,
      (UInt32, Ptr{Cvoid}, Ptr{Cvoid}),
      Flags, Recipient, RegistrationHandle)
# Flags : REGISTER_NOTIFICATION_FLAGS -> UInt32
# Recipient : HANDLE -> Ptr{Cvoid}
# RegistrationHandle : void** out -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
uint32_t PowerRegisterSuspendResumeNotification(
    uint32_t Flags,
    void* Recipient,
    void** RegistrationHandle);
]]
local powrprof = ffi.load("powrprof")
-- powrprof.PowerRegisterSuspendResumeNotification(Flags, Recipient, RegistrationHandle)
-- Flags : REGISTER_NOTIFICATION_FLAGS
-- Recipient : HANDLE
-- RegistrationHandle : void** out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('POWRPROF.dll');
const PowerRegisterSuspendResumeNotification = lib.func('__stdcall', 'PowerRegisterSuspendResumeNotification', 'uint32_t', ['uint32_t', 'void *', 'void *']);
// PowerRegisterSuspendResumeNotification(Flags, Recipient, RegistrationHandle)
// Flags : REGISTER_NOTIFICATION_FLAGS -> 'uint32_t'
// Recipient : HANDLE -> 'void *'
// RegistrationHandle : void** out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("POWRPROF.dll", {
  PowerRegisterSuspendResumeNotification: { parameters: ["u32", "pointer", "pointer"], result: "u32" },
});
// lib.symbols.PowerRegisterSuspendResumeNotification(Flags, Recipient, RegistrationHandle)
// Flags : REGISTER_NOTIFICATION_FLAGS -> "u32"
// Recipient : HANDLE -> "pointer"
// RegistrationHandle : void** out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
uint32_t PowerRegisterSuspendResumeNotification(
    uint32_t Flags,
    void* Recipient,
    void** RegistrationHandle);
C, "POWRPROF.dll");
// $ffi->PowerRegisterSuspendResumeNotification(Flags, Recipient, RegistrationHandle);
// Flags : REGISTER_NOTIFICATION_FLAGS
// Recipient : HANDLE
// RegistrationHandle : void** 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 Powrprof extends StdCallLibrary {
    Powrprof INSTANCE = Native.load("powrprof", Powrprof.class);
    int PowerRegisterSuspendResumeNotification(
        int Flags,   // REGISTER_NOTIFICATION_FLAGS
        Pointer Recipient,   // HANDLE
        Pointer RegistrationHandle   // void** out
    );
}
@[Link("powrprof")]
lib LibPOWRPROF
  fun PowerRegisterSuspendResumeNotification = PowerRegisterSuspendResumeNotification(
    Flags : UInt32,   # REGISTER_NOTIFICATION_FLAGS
    Recipient : Void*,   # HANDLE
    RegistrationHandle : Void**   # void** out
  ) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef PowerRegisterSuspendResumeNotificationNative = Uint32 Function(Uint32, Pointer<Void>, Pointer<Void>);
typedef PowerRegisterSuspendResumeNotificationDart = int Function(int, Pointer<Void>, Pointer<Void>);
final PowerRegisterSuspendResumeNotification = DynamicLibrary.open('POWRPROF.dll')
    .lookupFunction<PowerRegisterSuspendResumeNotificationNative, PowerRegisterSuspendResumeNotificationDart>('PowerRegisterSuspendResumeNotification');
// Flags : REGISTER_NOTIFICATION_FLAGS -> Uint32
// Recipient : HANDLE -> Pointer<Void>
// RegistrationHandle : void** out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function PowerRegisterSuspendResumeNotification(
  Flags: DWORD;   // REGISTER_NOTIFICATION_FLAGS
  Recipient: THandle;   // HANDLE
  RegistrationHandle: Pointer   // void** out
): DWORD; stdcall;
  external 'POWRPROF.dll' name 'PowerRegisterSuspendResumeNotification';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "PowerRegisterSuspendResumeNotification"
  c_PowerRegisterSuspendResumeNotification :: Word32 -> Ptr () -> Ptr () -> IO Word32
-- Flags : REGISTER_NOTIFICATION_FLAGS -> Word32
-- Recipient : HANDLE -> Ptr ()
-- RegistrationHandle : void** out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let powerregistersuspendresumenotification =
  foreign "PowerRegisterSuspendResumeNotification"
    (uint32_t @-> (ptr void) @-> (ptr void) @-> returning uint32_t)
(* Flags : REGISTER_NOTIFICATION_FLAGS -> uint32_t *)
(* Recipient : HANDLE -> (ptr void) *)
(* RegistrationHandle : void** out -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library powrprof (t "POWRPROF.dll"))
(cffi:use-foreign-library powrprof)

(cffi:defcfun ("PowerRegisterSuspendResumeNotification" power-register-suspend-resume-notification :convention :stdcall) :uint32
  (flags :uint32)   ; REGISTER_NOTIFICATION_FLAGS
  (recipient :pointer)   ; HANDLE
  (registration-handle :pointer))   ; void** out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $PowerRegisterSuspendResumeNotification = Win32::API::More->new('POWRPROF',
    'DWORD PowerRegisterSuspendResumeNotification(DWORD Flags, HANDLE Recipient, LPVOID RegistrationHandle)');
# my $ret = $PowerRegisterSuspendResumeNotification->Call($Flags, $Recipient, $RegistrationHandle);
# Flags : REGISTER_NOTIFICATION_FLAGS -> DWORD
# Recipient : HANDLE -> HANDLE
# RegistrationHandle : void** out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

公式の関連項目
使用する型