ホーム › System.Registry › RegOpenKeyExW
RegOpenKeyExW
関数アクセス権を指定してレジストリキーを開く。
シグネチャ
// ADVAPI32.dll (Unicode / -W)
#include <windows.h>
WIN32_ERROR RegOpenKeyExW(
HKEY hKey,
LPCWSTR lpSubKey, // optional
DWORD ulOptions, // optional
REG_SAM_FLAGS samDesired,
HKEY* phkResult
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| hKey | HKEY | in |
| lpSubKey | LPCWSTR | inoptional |
| ulOptions | DWORD | inoptional |
| samDesired | REG_SAM_FLAGS | in |
| phkResult | HKEY* | out |
戻り値の型: WIN32_ERROR
各言語での呼び出し定義
// ADVAPI32.dll (Unicode / -W)
#include <windows.h>
WIN32_ERROR RegOpenKeyExW(
HKEY hKey,
LPCWSTR lpSubKey, // optional
DWORD ulOptions, // optional
REG_SAM_FLAGS samDesired,
HKEY* phkResult
);[DllImport("ADVAPI32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern uint RegOpenKeyExW(
IntPtr hKey, // HKEY
[MarshalAs(UnmanagedType.LPWStr)] string lpSubKey, // LPCWSTR optional
uint ulOptions, // DWORD optional
uint samDesired, // REG_SAM_FLAGS
IntPtr phkResult // HKEY* out
);<DllImport("ADVAPI32.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function RegOpenKeyExW(
hKey As IntPtr, ' HKEY
<MarshalAs(UnmanagedType.LPWStr)> lpSubKey As String, ' LPCWSTR optional
ulOptions As UInteger, ' DWORD optional
samDesired As UInteger, ' REG_SAM_FLAGS
phkResult As IntPtr ' HKEY* out
) As UInteger
End Function' hKey : HKEY
' lpSubKey : LPCWSTR optional
' ulOptions : DWORD optional
' samDesired : REG_SAM_FLAGS
' phkResult : HKEY* out
Declare PtrSafe Function RegOpenKeyExW Lib "advapi32" ( _
ByVal hKey As LongPtr, _
ByVal lpSubKey As LongPtr, _
ByVal ulOptions As Long, _
ByVal samDesired As Long, _
ByVal phkResult As LongPtr) As Long
' Unicode(W): 文字列は ByVal As LongPtr とし StrPtr(unicodeStr) を渡す
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
RegOpenKeyExW = ctypes.windll.advapi32.RegOpenKeyExW
RegOpenKeyExW.restype = wintypes.DWORD
RegOpenKeyExW.argtypes = [
wintypes.HANDLE, # hKey : HKEY
wintypes.LPCWSTR, # lpSubKey : LPCWSTR optional
wintypes.DWORD, # ulOptions : DWORD optional
wintypes.DWORD, # samDesired : REG_SAM_FLAGS
ctypes.c_void_p, # phkResult : HKEY* out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('ADVAPI32.dll')
RegOpenKeyExW = Fiddle::Function.new(
lib['RegOpenKeyExW'],
[
Fiddle::TYPE_VOIDP, # hKey : HKEY
Fiddle::TYPE_VOIDP, # lpSubKey : LPCWSTR optional
-Fiddle::TYPE_INT, # ulOptions : DWORD optional
-Fiddle::TYPE_INT, # samDesired : REG_SAM_FLAGS
Fiddle::TYPE_VOIDP, # phkResult : HKEY* out
],
-Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "advapi32")]
extern "system" {
fn RegOpenKeyExW(
hKey: *mut core::ffi::c_void, // HKEY
lpSubKey: *const u16, // LPCWSTR optional
ulOptions: u32, // DWORD optional
samDesired: u32, // REG_SAM_FLAGS
phkResult: *mut *mut core::ffi::c_void // HKEY* out
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("ADVAPI32.dll", CharSet = CharSet.Unicode)]
public static extern uint RegOpenKeyExW(IntPtr hKey, [MarshalAs(UnmanagedType.LPWStr)] string lpSubKey, uint ulOptions, uint samDesired, IntPtr phkResult);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ADVAPI32_RegOpenKeyExW' -Namespace Win32 -PassThru
# $api::RegOpenKeyExW(hKey, lpSubKey, ulOptions, samDesired, phkResult)#uselib "ADVAPI32.dll"
#func global RegOpenKeyExW "RegOpenKeyExW" wptr, wptr, wptr, wptr, wptr
; RegOpenKeyExW hKey, lpSubKey, ulOptions, samDesired, phkResult ; 戻り値は stat
; hKey : HKEY -> "wptr"
; lpSubKey : LPCWSTR optional -> "wptr"
; ulOptions : DWORD optional -> "wptr"
; samDesired : REG_SAM_FLAGS -> "wptr"
; phkResult : HKEY* out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "ADVAPI32.dll"
#cfunc global RegOpenKeyExW "RegOpenKeyExW" sptr, wstr, int, int, sptr
; res = RegOpenKeyExW(hKey, lpSubKey, ulOptions, samDesired, phkResult)
; hKey : HKEY -> "sptr"
; lpSubKey : LPCWSTR optional -> "wstr"
; ulOptions : DWORD optional -> "int"
; samDesired : REG_SAM_FLAGS -> "int"
; phkResult : HKEY* out -> "sptr"; WIN32_ERROR RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REG_SAM_FLAGS samDesired, HKEY* phkResult)
#uselib "ADVAPI32.dll"
#cfunc global RegOpenKeyExW "RegOpenKeyExW" intptr, wstr, int, int, intptr
; res = RegOpenKeyExW(hKey, lpSubKey, ulOptions, samDesired, phkResult)
; hKey : HKEY -> "intptr"
; lpSubKey : LPCWSTR optional -> "wstr"
; ulOptions : DWORD optional -> "int"
; samDesired : REG_SAM_FLAGS -> "int"
; phkResult : HKEY* out -> "intptr"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
advapi32 = windows.NewLazySystemDLL("ADVAPI32.dll")
procRegOpenKeyExW = advapi32.NewProc("RegOpenKeyExW")
)
// hKey (HKEY), lpSubKey (LPCWSTR optional), ulOptions (DWORD optional), samDesired (REG_SAM_FLAGS), phkResult (HKEY* out)
r1, _, err := procRegOpenKeyExW.Call(
uintptr(hKey),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpSubKey))),
uintptr(ulOptions),
uintptr(samDesired),
uintptr(phkResult),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // WIN32_ERRORfunction RegOpenKeyExW(
hKey: THandle; // HKEY
lpSubKey: PWideChar; // LPCWSTR optional
ulOptions: DWORD; // DWORD optional
samDesired: DWORD; // REG_SAM_FLAGS
phkResult: Pointer // HKEY* out
): DWORD; stdcall;
external 'ADVAPI32.dll' name 'RegOpenKeyExW';result := DllCall("ADVAPI32\RegOpenKeyExW"
, "Ptr", hKey ; HKEY
, "WStr", lpSubKey ; LPCWSTR optional
, "UInt", ulOptions ; DWORD optional
, "UInt", samDesired ; REG_SAM_FLAGS
, "Ptr", phkResult ; HKEY* out
, "UInt") ; return: WIN32_ERROR●RegOpenKeyExW(hKey, lpSubKey, ulOptions, samDesired, phkResult) = DLL("ADVAPI32.dll", "dword RegOpenKeyExW(void*, char*, dword, dword, void*)")
# 呼び出し: RegOpenKeyExW(hKey, lpSubKey, ulOptions, samDesired, phkResult)
# hKey : HKEY -> "void*"
# lpSubKey : LPCWSTR optional -> "char*"
# ulOptions : DWORD optional -> "dword"
# samDesired : REG_SAM_FLAGS -> "dword"
# phkResult : HKEY* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。