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

RegisterSuspendResumeNotification

関数
サスペンド・再開の電源通知を受け取るよう登録する。
DLLUSER32.dll呼出規約winapiSetLastErrorあり対応OSwindows8.0

シグネチャ

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

HPOWERNOTIFY RegisterSuspendResumeNotification(
    HANDLE hRecipient,
    REGISTER_NOTIFICATION_FLAGS Flags
);

パラメーター

名前方向
hRecipientHANDLEin
FlagsREGISTER_NOTIFICATION_FLAGSin

戻り値の型: HPOWERNOTIFY

各言語での呼び出し定義

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

HPOWERNOTIFY RegisterSuspendResumeNotification(
    HANDLE hRecipient,
    REGISTER_NOTIFICATION_FLAGS Flags
);
[DllImport("USER32.dll", SetLastError = true, ExactSpelling = true)]
static extern IntPtr RegisterSuspendResumeNotification(
    IntPtr hRecipient,   // HANDLE
    uint Flags   // REGISTER_NOTIFICATION_FLAGS
);
<DllImport("USER32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function RegisterSuspendResumeNotification(
    hRecipient As IntPtr,   ' HANDLE
    Flags As UInteger   ' REGISTER_NOTIFICATION_FLAGS
) As IntPtr
End Function
' hRecipient : HANDLE
' Flags : REGISTER_NOTIFICATION_FLAGS
Declare PtrSafe Function RegisterSuspendResumeNotification Lib "user32" ( _
    ByVal hRecipient As LongPtr, _
    ByVal Flags As Long) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

RegisterSuspendResumeNotification = ctypes.windll.user32.RegisterSuspendResumeNotification
RegisterSuspendResumeNotification.restype = ctypes.c_ssize_t
RegisterSuspendResumeNotification.argtypes = [
    wintypes.HANDLE,  # hRecipient : HANDLE
    wintypes.DWORD,  # Flags : REGISTER_NOTIFICATION_FLAGS
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

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

var (
	user32 = windows.NewLazySystemDLL("USER32.dll")
	procRegisterSuspendResumeNotification = user32.NewProc("RegisterSuspendResumeNotification")
)

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