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

PowerRegisterForEffectivePowerModeNotifications

関数
実効電源モード変更の通知コールバックを登録する。
DLLPOWRPROF.dll呼出規約winapi対応OSWindows 10 以降

シグネチャ

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

HRESULT PowerRegisterForEffectivePowerModeNotifications(
    DWORD Version,
    EFFECTIVE_POWER_MODE_CALLBACK Callback,
    void* Context,   // optional
    void** RegistrationHandle
);

パラメーター

名前方向
VersionDWORDin
CallbackEFFECTIVE_POWER_MODE_CALLBACKin
Contextvoid*inoptional
RegistrationHandlevoid**out

戻り値の型: HRESULT

各言語での呼び出し定義

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

HRESULT PowerRegisterForEffectivePowerModeNotifications(
    DWORD Version,
    EFFECTIVE_POWER_MODE_CALLBACK Callback,
    void* Context,   // optional
    void** RegistrationHandle
);
[DllImport("POWRPROF.dll", ExactSpelling = true)]
static extern int PowerRegisterForEffectivePowerModeNotifications(
    uint Version,   // DWORD
    IntPtr Callback,   // EFFECTIVE_POWER_MODE_CALLBACK
    IntPtr Context,   // void* optional
    IntPtr RegistrationHandle   // void** out
);
<DllImport("POWRPROF.dll", ExactSpelling:=True)>
Public Shared Function PowerRegisterForEffectivePowerModeNotifications(
    Version As UInteger,   ' DWORD
    Callback As IntPtr,   ' EFFECTIVE_POWER_MODE_CALLBACK
    Context As IntPtr,   ' void* optional
    RegistrationHandle As IntPtr   ' void** out
) As Integer
End Function
' Version : DWORD
' Callback : EFFECTIVE_POWER_MODE_CALLBACK
' Context : void* optional
' RegistrationHandle : void** out
Declare PtrSafe Function PowerRegisterForEffectivePowerModeNotifications Lib "powrprof" ( _
    ByVal Version As Long, _
    ByVal Callback As LongPtr, _
    ByVal Context 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

PowerRegisterForEffectivePowerModeNotifications = ctypes.windll.powrprof.PowerRegisterForEffectivePowerModeNotifications
PowerRegisterForEffectivePowerModeNotifications.restype = ctypes.c_int
PowerRegisterForEffectivePowerModeNotifications.argtypes = [
    wintypes.DWORD,  # Version : DWORD
    ctypes.c_void_p,  # Callback : EFFECTIVE_POWER_MODE_CALLBACK
    ctypes.POINTER(None),  # Context : void* optional
    ctypes.c_void_p,  # RegistrationHandle : void** out
]
require 'fiddle'
require 'fiddle/import'

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

var (
	powrprof = windows.NewLazySystemDLL("POWRPROF.dll")
	procPowerRegisterForEffectivePowerModeNotifications = powrprof.NewProc("PowerRegisterForEffectivePowerModeNotifications")
)

// Version (DWORD), Callback (EFFECTIVE_POWER_MODE_CALLBACK), Context (void* optional), RegistrationHandle (void** out)
r1, _, err := procPowerRegisterForEffectivePowerModeNotifications.Call(
	uintptr(Version),
	uintptr(Callback),
	uintptr(Context),
	uintptr(RegistrationHandle),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function PowerRegisterForEffectivePowerModeNotifications(
  Version: DWORD;   // DWORD
  Callback: Pointer;   // EFFECTIVE_POWER_MODE_CALLBACK
  Context: Pointer;   // void* optional
  RegistrationHandle: Pointer   // void** out
): Integer; stdcall;
  external 'POWRPROF.dll' name 'PowerRegisterForEffectivePowerModeNotifications';
result := DllCall("POWRPROF\PowerRegisterForEffectivePowerModeNotifications"
    , "UInt", Version   ; DWORD
    , "Ptr", Callback   ; EFFECTIVE_POWER_MODE_CALLBACK
    , "Ptr", Context   ; void* optional
    , "Ptr", RegistrationHandle   ; void** out
    , "Int")   ; return: HRESULT
●PowerRegisterForEffectivePowerModeNotifications(Version, Callback, Context, RegistrationHandle) = DLL("POWRPROF.dll", "int PowerRegisterForEffectivePowerModeNotifications(dword, void*, void*, void*)")
# 呼び出し: PowerRegisterForEffectivePowerModeNotifications(Version, Callback, Context, RegistrationHandle)
# Version : DWORD -> "dword"
# Callback : EFFECTIVE_POWER_MODE_CALLBACK -> "void*"
# Context : void* optional -> "void*"
# RegistrationHandle : void** out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。