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

PowerOpenUserPowerKey

関数
ユーザー固有の電源設定レジストリキーを開く。
DLLPOWRPROF.dll呼出規約winapi

シグネチャ

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

DWORD PowerOpenUserPowerKey(
    HKEY* phUserPowerKey,
    DWORD Access,
    BOOL OpenExisting
);

パラメーター

名前方向
phUserPowerKeyHKEY*out
AccessDWORDin
OpenExistingBOOLin

戻り値の型: DWORD

各言語での呼び出し定義

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

DWORD PowerOpenUserPowerKey(
    HKEY* phUserPowerKey,
    DWORD Access,
    BOOL OpenExisting
);
[DllImport("POWRPROF.dll", ExactSpelling = true)]
static extern uint PowerOpenUserPowerKey(
    IntPtr phUserPowerKey,   // HKEY* out
    uint Access,   // DWORD
    bool OpenExisting   // BOOL
);
<DllImport("POWRPROF.dll", ExactSpelling:=True)>
Public Shared Function PowerOpenUserPowerKey(
    phUserPowerKey As IntPtr,   ' HKEY* out
    Access As UInteger,   ' DWORD
    OpenExisting As Boolean   ' BOOL
) As UInteger
End Function
' phUserPowerKey : HKEY* out
' Access : DWORD
' OpenExisting : BOOL
Declare PtrSafe Function PowerOpenUserPowerKey Lib "powrprof" ( _
    ByVal phUserPowerKey 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

PowerOpenUserPowerKey = ctypes.windll.powrprof.PowerOpenUserPowerKey
PowerOpenUserPowerKey.restype = wintypes.DWORD
PowerOpenUserPowerKey.argtypes = [
    ctypes.c_void_p,  # phUserPowerKey : HKEY* out
    wintypes.DWORD,  # Access : DWORD
    wintypes.BOOL,  # OpenExisting : BOOL
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('POWRPROF.dll')
PowerOpenUserPowerKey = Fiddle::Function.new(
  lib['PowerOpenUserPowerKey'],
  [
    Fiddle::TYPE_VOIDP,  # phUserPowerKey : HKEY* out
    -Fiddle::TYPE_INT,  # Access : DWORD
    Fiddle::TYPE_INT,  # OpenExisting : BOOL
  ],
  -Fiddle::TYPE_INT)
#[link(name = "powrprof")]
extern "system" {
    fn PowerOpenUserPowerKey(
        phUserPowerKey: *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 PowerOpenUserPowerKey(IntPtr phUserPowerKey, uint Access, bool OpenExisting);
"@
$api = Add-Type -MemberDefinition $sig -Name 'POWRPROF_PowerOpenUserPowerKey' -Namespace Win32 -PassThru
# $api::PowerOpenUserPowerKey(phUserPowerKey, Access, OpenExisting)
#uselib "POWRPROF.dll"
#func global PowerOpenUserPowerKey "PowerOpenUserPowerKey" sptr, sptr, sptr
; PowerOpenUserPowerKey phUserPowerKey, Access, OpenExisting   ; 戻り値は stat
; phUserPowerKey : HKEY* out -> "sptr"
; Access : DWORD -> "sptr"
; OpenExisting : BOOL -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "POWRPROF.dll"
#cfunc global PowerOpenUserPowerKey "PowerOpenUserPowerKey" sptr, int, int
; res = PowerOpenUserPowerKey(phUserPowerKey, Access, OpenExisting)
; phUserPowerKey : HKEY* out -> "sptr"
; Access : DWORD -> "int"
; OpenExisting : BOOL -> "int"
; DWORD PowerOpenUserPowerKey(HKEY* phUserPowerKey, DWORD Access, BOOL OpenExisting)
#uselib "POWRPROF.dll"
#cfunc global PowerOpenUserPowerKey "PowerOpenUserPowerKey" intptr, int, int
; res = PowerOpenUserPowerKey(phUserPowerKey, Access, OpenExisting)
; phUserPowerKey : HKEY* out -> "intptr"
; Access : DWORD -> "int"
; OpenExisting : BOOL -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	powrprof = windows.NewLazySystemDLL("POWRPROF.dll")
	procPowerOpenUserPowerKey = powrprof.NewProc("PowerOpenUserPowerKey")
)

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