ホーム › System.Power › PowerOpenSystemPowerKey
PowerOpenSystemPowerKey
関数システムの電源設定レジストリキーを開く。
シグネチャ
// POWRPROF.dll
#include <windows.h>
DWORD PowerOpenSystemPowerKey(
HKEY* phSystemPowerKey,
DWORD Access,
BOOL OpenExisting
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| phSystemPowerKey | HKEY* | out | 開いたシステム電源キーのハンドルを受け取るHKEYへのポインタ。出力。使用後は閉じる。 |
| Access | DWORD | in | 要求するアクセス権(KEY_READ等のレジストリSAMフラグ)を示すDWORD。 |
| OpenExisting | BOOL | in | 既存キーのみを開く場合はTRUE、無ければ作成する場合はFALSE。 |
戻り値の型: DWORD
各言語での呼び出し定義
// POWRPROF.dll
#include <windows.h>
DWORD PowerOpenSystemPowerKey(
HKEY* phSystemPowerKey,
DWORD Access,
BOOL OpenExisting
);[DllImport("POWRPROF.dll", ExactSpelling = true)]
static extern uint PowerOpenSystemPowerKey(
IntPtr phSystemPowerKey, // HKEY* out
uint Access, // DWORD
bool OpenExisting // BOOL
);<DllImport("POWRPROF.dll", ExactSpelling:=True)>
Public Shared Function PowerOpenSystemPowerKey(
phSystemPowerKey As IntPtr, ' HKEY* out
Access As UInteger, ' DWORD
OpenExisting As Boolean ' BOOL
) As UInteger
End Function' phSystemPowerKey : HKEY* out
' Access : DWORD
' OpenExisting : BOOL
Declare PtrSafe Function PowerOpenSystemPowerKey Lib "powrprof" ( _
ByVal phSystemPowerKey As LongPtr, _
ByVal Access As Long, _
ByVal OpenExisting As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
PowerOpenSystemPowerKey = ctypes.windll.powrprof.PowerOpenSystemPowerKey
PowerOpenSystemPowerKey.restype = wintypes.DWORD
PowerOpenSystemPowerKey.argtypes = [
ctypes.c_void_p, # phSystemPowerKey : HKEY* out
wintypes.DWORD, # Access : DWORD
wintypes.BOOL, # OpenExisting : BOOL
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('POWRPROF.dll')
PowerOpenSystemPowerKey = Fiddle::Function.new(
lib['PowerOpenSystemPowerKey'],
[
Fiddle::TYPE_VOIDP, # phSystemPowerKey : HKEY* out
-Fiddle::TYPE_INT, # Access : DWORD
Fiddle::TYPE_INT, # OpenExisting : BOOL
],
-Fiddle::TYPE_INT)#[link(name = "powrprof")]
extern "system" {
fn PowerOpenSystemPowerKey(
phSystemPowerKey: *mut *mut core::ffi::c_void, // HKEY* out
Access: u32, // DWORD
OpenExisting: i32 // BOOL
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("POWRPROF.dll")]
public static extern uint PowerOpenSystemPowerKey(IntPtr phSystemPowerKey, uint Access, bool OpenExisting);
"@
$api = Add-Type -MemberDefinition $sig -Name 'POWRPROF_PowerOpenSystemPowerKey' -Namespace Win32 -PassThru
# $api::PowerOpenSystemPowerKey(phSystemPowerKey, Access, OpenExisting)#uselib "POWRPROF.dll"
#func global PowerOpenSystemPowerKey "PowerOpenSystemPowerKey" sptr, sptr, sptr
; PowerOpenSystemPowerKey phSystemPowerKey, Access, OpenExisting ; 戻り値は stat
; phSystemPowerKey : HKEY* out -> "sptr"
; Access : DWORD -> "sptr"
; OpenExisting : BOOL -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "POWRPROF.dll"
#cfunc global PowerOpenSystemPowerKey "PowerOpenSystemPowerKey" sptr, int, int
; res = PowerOpenSystemPowerKey(phSystemPowerKey, Access, OpenExisting)
; phSystemPowerKey : HKEY* out -> "sptr"
; Access : DWORD -> "int"
; OpenExisting : BOOL -> "int"; DWORD PowerOpenSystemPowerKey(HKEY* phSystemPowerKey, DWORD Access, BOOL OpenExisting)
#uselib "POWRPROF.dll"
#cfunc global PowerOpenSystemPowerKey "PowerOpenSystemPowerKey" intptr, int, int
; res = PowerOpenSystemPowerKey(phSystemPowerKey, Access, OpenExisting)
; phSystemPowerKey : HKEY* out -> "intptr"
; Access : DWORD -> "int"
; OpenExisting : BOOL -> "int"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
powrprof = windows.NewLazySystemDLL("POWRPROF.dll")
procPowerOpenSystemPowerKey = powrprof.NewProc("PowerOpenSystemPowerKey")
)
// phSystemPowerKey (HKEY* out), Access (DWORD), OpenExisting (BOOL)
r1, _, err := procPowerOpenSystemPowerKey.Call(
uintptr(phSystemPowerKey),
uintptr(Access),
uintptr(OpenExisting),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction PowerOpenSystemPowerKey(
phSystemPowerKey: Pointer; // HKEY* out
Access: DWORD; // DWORD
OpenExisting: BOOL // BOOL
): DWORD; stdcall;
external 'POWRPROF.dll' name 'PowerOpenSystemPowerKey';result := DllCall("POWRPROF\PowerOpenSystemPowerKey"
, "Ptr", phSystemPowerKey ; HKEY* out
, "UInt", Access ; DWORD
, "Int", OpenExisting ; BOOL
, "UInt") ; return: DWORD●PowerOpenSystemPowerKey(phSystemPowerKey, Access, OpenExisting) = DLL("POWRPROF.dll", "dword PowerOpenSystemPowerKey(void*, dword, bool)")
# 呼び出し: PowerOpenSystemPowerKey(phSystemPowerKey, Access, OpenExisting)
# phSystemPowerKey : HKEY* out -> "void*"
# Access : DWORD -> "dword"
# OpenExisting : BOOL -> "bool"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "powrprof" fn PowerOpenSystemPowerKey(
phSystemPowerKey: ?*anyopaque, // HKEY* out
Access: u32, // DWORD
OpenExisting: i32 // BOOL
) callconv(std.os.windows.WINAPI) u32;proc PowerOpenSystemPowerKey(
phSystemPowerKey: pointer, # HKEY* out
Access: uint32, # DWORD
OpenExisting: int32 # BOOL
): uint32 {.importc: "PowerOpenSystemPowerKey", stdcall, dynlib: "POWRPROF.dll".}pragma(lib, "powrprof");
extern(Windows)
uint PowerOpenSystemPowerKey(
void* phSystemPowerKey, // HKEY* out
uint Access, // DWORD
int OpenExisting // BOOL
);ccall((:PowerOpenSystemPowerKey, "POWRPROF.dll"), stdcall, UInt32,
(Ptr{Cvoid}, UInt32, Int32),
phSystemPowerKey, Access, OpenExisting)
# phSystemPowerKey : HKEY* out -> Ptr{Cvoid}
# Access : DWORD -> UInt32
# OpenExisting : BOOL -> Int32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
uint32_t PowerOpenSystemPowerKey(
void* phSystemPowerKey,
uint32_t Access,
int32_t OpenExisting);
]]
local powrprof = ffi.load("powrprof")
-- powrprof.PowerOpenSystemPowerKey(phSystemPowerKey, Access, OpenExisting)
-- phSystemPowerKey : HKEY* out
-- Access : DWORD
-- OpenExisting : BOOL
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('POWRPROF.dll');
const PowerOpenSystemPowerKey = lib.func('__stdcall', 'PowerOpenSystemPowerKey', 'uint32_t', ['void *', 'uint32_t', 'int32_t']);
// PowerOpenSystemPowerKey(phSystemPowerKey, Access, OpenExisting)
// phSystemPowerKey : HKEY* out -> 'void *'
// Access : DWORD -> 'uint32_t'
// OpenExisting : BOOL -> 'int32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("POWRPROF.dll", {
PowerOpenSystemPowerKey: { parameters: ["pointer", "u32", "i32"], result: "u32" },
});
// lib.symbols.PowerOpenSystemPowerKey(phSystemPowerKey, Access, OpenExisting)
// phSystemPowerKey : HKEY* out -> "pointer"
// Access : DWORD -> "u32"
// OpenExisting : BOOL -> "i32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t PowerOpenSystemPowerKey(
void* phSystemPowerKey,
uint32_t Access,
int32_t OpenExisting);
C, "POWRPROF.dll");
// $ffi->PowerOpenSystemPowerKey(phSystemPowerKey, Access, OpenExisting);
// phSystemPowerKey : HKEY* out
// Access : DWORD
// OpenExisting : BOOL
// 構造体/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 PowerOpenSystemPowerKey(
Pointer phSystemPowerKey, // HKEY* out
int Access, // DWORD
boolean OpenExisting // BOOL
);
}@[Link("powrprof")]
lib LibPOWRPROF
fun PowerOpenSystemPowerKey = PowerOpenSystemPowerKey(
phSystemPowerKey : Void*, # HKEY* out
Access : UInt32, # DWORD
OpenExisting : Int32 # BOOL
) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef PowerOpenSystemPowerKeyNative = Uint32 Function(Pointer<Void>, Uint32, Int32);
typedef PowerOpenSystemPowerKeyDart = int Function(Pointer<Void>, int, int);
final PowerOpenSystemPowerKey = DynamicLibrary.open('POWRPROF.dll')
.lookupFunction<PowerOpenSystemPowerKeyNative, PowerOpenSystemPowerKeyDart>('PowerOpenSystemPowerKey');
// phSystemPowerKey : HKEY* out -> Pointer<Void>
// Access : DWORD -> Uint32
// OpenExisting : BOOL -> Int32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function PowerOpenSystemPowerKey(
phSystemPowerKey: Pointer; // HKEY* out
Access: DWORD; // DWORD
OpenExisting: BOOL // BOOL
): DWORD; stdcall;
external 'POWRPROF.dll' name 'PowerOpenSystemPowerKey';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "PowerOpenSystemPowerKey"
c_PowerOpenSystemPowerKey :: Ptr () -> Word32 -> CInt -> IO Word32
-- phSystemPowerKey : HKEY* out -> Ptr ()
-- Access : DWORD -> Word32
-- OpenExisting : BOOL -> CInt
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let poweropensystempowerkey =
foreign "PowerOpenSystemPowerKey"
((ptr void) @-> uint32_t @-> int32_t @-> returning uint32_t)
(* phSystemPowerKey : HKEY* out -> (ptr void) *)
(* Access : DWORD -> uint32_t *)
(* OpenExisting : BOOL -> int32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library powrprof (t "POWRPROF.dll"))
(cffi:use-foreign-library powrprof)
(cffi:defcfun ("PowerOpenSystemPowerKey" power-open-system-power-key :convention :stdcall) :uint32
(ph-system-power-key :pointer) ; HKEY* out
(access :uint32) ; DWORD
(open-existing :int32)) ; BOOL
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $PowerOpenSystemPowerKey = Win32::API::More->new('POWRPROF',
'DWORD PowerOpenSystemPowerKey(HANDLE phSystemPowerKey, DWORD Access, BOOL OpenExisting)');
# my $ret = $PowerOpenSystemPowerKey->Call($phSystemPowerKey, $Access, $OpenExisting);
# phSystemPowerKey : HKEY* out -> HANDLE
# Access : DWORD -> DWORD
# OpenExisting : BOOL -> BOOL
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。