ホーム › System.Power › PowerEnumerate
PowerEnumerate
関数電源スキームやサブグループ、設定の要素を列挙する。
シグネチャ
// POWRPROF.dll
#include <windows.h>
WIN32_ERROR PowerEnumerate(
HKEY RootPowerKey, // optional
const GUID* SchemeGuid, // optional
const GUID* SubGroupOfPowerSettingsGuid, // optional
POWER_DATA_ACCESSOR AccessFlags,
DWORD Index,
BYTE* Buffer, // optional
DWORD* BufferSize
);パラメーター
| 名前 | 型 | 方向 | 説明 | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| RootPowerKey | HKEY | inoptional | このパラメーターは将来の使用のために予約されており、NULL を設定する必要があります。 | ||||||||||||||||||
| SchemeGuid | GUID* | inoptional | 電源スキームの識別子。このパラメーターが NULL の場合、 電源ポリシーの列挙が返されます。 | ||||||||||||||||||
| SubGroupOfPowerSettingsGuid | GUID* | inoptional | 電源設定のサブグループ。このパラメーターが NULL の場合、PolicyGuid キー配下の設定の 列挙が返されます。
| ||||||||||||||||||
| AccessFlags | POWER_DATA_ACCESSOR | in | 列挙対象を指定するフラグのセット。
| ||||||||||||||||||
| Index | DWORD | in | 列挙対象のスキーム、サブグループ、または設定のゼロから始まるインデックス。 | ||||||||||||||||||
| Buffer | BYTE* | outoptional | 要素を受け取る変数へのポインター。このパラメーターが NULL の場合、関数は必要なバッファーのサイズを取得します。 | ||||||||||||||||||
| BufferSize | DWORD* | inout | 入力時に Buffer パラメーターが指すバッファーのサイズを格納する変数への ポインター。Buffer パラメーターが NULL の場合、または BufferSize が十分な大きさでない場合、関数は ERROR_MORE_DATA を返し、変数には必要なバッファーサイズが格納されます。 |
戻り値の型: WIN32_ERROR
公式ドキュメント
電源スキーム内の指定された要素を列挙します。
戻り値
呼び出しが成功した場合は ERROR_SUCCESS(ゼロ)を返し、 呼び出しが失敗した場合は 0 以外の値を返します。BufferSize パラメーターで渡されたバッファーサイズが小さすぎる場合、 または Buffer パラメーターが NULL の場合、 ERROR_MORE_DATA が返され、BufferSize パラメーターが指す DWORD に必要なバッファーサイズが格納されます。
出典・ライセンス: 上記「公式ドキュメント」の内容は 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>
WIN32_ERROR PowerEnumerate(
HKEY RootPowerKey, // optional
const GUID* SchemeGuid, // optional
const GUID* SubGroupOfPowerSettingsGuid, // optional
POWER_DATA_ACCESSOR AccessFlags,
DWORD Index,
BYTE* Buffer, // optional
DWORD* BufferSize
);[DllImport("POWRPROF.dll", ExactSpelling = true)]
static extern uint PowerEnumerate(
IntPtr RootPowerKey, // HKEY optional
IntPtr SchemeGuid, // GUID* optional
IntPtr SubGroupOfPowerSettingsGuid, // GUID* optional
int AccessFlags, // POWER_DATA_ACCESSOR
uint Index, // DWORD
IntPtr Buffer, // BYTE* optional, out
ref uint BufferSize // DWORD* in/out
);<DllImport("POWRPROF.dll", ExactSpelling:=True)>
Public Shared Function PowerEnumerate(
RootPowerKey As IntPtr, ' HKEY optional
SchemeGuid As IntPtr, ' GUID* optional
SubGroupOfPowerSettingsGuid As IntPtr, ' GUID* optional
AccessFlags As Integer, ' POWER_DATA_ACCESSOR
Index As UInteger, ' DWORD
Buffer As IntPtr, ' BYTE* optional, out
ByRef BufferSize As UInteger ' DWORD* in/out
) As UInteger
End Function' RootPowerKey : HKEY optional
' SchemeGuid : GUID* optional
' SubGroupOfPowerSettingsGuid : GUID* optional
' AccessFlags : POWER_DATA_ACCESSOR
' Index : DWORD
' Buffer : BYTE* optional, out
' BufferSize : DWORD* in/out
Declare PtrSafe Function PowerEnumerate Lib "powrprof" ( _
ByVal RootPowerKey As LongPtr, _
ByVal SchemeGuid As LongPtr, _
ByVal SubGroupOfPowerSettingsGuid As LongPtr, _
ByVal AccessFlags As Long, _
ByVal Index As Long, _
ByVal Buffer As LongPtr, _
ByRef BufferSize As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
PowerEnumerate = ctypes.windll.powrprof.PowerEnumerate
PowerEnumerate.restype = wintypes.DWORD
PowerEnumerate.argtypes = [
wintypes.HANDLE, # RootPowerKey : HKEY optional
ctypes.c_void_p, # SchemeGuid : GUID* optional
ctypes.c_void_p, # SubGroupOfPowerSettingsGuid : GUID* optional
ctypes.c_int, # AccessFlags : POWER_DATA_ACCESSOR
wintypes.DWORD, # Index : DWORD
ctypes.POINTER(ctypes.c_ubyte), # Buffer : BYTE* optional, out
ctypes.POINTER(wintypes.DWORD), # BufferSize : DWORD* in/out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('POWRPROF.dll')
PowerEnumerate = Fiddle::Function.new(
lib['PowerEnumerate'],
[
Fiddle::TYPE_VOIDP, # RootPowerKey : HKEY optional
Fiddle::TYPE_VOIDP, # SchemeGuid : GUID* optional
Fiddle::TYPE_VOIDP, # SubGroupOfPowerSettingsGuid : GUID* optional
Fiddle::TYPE_INT, # AccessFlags : POWER_DATA_ACCESSOR
-Fiddle::TYPE_INT, # Index : DWORD
Fiddle::TYPE_VOIDP, # Buffer : BYTE* optional, out
Fiddle::TYPE_VOIDP, # BufferSize : DWORD* in/out
],
-Fiddle::TYPE_INT)#[link(name = "powrprof")]
extern "system" {
fn PowerEnumerate(
RootPowerKey: *mut core::ffi::c_void, // HKEY optional
SchemeGuid: *const GUID, // GUID* optional
SubGroupOfPowerSettingsGuid: *const GUID, // GUID* optional
AccessFlags: i32, // POWER_DATA_ACCESSOR
Index: u32, // DWORD
Buffer: *mut u8, // BYTE* optional, out
BufferSize: *mut u32 // DWORD* in/out
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("POWRPROF.dll")]
public static extern uint PowerEnumerate(IntPtr RootPowerKey, IntPtr SchemeGuid, IntPtr SubGroupOfPowerSettingsGuid, int AccessFlags, uint Index, IntPtr Buffer, ref uint BufferSize);
"@
$api = Add-Type -MemberDefinition $sig -Name 'POWRPROF_PowerEnumerate' -Namespace Win32 -PassThru
# $api::PowerEnumerate(RootPowerKey, SchemeGuid, SubGroupOfPowerSettingsGuid, AccessFlags, Index, Buffer, BufferSize)#uselib "POWRPROF.dll"
#func global PowerEnumerate "PowerEnumerate" sptr, sptr, sptr, sptr, sptr, sptr, sptr
; PowerEnumerate RootPowerKey, varptr(SchemeGuid), varptr(SubGroupOfPowerSettingsGuid), AccessFlags, Index, varptr(Buffer), varptr(BufferSize) ; 戻り値は stat
; RootPowerKey : HKEY optional -> "sptr"
; SchemeGuid : GUID* optional -> "sptr"
; SubGroupOfPowerSettingsGuid : GUID* optional -> "sptr"
; AccessFlags : POWER_DATA_ACCESSOR -> "sptr"
; Index : DWORD -> "sptr"
; Buffer : BYTE* optional, out -> "sptr"
; BufferSize : DWORD* in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "POWRPROF.dll" #cfunc global PowerEnumerate "PowerEnumerate" sptr, var, var, int, int, var, var ; res = PowerEnumerate(RootPowerKey, SchemeGuid, SubGroupOfPowerSettingsGuid, AccessFlags, Index, Buffer, BufferSize) ; RootPowerKey : HKEY optional -> "sptr" ; SchemeGuid : GUID* optional -> "var" ; SubGroupOfPowerSettingsGuid : GUID* optional -> "var" ; AccessFlags : POWER_DATA_ACCESSOR -> "int" ; Index : DWORD -> "int" ; Buffer : BYTE* optional, out -> "var" ; BufferSize : DWORD* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "POWRPROF.dll" #cfunc global PowerEnumerate "PowerEnumerate" sptr, sptr, sptr, int, int, sptr, sptr ; res = PowerEnumerate(RootPowerKey, varptr(SchemeGuid), varptr(SubGroupOfPowerSettingsGuid), AccessFlags, Index, varptr(Buffer), varptr(BufferSize)) ; RootPowerKey : HKEY optional -> "sptr" ; SchemeGuid : GUID* optional -> "sptr" ; SubGroupOfPowerSettingsGuid : GUID* optional -> "sptr" ; AccessFlags : POWER_DATA_ACCESSOR -> "int" ; Index : DWORD -> "int" ; Buffer : BYTE* optional, out -> "sptr" ; BufferSize : DWORD* in/out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; WIN32_ERROR PowerEnumerate(HKEY RootPowerKey, GUID* SchemeGuid, GUID* SubGroupOfPowerSettingsGuid, POWER_DATA_ACCESSOR AccessFlags, DWORD Index, BYTE* Buffer, DWORD* BufferSize) #uselib "POWRPROF.dll" #cfunc global PowerEnumerate "PowerEnumerate" intptr, var, var, int, int, var, var ; res = PowerEnumerate(RootPowerKey, SchemeGuid, SubGroupOfPowerSettingsGuid, AccessFlags, Index, Buffer, BufferSize) ; RootPowerKey : HKEY optional -> "intptr" ; SchemeGuid : GUID* optional -> "var" ; SubGroupOfPowerSettingsGuid : GUID* optional -> "var" ; AccessFlags : POWER_DATA_ACCESSOR -> "int" ; Index : DWORD -> "int" ; Buffer : BYTE* optional, out -> "var" ; BufferSize : DWORD* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; WIN32_ERROR PowerEnumerate(HKEY RootPowerKey, GUID* SchemeGuid, GUID* SubGroupOfPowerSettingsGuid, POWER_DATA_ACCESSOR AccessFlags, DWORD Index, BYTE* Buffer, DWORD* BufferSize) #uselib "POWRPROF.dll" #cfunc global PowerEnumerate "PowerEnumerate" intptr, intptr, intptr, int, int, intptr, intptr ; res = PowerEnumerate(RootPowerKey, varptr(SchemeGuid), varptr(SubGroupOfPowerSettingsGuid), AccessFlags, Index, varptr(Buffer), varptr(BufferSize)) ; RootPowerKey : HKEY optional -> "intptr" ; SchemeGuid : GUID* optional -> "intptr" ; SubGroupOfPowerSettingsGuid : GUID* optional -> "intptr" ; AccessFlags : POWER_DATA_ACCESSOR -> "int" ; Index : DWORD -> "int" ; Buffer : BYTE* optional, out -> "intptr" ; BufferSize : DWORD* in/out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
powrprof = windows.NewLazySystemDLL("POWRPROF.dll")
procPowerEnumerate = powrprof.NewProc("PowerEnumerate")
)
// RootPowerKey (HKEY optional), SchemeGuid (GUID* optional), SubGroupOfPowerSettingsGuid (GUID* optional), AccessFlags (POWER_DATA_ACCESSOR), Index (DWORD), Buffer (BYTE* optional, out), BufferSize (DWORD* in/out)
r1, _, err := procPowerEnumerate.Call(
uintptr(RootPowerKey),
uintptr(SchemeGuid),
uintptr(SubGroupOfPowerSettingsGuid),
uintptr(AccessFlags),
uintptr(Index),
uintptr(Buffer),
uintptr(BufferSize),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // WIN32_ERRORfunction PowerEnumerate(
RootPowerKey: THandle; // HKEY optional
SchemeGuid: PGUID; // GUID* optional
SubGroupOfPowerSettingsGuid: PGUID; // GUID* optional
AccessFlags: Integer; // POWER_DATA_ACCESSOR
Index: DWORD; // DWORD
Buffer: Pointer; // BYTE* optional, out
BufferSize: Pointer // DWORD* in/out
): DWORD; stdcall;
external 'POWRPROF.dll' name 'PowerEnumerate';result := DllCall("POWRPROF\PowerEnumerate"
, "Ptr", RootPowerKey ; HKEY optional
, "Ptr", SchemeGuid ; GUID* optional
, "Ptr", SubGroupOfPowerSettingsGuid ; GUID* optional
, "Int", AccessFlags ; POWER_DATA_ACCESSOR
, "UInt", Index ; DWORD
, "Ptr", Buffer ; BYTE* optional, out
, "Ptr", BufferSize ; DWORD* in/out
, "UInt") ; return: WIN32_ERROR●PowerEnumerate(RootPowerKey, SchemeGuid, SubGroupOfPowerSettingsGuid, AccessFlags, Index, Buffer, BufferSize) = DLL("POWRPROF.dll", "dword PowerEnumerate(void*, void*, void*, int, dword, void*, void*)")
# 呼び出し: PowerEnumerate(RootPowerKey, SchemeGuid, SubGroupOfPowerSettingsGuid, AccessFlags, Index, Buffer, BufferSize)
# RootPowerKey : HKEY optional -> "void*"
# SchemeGuid : GUID* optional -> "void*"
# SubGroupOfPowerSettingsGuid : GUID* optional -> "void*"
# AccessFlags : POWER_DATA_ACCESSOR -> "int"
# Index : DWORD -> "dword"
# Buffer : BYTE* optional, out -> "void*"
# BufferSize : DWORD* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "powrprof" fn PowerEnumerate(
RootPowerKey: ?*anyopaque, // HKEY optional
SchemeGuid: [*c]GUID, // GUID* optional
SubGroupOfPowerSettingsGuid: [*c]GUID, // GUID* optional
AccessFlags: i32, // POWER_DATA_ACCESSOR
Index: u32, // DWORD
Buffer: [*c]u8, // BYTE* optional, out
BufferSize: [*c]u32 // DWORD* in/out
) callconv(std.os.windows.WINAPI) u32;proc PowerEnumerate(
RootPowerKey: pointer, # HKEY optional
SchemeGuid: ptr GUID, # GUID* optional
SubGroupOfPowerSettingsGuid: ptr GUID, # GUID* optional
AccessFlags: int32, # POWER_DATA_ACCESSOR
Index: uint32, # DWORD
Buffer: ptr uint8, # BYTE* optional, out
BufferSize: ptr uint32 # DWORD* in/out
): uint32 {.importc: "PowerEnumerate", stdcall, dynlib: "POWRPROF.dll".}pragma(lib, "powrprof");
extern(Windows)
uint PowerEnumerate(
void* RootPowerKey, // HKEY optional
GUID* SchemeGuid, // GUID* optional
GUID* SubGroupOfPowerSettingsGuid, // GUID* optional
int AccessFlags, // POWER_DATA_ACCESSOR
uint Index, // DWORD
ubyte* Buffer, // BYTE* optional, out
uint* BufferSize // DWORD* in/out
);ccall((:PowerEnumerate, "POWRPROF.dll"), stdcall, UInt32,
(Ptr{Cvoid}, Ptr{GUID}, Ptr{GUID}, Int32, UInt32, Ptr{UInt8}, Ptr{UInt32}),
RootPowerKey, SchemeGuid, SubGroupOfPowerSettingsGuid, AccessFlags, Index, Buffer, BufferSize)
# RootPowerKey : HKEY optional -> Ptr{Cvoid}
# SchemeGuid : GUID* optional -> Ptr{GUID}
# SubGroupOfPowerSettingsGuid : GUID* optional -> Ptr{GUID}
# AccessFlags : POWER_DATA_ACCESSOR -> Int32
# Index : DWORD -> UInt32
# Buffer : BYTE* optional, out -> Ptr{UInt8}
# BufferSize : DWORD* in/out -> Ptr{UInt32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
uint32_t PowerEnumerate(
void* RootPowerKey,
void* SchemeGuid,
void* SubGroupOfPowerSettingsGuid,
int32_t AccessFlags,
uint32_t Index,
uint8_t* Buffer,
uint32_t* BufferSize);
]]
local powrprof = ffi.load("powrprof")
-- powrprof.PowerEnumerate(RootPowerKey, SchemeGuid, SubGroupOfPowerSettingsGuid, AccessFlags, Index, Buffer, BufferSize)
-- RootPowerKey : HKEY optional
-- SchemeGuid : GUID* optional
-- SubGroupOfPowerSettingsGuid : GUID* optional
-- AccessFlags : POWER_DATA_ACCESSOR
-- Index : DWORD
-- Buffer : BYTE* optional, out
-- BufferSize : DWORD* in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('POWRPROF.dll');
const PowerEnumerate = lib.func('__stdcall', 'PowerEnumerate', 'uint32_t', ['void *', 'void *', 'void *', 'int32_t', 'uint32_t', 'uint8_t *', 'uint32_t *']);
// PowerEnumerate(RootPowerKey, SchemeGuid, SubGroupOfPowerSettingsGuid, AccessFlags, Index, Buffer, BufferSize)
// RootPowerKey : HKEY optional -> 'void *'
// SchemeGuid : GUID* optional -> 'void *'
// SubGroupOfPowerSettingsGuid : GUID* optional -> 'void *'
// AccessFlags : POWER_DATA_ACCESSOR -> 'int32_t'
// Index : DWORD -> 'uint32_t'
// Buffer : BYTE* optional, out -> 'uint8_t *'
// BufferSize : DWORD* in/out -> 'uint32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("POWRPROF.dll", {
PowerEnumerate: { parameters: ["pointer", "pointer", "pointer", "i32", "u32", "pointer", "pointer"], result: "u32" },
});
// lib.symbols.PowerEnumerate(RootPowerKey, SchemeGuid, SubGroupOfPowerSettingsGuid, AccessFlags, Index, Buffer, BufferSize)
// RootPowerKey : HKEY optional -> "pointer"
// SchemeGuid : GUID* optional -> "pointer"
// SubGroupOfPowerSettingsGuid : GUID* optional -> "pointer"
// AccessFlags : POWER_DATA_ACCESSOR -> "i32"
// Index : DWORD -> "u32"
// Buffer : BYTE* optional, out -> "pointer"
// BufferSize : DWORD* in/out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t PowerEnumerate(
void* RootPowerKey,
void* SchemeGuid,
void* SubGroupOfPowerSettingsGuid,
int32_t AccessFlags,
uint32_t Index,
uint8_t* Buffer,
uint32_t* BufferSize);
C, "POWRPROF.dll");
// $ffi->PowerEnumerate(RootPowerKey, SchemeGuid, SubGroupOfPowerSettingsGuid, AccessFlags, Index, Buffer, BufferSize);
// RootPowerKey : HKEY optional
// SchemeGuid : GUID* optional
// SubGroupOfPowerSettingsGuid : GUID* optional
// AccessFlags : POWER_DATA_ACCESSOR
// Index : DWORD
// Buffer : BYTE* optional, out
// BufferSize : DWORD* in/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 PowerEnumerate(
Pointer RootPowerKey, // HKEY optional
Pointer SchemeGuid, // GUID* optional
Pointer SubGroupOfPowerSettingsGuid, // GUID* optional
int AccessFlags, // POWER_DATA_ACCESSOR
int Index, // DWORD
byte[] Buffer, // BYTE* optional, out
IntByReference BufferSize // DWORD* in/out
);
}@[Link("powrprof")]
lib LibPOWRPROF
fun PowerEnumerate = PowerEnumerate(
RootPowerKey : Void*, # HKEY optional
SchemeGuid : GUID*, # GUID* optional
SubGroupOfPowerSettingsGuid : GUID*, # GUID* optional
AccessFlags : Int32, # POWER_DATA_ACCESSOR
Index : UInt32, # DWORD
Buffer : UInt8*, # BYTE* optional, out
BufferSize : UInt32* # DWORD* in/out
) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef PowerEnumerateNative = Uint32 Function(Pointer<Void>, Pointer<Void>, Pointer<Void>, Int32, Uint32, Pointer<Uint8>, Pointer<Uint32>);
typedef PowerEnumerateDart = int Function(Pointer<Void>, Pointer<Void>, Pointer<Void>, int, int, Pointer<Uint8>, Pointer<Uint32>);
final PowerEnumerate = DynamicLibrary.open('POWRPROF.dll')
.lookupFunction<PowerEnumerateNative, PowerEnumerateDart>('PowerEnumerate');
// RootPowerKey : HKEY optional -> Pointer<Void>
// SchemeGuid : GUID* optional -> Pointer<Void>
// SubGroupOfPowerSettingsGuid : GUID* optional -> Pointer<Void>
// AccessFlags : POWER_DATA_ACCESSOR -> Int32
// Index : DWORD -> Uint32
// Buffer : BYTE* optional, out -> Pointer<Uint8>
// BufferSize : DWORD* in/out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function PowerEnumerate(
RootPowerKey: THandle; // HKEY optional
SchemeGuid: PGUID; // GUID* optional
SubGroupOfPowerSettingsGuid: PGUID; // GUID* optional
AccessFlags: Integer; // POWER_DATA_ACCESSOR
Index: DWORD; // DWORD
Buffer: Pointer; // BYTE* optional, out
BufferSize: Pointer // DWORD* in/out
): DWORD; stdcall;
external 'POWRPROF.dll' name 'PowerEnumerate';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "PowerEnumerate"
c_PowerEnumerate :: Ptr () -> Ptr () -> Ptr () -> Int32 -> Word32 -> Ptr Word8 -> Ptr Word32 -> IO Word32
-- RootPowerKey : HKEY optional -> Ptr ()
-- SchemeGuid : GUID* optional -> Ptr ()
-- SubGroupOfPowerSettingsGuid : GUID* optional -> Ptr ()
-- AccessFlags : POWER_DATA_ACCESSOR -> Int32
-- Index : DWORD -> Word32
-- Buffer : BYTE* optional, out -> Ptr Word8
-- BufferSize : DWORD* in/out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let powerenumerate =
foreign "PowerEnumerate"
((ptr void) @-> (ptr void) @-> (ptr void) @-> int32_t @-> uint32_t @-> (ptr uint8_t) @-> (ptr uint32_t) @-> returning uint32_t)
(* RootPowerKey : HKEY optional -> (ptr void) *)
(* SchemeGuid : GUID* optional -> (ptr void) *)
(* SubGroupOfPowerSettingsGuid : GUID* optional -> (ptr void) *)
(* AccessFlags : POWER_DATA_ACCESSOR -> int32_t *)
(* Index : DWORD -> uint32_t *)
(* Buffer : BYTE* optional, out -> (ptr uint8_t) *)
(* BufferSize : DWORD* in/out -> (ptr uint32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library powrprof (t "POWRPROF.dll"))
(cffi:use-foreign-library powrprof)
(cffi:defcfun ("PowerEnumerate" power-enumerate :convention :stdcall) :uint32
(root-power-key :pointer) ; HKEY optional
(scheme-guid :pointer) ; GUID* optional
(sub-group-of-power-settings-guid :pointer) ; GUID* optional
(access-flags :int32) ; POWER_DATA_ACCESSOR
(index :uint32) ; DWORD
(buffer :pointer) ; BYTE* optional, out
(buffer-size :pointer)) ; DWORD* in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $PowerEnumerate = Win32::API::More->new('POWRPROF',
'DWORD PowerEnumerate(HANDLE RootPowerKey, LPVOID SchemeGuid, LPVOID SubGroupOfPowerSettingsGuid, int AccessFlags, DWORD Index, LPVOID Buffer, LPVOID BufferSize)');
# my $ret = $PowerEnumerate->Call($RootPowerKey, $SchemeGuid, $SubGroupOfPowerSettingsGuid, $AccessFlags, $Index, $Buffer, $BufferSize);
# RootPowerKey : HKEY optional -> HANDLE
# SchemeGuid : GUID* optional -> LPVOID
# SubGroupOfPowerSettingsGuid : GUID* optional -> LPVOID
# AccessFlags : POWER_DATA_ACCESSOR -> int
# Index : DWORD -> DWORD
# Buffer : BYTE* optional, out -> LPVOID
# BufferSize : DWORD* in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。