ホーム › System.Registry › RegOpenKeyA
RegOpenKeyA
関数指定したレジストリキーを開く。
シグネチャ
// ADVAPI32.dll (ANSI / -A)
#include <windows.h>
WIN32_ERROR RegOpenKeyA(
HKEY hKey,
LPCSTR lpSubKey, // optional
HKEY* phkResult
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| hKey | HKEY | in |
| lpSubKey | LPCSTR | inoptional |
| phkResult | HKEY* | out |
戻り値の型: WIN32_ERROR
各言語での呼び出し定義
// ADVAPI32.dll (ANSI / -A)
#include <windows.h>
WIN32_ERROR RegOpenKeyA(
HKEY hKey,
LPCSTR lpSubKey, // optional
HKEY* phkResult
);[DllImport("ADVAPI32.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern uint RegOpenKeyA(
IntPtr hKey, // HKEY
[MarshalAs(UnmanagedType.LPStr)] string lpSubKey, // LPCSTR optional
IntPtr phkResult // HKEY* out
);<DllImport("ADVAPI32.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function RegOpenKeyA(
hKey As IntPtr, ' HKEY
<MarshalAs(UnmanagedType.LPStr)> lpSubKey As String, ' LPCSTR optional
phkResult As IntPtr ' HKEY* out
) As UInteger
End Function' hKey : HKEY
' lpSubKey : LPCSTR optional
' phkResult : HKEY* out
Declare PtrSafe Function RegOpenKeyA Lib "advapi32" ( _
ByVal hKey As LongPtr, _
ByVal lpSubKey As String, _
ByVal phkResult As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
RegOpenKeyA = ctypes.windll.advapi32.RegOpenKeyA
RegOpenKeyA.restype = wintypes.DWORD
RegOpenKeyA.argtypes = [
wintypes.HANDLE, # hKey : HKEY
wintypes.LPCSTR, # lpSubKey : LPCSTR optional
ctypes.c_void_p, # phkResult : HKEY* out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('ADVAPI32.dll')
RegOpenKeyA = Fiddle::Function.new(
lib['RegOpenKeyA'],
[
Fiddle::TYPE_VOIDP, # hKey : HKEY
Fiddle::TYPE_VOIDP, # lpSubKey : LPCSTR optional
Fiddle::TYPE_VOIDP, # phkResult : HKEY* out
],
-Fiddle::TYPE_INT)#[link(name = "advapi32")]
extern "system" {
fn RegOpenKeyA(
hKey: *mut core::ffi::c_void, // HKEY
lpSubKey: *const u8, // LPCSTR optional
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.Ansi)]
public static extern uint RegOpenKeyA(IntPtr hKey, [MarshalAs(UnmanagedType.LPStr)] string lpSubKey, IntPtr phkResult);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ADVAPI32_RegOpenKeyA' -Namespace Win32 -PassThru
# $api::RegOpenKeyA(hKey, lpSubKey, phkResult)#uselib "ADVAPI32.dll"
#func global RegOpenKeyA "RegOpenKeyA" sptr, sptr, sptr
; RegOpenKeyA hKey, lpSubKey, phkResult ; 戻り値は stat
; hKey : HKEY -> "sptr"
; lpSubKey : LPCSTR optional -> "sptr"
; phkResult : HKEY* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "ADVAPI32.dll"
#cfunc global RegOpenKeyA "RegOpenKeyA" sptr, str, sptr
; res = RegOpenKeyA(hKey, lpSubKey, phkResult)
; hKey : HKEY -> "sptr"
; lpSubKey : LPCSTR optional -> "str"
; phkResult : HKEY* out -> "sptr"; WIN32_ERROR RegOpenKeyA(HKEY hKey, LPCSTR lpSubKey, HKEY* phkResult)
#uselib "ADVAPI32.dll"
#cfunc global RegOpenKeyA "RegOpenKeyA" intptr, str, intptr
; res = RegOpenKeyA(hKey, lpSubKey, phkResult)
; hKey : HKEY -> "intptr"
; lpSubKey : LPCSTR optional -> "str"
; phkResult : HKEY* out -> "intptr"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
advapi32 = windows.NewLazySystemDLL("ADVAPI32.dll")
procRegOpenKeyA = advapi32.NewProc("RegOpenKeyA")
)
// hKey (HKEY), lpSubKey (LPCSTR optional), phkResult (HKEY* out)
r1, _, err := procRegOpenKeyA.Call(
uintptr(hKey),
uintptr(unsafe.Pointer(windows.BytePtrFromString(lpSubKey))),
uintptr(phkResult),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // WIN32_ERRORfunction RegOpenKeyA(
hKey: THandle; // HKEY
lpSubKey: PAnsiChar; // LPCSTR optional
phkResult: Pointer // HKEY* out
): DWORD; stdcall;
external 'ADVAPI32.dll' name 'RegOpenKeyA';result := DllCall("ADVAPI32\RegOpenKeyA"
, "Ptr", hKey ; HKEY
, "AStr", lpSubKey ; LPCSTR optional
, "Ptr", phkResult ; HKEY* out
, "UInt") ; return: WIN32_ERROR●RegOpenKeyA(hKey, lpSubKey, phkResult) = DLL("ADVAPI32.dll", "dword RegOpenKeyA(void*, char*, void*)")
# 呼び出し: RegOpenKeyA(hKey, lpSubKey, phkResult)
# hKey : HKEY -> "void*"
# lpSubKey : LPCSTR optional -> "char*"
# phkResult : HKEY* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。