ホーム › System.Power › PowerRegisterForEffectivePowerModeNotifications
PowerRegisterForEffectivePowerModeNotifications
関数実効電源モード変更の通知コールバックを登録する。
シグネチャ
// POWRPROF.dll
#include <windows.h>
HRESULT PowerRegisterForEffectivePowerModeNotifications(
DWORD Version,
EFFECTIVE_POWER_MODE_CALLBACK Callback,
void* Context, // optional
void** RegistrationHandle
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| Version | DWORD | in | 呼び出し元が解釈できる実効電源モードの最大バージョンを指定します。実効電源モードがより新しいバージョンに由来する場合は、互換性のあるバージョンに引き下げられ、その値がコールバックに渡されます。 次の値を指定できます。
|
| Callback | EFFECTIVE_POWER_MODE_CALLBACK | in | 実効電源モードが変更されたときに呼び出すコールバックへのポインターです。これは登録時にも一度呼び出され、現在のモードが渡されます。この API を使用して複数のコールバックを登録した場合、それらのコールバックは同時に呼び出されることがあります。 |
| Context | void* | inoptional | 呼び出し元が指定する不透明なコンテキストです。 |
| RegistrationHandle | void** | out | 登録へのハンドルです。通知の登録を解除するにはこのハンドルを使用します。 |
戻り値の型: HRESULT
公式ドキュメント
実効電源モードの変更通知を受け取るためのコールバックを登録します。
戻り値
呼び出しが成功した場合は S_OK (ゼロ) を返し、失敗した場合は非ゼロの値を返します。
解説(Remarks)
登録の直後に、コールバックは電源設定の現在の値とともに呼び出されます。電源モードの変更中に登録が行われた場合は、複数のコールバックを受け取ることがあります。最後のコールバックが最新の更新です。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// 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 // HRESULTfunction 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)。const std = @import("std");
extern "powrprof" fn PowerRegisterForEffectivePowerModeNotifications(
Version: u32, // DWORD
Callback: ?*anyopaque, // EFFECTIVE_POWER_MODE_CALLBACK
Context: ?*anyopaque, // void* optional
RegistrationHandle: ?*anyopaque // void** out
) callconv(std.os.windows.WINAPI) i32;proc PowerRegisterForEffectivePowerModeNotifications(
Version: uint32, # DWORD
Callback: pointer, # EFFECTIVE_POWER_MODE_CALLBACK
Context: pointer, # void* optional
RegistrationHandle: pointer # void** out
): int32 {.importc: "PowerRegisterForEffectivePowerModeNotifications", stdcall, dynlib: "POWRPROF.dll".}pragma(lib, "powrprof");
extern(Windows)
int PowerRegisterForEffectivePowerModeNotifications(
uint Version, // DWORD
void* Callback, // EFFECTIVE_POWER_MODE_CALLBACK
void* Context, // void* optional
void** RegistrationHandle // void** out
);ccall((:PowerRegisterForEffectivePowerModeNotifications, "POWRPROF.dll"), stdcall, Int32,
(UInt32, Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}),
Version, Callback, Context, RegistrationHandle)
# Version : DWORD -> UInt32
# Callback : EFFECTIVE_POWER_MODE_CALLBACK -> Ptr{Cvoid}
# Context : void* optional -> Ptr{Cvoid}
# RegistrationHandle : void** out -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t PowerRegisterForEffectivePowerModeNotifications(
uint32_t Version,
void* Callback,
void* Context,
void** RegistrationHandle);
]]
local powrprof = ffi.load("powrprof")
-- powrprof.PowerRegisterForEffectivePowerModeNotifications(Version, Callback, Context, RegistrationHandle)
-- Version : DWORD
-- Callback : EFFECTIVE_POWER_MODE_CALLBACK
-- Context : void* optional
-- RegistrationHandle : void** out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('POWRPROF.dll');
const PowerRegisterForEffectivePowerModeNotifications = lib.func('__stdcall', 'PowerRegisterForEffectivePowerModeNotifications', 'int32_t', ['uint32_t', 'void *', 'void *', 'void *']);
// PowerRegisterForEffectivePowerModeNotifications(Version, Callback, Context, RegistrationHandle)
// Version : DWORD -> 'uint32_t'
// Callback : EFFECTIVE_POWER_MODE_CALLBACK -> 'void *'
// Context : void* optional -> 'void *'
// RegistrationHandle : void** out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
// コールバック(関数ポインタ)は koffi.proto/koffi.register で型を定義して渡す(素の void* では JS 関数を渡せない)。const lib = Deno.dlopen("POWRPROF.dll", {
PowerRegisterForEffectivePowerModeNotifications: { parameters: ["u32", "pointer", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.PowerRegisterForEffectivePowerModeNotifications(Version, Callback, Context, RegistrationHandle)
// Version : DWORD -> "u32"
// Callback : EFFECTIVE_POWER_MODE_CALLBACK -> "pointer"
// Context : void* optional -> "pointer"
// RegistrationHandle : void** out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t PowerRegisterForEffectivePowerModeNotifications(
uint32_t Version,
void* Callback,
void* Context,
void** RegistrationHandle);
C, "POWRPROF.dll");
// $ffi->PowerRegisterForEffectivePowerModeNotifications(Version, Callback, Context, RegistrationHandle);
// Version : DWORD
// Callback : EFFECTIVE_POWER_MODE_CALLBACK
// Context : void* optional
// 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 PowerRegisterForEffectivePowerModeNotifications(
int Version, // DWORD
Callback Callback, // EFFECTIVE_POWER_MODE_CALLBACK
Pointer Context, // void* optional
Pointer RegistrationHandle // void** out
);
}@[Link("powrprof")]
lib LibPOWRPROF
fun PowerRegisterForEffectivePowerModeNotifications = PowerRegisterForEffectivePowerModeNotifications(
Version : UInt32, # DWORD
Callback : Void*, # EFFECTIVE_POWER_MODE_CALLBACK
Context : Void*, # void* optional
RegistrationHandle : Void** # void** out
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef PowerRegisterForEffectivePowerModeNotificationsNative = Int32 Function(Uint32, Pointer<Void>, Pointer<Void>, Pointer<Void>);
typedef PowerRegisterForEffectivePowerModeNotificationsDart = int Function(int, Pointer<Void>, Pointer<Void>, Pointer<Void>);
final PowerRegisterForEffectivePowerModeNotifications = DynamicLibrary.open('POWRPROF.dll')
.lookupFunction<PowerRegisterForEffectivePowerModeNotificationsNative, PowerRegisterForEffectivePowerModeNotificationsDart>('PowerRegisterForEffectivePowerModeNotifications');
// Version : DWORD -> Uint32
// Callback : EFFECTIVE_POWER_MODE_CALLBACK -> Pointer<Void>
// Context : void* optional -> Pointer<Void>
// RegistrationHandle : void** out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
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';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "PowerRegisterForEffectivePowerModeNotifications"
c_PowerRegisterForEffectivePowerModeNotifications :: Word32 -> Ptr () -> Ptr () -> Ptr () -> IO Int32
-- Version : DWORD -> Word32
-- Callback : EFFECTIVE_POWER_MODE_CALLBACK -> Ptr ()
-- Context : void* optional -> Ptr ()
-- RegistrationHandle : void** out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let powerregisterforeffectivepowermodenotifications =
foreign "PowerRegisterForEffectivePowerModeNotifications"
(uint32_t @-> (ptr void) @-> (ptr void) @-> (ptr void) @-> returning int32_t)
(* Version : DWORD -> uint32_t *)
(* Callback : EFFECTIVE_POWER_MODE_CALLBACK -> (ptr void) *)
(* Context : void* optional -> (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 ("PowerRegisterForEffectivePowerModeNotifications" power-register-for-effective-power-mode-notifications :convention :stdcall) :int32
(version :uint32) ; DWORD
(callback :pointer) ; EFFECTIVE_POWER_MODE_CALLBACK
(context :pointer) ; void* optional
(registration-handle :pointer)) ; void** out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $PowerRegisterForEffectivePowerModeNotifications = Win32::API::More->new('POWRPROF',
'int PowerRegisterForEffectivePowerModeNotifications(DWORD Version, LPVOID Callback, LPVOID Context, LPVOID RegistrationHandle)');
# my $ret = $PowerRegisterForEffectivePowerModeNotifications->Call($Version, $Callback, $Context, $RegistrationHandle);
# Version : DWORD -> DWORD
# Callback : EFFECTIVE_POWER_MODE_CALLBACK -> LPVOID
# Context : void* optional -> LPVOID
# RegistrationHandle : void** out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# コールバック(関数ポインタ)は Perl sub を直接渡せません。Win32::API::Callback を使用してください。