SHRegOpenUSKeyA
関数HKCUとHKLMを統合するユーザー単位レジストリキーを開く。
シグネチャ
// SHLWAPI.dll (ANSI / -A)
#include <windows.h>
WIN32_ERROR SHRegOpenUSKeyA(
LPCSTR pszPath,
DWORD samDesired,
INT_PTR hRelativeUSKey, // optional
INT_PTR* phNewUSKey,
BOOL fIgnoreHKCU
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| pszPath | LPCSTR | in | サブキーの名前を含む null 終端文字列へのポインター。 |
| samDesired | DWORD | in | 要求するセキュリティ アクセス。セキュリティ アクセスの詳細については、REGSAM を参照してください。 |
| hRelativeUSKey | INT_PTR | inoptional | 相対パスの基準として使用するキー。pszPath が相対パスの場合、指定されるキーは hRelativeUSKey からの相対パスになります。pszPath が絶対パスの場合は、hRelativeUSKey に NULL を設定します。 |
| phNewUSKey | INT_PTR* | out | 開いたキーのハンドルへのポインター。 |
| fIgnoreHKCU | BOOL | in | どのキーを参照するかを指定する変数。TRUE に設定すると、SHRegOpenUSKey は HKEY_CURRENT_USER を無視し、HKEY_LOCAL_MACHINE から値を返します。 |
戻り値の型: WIN32_ERROR
公式ドキュメント
ユーザー固有のサブツリー(HKEY_CURRENT_USER または HKEY_LOCAL_MACHINE)内のレジストリ サブキーを開きます。(ANSI)
戻り値
型: LSTATUS
成功した場合は ERROR_SUCCESS を返します。それ以外の場合は、Winerror.h で定義されている 0 以外のエラー コードを返します。FormatMessage 関数を FORMAT_MESSAGE_FROM_SYSTEM フラグとともに使用すると、エラーの一般的な説明を取得できます。
解説(Remarks)
メモ
shlwapi.h ヘッダーは、SHRegOpenUSKey をエイリアスとして定義しており、UNICODE プリプロセッサ定数の定義に基づいて、この関数の ANSI 版または Unicode 版を自動的に選択します。エンコード中立のエイリアスの使用を、エンコード中立でないコードと混在させると、不一致が生じ、コンパイル エラーやランタイム エラーの原因となることがあります。詳細については、Conventions for Function Prototypes を参照してください。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// SHLWAPI.dll (ANSI / -A)
#include <windows.h>
WIN32_ERROR SHRegOpenUSKeyA(
LPCSTR pszPath,
DWORD samDesired,
INT_PTR hRelativeUSKey, // optional
INT_PTR* phNewUSKey,
BOOL fIgnoreHKCU
);[DllImport("SHLWAPI.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern uint SHRegOpenUSKeyA(
[MarshalAs(UnmanagedType.LPStr)] string pszPath, // LPCSTR
uint samDesired, // DWORD
IntPtr hRelativeUSKey, // INT_PTR optional
out IntPtr phNewUSKey, // INT_PTR* out
bool fIgnoreHKCU // BOOL
);<DllImport("SHLWAPI.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function SHRegOpenUSKeyA(
<MarshalAs(UnmanagedType.LPStr)> pszPath As String, ' LPCSTR
samDesired As UInteger, ' DWORD
hRelativeUSKey As IntPtr, ' INT_PTR optional
<Out> ByRef phNewUSKey As IntPtr, ' INT_PTR* out
fIgnoreHKCU As Boolean ' BOOL
) As UInteger
End Function' pszPath : LPCSTR
' samDesired : DWORD
' hRelativeUSKey : INT_PTR optional
' phNewUSKey : INT_PTR* out
' fIgnoreHKCU : BOOL
Declare PtrSafe Function SHRegOpenUSKeyA Lib "shlwapi" ( _
ByVal pszPath As String, _
ByVal samDesired As Long, _
ByVal hRelativeUSKey As LongPtr, _
ByRef phNewUSKey As LongPtr, _
ByVal fIgnoreHKCU As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
SHRegOpenUSKeyA = ctypes.windll.shlwapi.SHRegOpenUSKeyA
SHRegOpenUSKeyA.restype = wintypes.DWORD
SHRegOpenUSKeyA.argtypes = [
wintypes.LPCSTR, # pszPath : LPCSTR
wintypes.DWORD, # samDesired : DWORD
ctypes.c_ssize_t, # hRelativeUSKey : INT_PTR optional
ctypes.POINTER(ctypes.c_ssize_t), # phNewUSKey : INT_PTR* out
wintypes.BOOL, # fIgnoreHKCU : BOOL
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('SHLWAPI.dll')
SHRegOpenUSKeyA = Fiddle::Function.new(
lib['SHRegOpenUSKeyA'],
[
Fiddle::TYPE_VOIDP, # pszPath : LPCSTR
-Fiddle::TYPE_INT, # samDesired : DWORD
Fiddle::TYPE_INTPTR_T, # hRelativeUSKey : INT_PTR optional
Fiddle::TYPE_VOIDP, # phNewUSKey : INT_PTR* out
Fiddle::TYPE_INT, # fIgnoreHKCU : BOOL
],
-Fiddle::TYPE_INT)#[link(name = "shlwapi")]
extern "system" {
fn SHRegOpenUSKeyA(
pszPath: *const u8, // LPCSTR
samDesired: u32, // DWORD
hRelativeUSKey: isize, // INT_PTR optional
phNewUSKey: *mut isize, // INT_PTR* out
fIgnoreHKCU: i32 // BOOL
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("SHLWAPI.dll", CharSet = CharSet.Ansi)]
public static extern uint SHRegOpenUSKeyA([MarshalAs(UnmanagedType.LPStr)] string pszPath, uint samDesired, IntPtr hRelativeUSKey, out IntPtr phNewUSKey, bool fIgnoreHKCU);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SHLWAPI_SHRegOpenUSKeyA' -Namespace Win32 -PassThru
# $api::SHRegOpenUSKeyA(pszPath, samDesired, hRelativeUSKey, phNewUSKey, fIgnoreHKCU)#uselib "SHLWAPI.dll"
#func global SHRegOpenUSKeyA "SHRegOpenUSKeyA" sptr, sptr, sptr, sptr, sptr
; SHRegOpenUSKeyA pszPath, samDesired, hRelativeUSKey, varptr(phNewUSKey), fIgnoreHKCU ; 戻り値は stat
; pszPath : LPCSTR -> "sptr"
; samDesired : DWORD -> "sptr"
; hRelativeUSKey : INT_PTR optional -> "sptr"
; phNewUSKey : INT_PTR* out -> "sptr"
; fIgnoreHKCU : BOOL -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "SHLWAPI.dll" #cfunc global SHRegOpenUSKeyA "SHRegOpenUSKeyA" str, int, sptr, var, int ; res = SHRegOpenUSKeyA(pszPath, samDesired, hRelativeUSKey, phNewUSKey, fIgnoreHKCU) ; pszPath : LPCSTR -> "str" ; samDesired : DWORD -> "int" ; hRelativeUSKey : INT_PTR optional -> "sptr" ; phNewUSKey : INT_PTR* out -> "var" ; fIgnoreHKCU : BOOL -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "SHLWAPI.dll" #cfunc global SHRegOpenUSKeyA "SHRegOpenUSKeyA" str, int, sptr, sptr, int ; res = SHRegOpenUSKeyA(pszPath, samDesired, hRelativeUSKey, varptr(phNewUSKey), fIgnoreHKCU) ; pszPath : LPCSTR -> "str" ; samDesired : DWORD -> "int" ; hRelativeUSKey : INT_PTR optional -> "sptr" ; phNewUSKey : INT_PTR* out -> "sptr" ; fIgnoreHKCU : BOOL -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; WIN32_ERROR SHRegOpenUSKeyA(LPCSTR pszPath, DWORD samDesired, INT_PTR hRelativeUSKey, INT_PTR* phNewUSKey, BOOL fIgnoreHKCU) #uselib "SHLWAPI.dll" #cfunc global SHRegOpenUSKeyA "SHRegOpenUSKeyA" str, int, intptr, var, int ; res = SHRegOpenUSKeyA(pszPath, samDesired, hRelativeUSKey, phNewUSKey, fIgnoreHKCU) ; pszPath : LPCSTR -> "str" ; samDesired : DWORD -> "int" ; hRelativeUSKey : INT_PTR optional -> "intptr" ; phNewUSKey : INT_PTR* out -> "var" ; fIgnoreHKCU : BOOL -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; WIN32_ERROR SHRegOpenUSKeyA(LPCSTR pszPath, DWORD samDesired, INT_PTR hRelativeUSKey, INT_PTR* phNewUSKey, BOOL fIgnoreHKCU) #uselib "SHLWAPI.dll" #cfunc global SHRegOpenUSKeyA "SHRegOpenUSKeyA" str, int, intptr, intptr, int ; res = SHRegOpenUSKeyA(pszPath, samDesired, hRelativeUSKey, varptr(phNewUSKey), fIgnoreHKCU) ; pszPath : LPCSTR -> "str" ; samDesired : DWORD -> "int" ; hRelativeUSKey : INT_PTR optional -> "intptr" ; phNewUSKey : INT_PTR* out -> "intptr" ; fIgnoreHKCU : BOOL -> "int" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
shlwapi = windows.NewLazySystemDLL("SHLWAPI.dll")
procSHRegOpenUSKeyA = shlwapi.NewProc("SHRegOpenUSKeyA")
)
// pszPath (LPCSTR), samDesired (DWORD), hRelativeUSKey (INT_PTR optional), phNewUSKey (INT_PTR* out), fIgnoreHKCU (BOOL)
r1, _, err := procSHRegOpenUSKeyA.Call(
uintptr(unsafe.Pointer(windows.BytePtrFromString(pszPath))),
uintptr(samDesired),
uintptr(hRelativeUSKey),
uintptr(phNewUSKey),
uintptr(fIgnoreHKCU),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // WIN32_ERRORfunction SHRegOpenUSKeyA(
pszPath: PAnsiChar; // LPCSTR
samDesired: DWORD; // DWORD
hRelativeUSKey: NativeInt; // INT_PTR optional
phNewUSKey: Pointer; // INT_PTR* out
fIgnoreHKCU: BOOL // BOOL
): DWORD; stdcall;
external 'SHLWAPI.dll' name 'SHRegOpenUSKeyA';result := DllCall("SHLWAPI\SHRegOpenUSKeyA"
, "AStr", pszPath ; LPCSTR
, "UInt", samDesired ; DWORD
, "Ptr", hRelativeUSKey ; INT_PTR optional
, "Ptr", phNewUSKey ; INT_PTR* out
, "Int", fIgnoreHKCU ; BOOL
, "UInt") ; return: WIN32_ERROR●SHRegOpenUSKeyA(pszPath, samDesired, hRelativeUSKey, phNewUSKey, fIgnoreHKCU) = DLL("SHLWAPI.dll", "dword SHRegOpenUSKeyA(char*, dword, int, void*, bool)")
# 呼び出し: SHRegOpenUSKeyA(pszPath, samDesired, hRelativeUSKey, phNewUSKey, fIgnoreHKCU)
# pszPath : LPCSTR -> "char*"
# samDesired : DWORD -> "dword"
# hRelativeUSKey : INT_PTR optional -> "int"
# phNewUSKey : INT_PTR* out -> "void*"
# fIgnoreHKCU : BOOL -> "bool"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "shlwapi" fn SHRegOpenUSKeyA(
pszPath: [*c]const u8, // LPCSTR
samDesired: u32, // DWORD
hRelativeUSKey: isize, // INT_PTR optional
phNewUSKey: [*c]isize, // INT_PTR* out
fIgnoreHKCU: i32 // BOOL
) callconv(std.os.windows.WINAPI) u32;proc SHRegOpenUSKeyA(
pszPath: cstring, # LPCSTR
samDesired: uint32, # DWORD
hRelativeUSKey: int, # INT_PTR optional
phNewUSKey: ptr int, # INT_PTR* out
fIgnoreHKCU: int32 # BOOL
): uint32 {.importc: "SHRegOpenUSKeyA", stdcall, dynlib: "SHLWAPI.dll".}pragma(lib, "shlwapi");
extern(Windows)
uint SHRegOpenUSKeyA(
const(char)* pszPath, // LPCSTR
uint samDesired, // DWORD
ptrdiff_t hRelativeUSKey, // INT_PTR optional
ptrdiff_t* phNewUSKey, // INT_PTR* out
int fIgnoreHKCU // BOOL
);ccall((:SHRegOpenUSKeyA, "SHLWAPI.dll"), stdcall, UInt32,
(Cstring, UInt32, Int, Ptr{Int}, Int32),
pszPath, samDesired, hRelativeUSKey, phNewUSKey, fIgnoreHKCU)
# pszPath : LPCSTR -> Cstring
# samDesired : DWORD -> UInt32
# hRelativeUSKey : INT_PTR optional -> Int
# phNewUSKey : INT_PTR* out -> Ptr{Int}
# fIgnoreHKCU : BOOL -> Int32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
uint32_t SHRegOpenUSKeyA(
const char* pszPath,
uint32_t samDesired,
intptr_t hRelativeUSKey,
intptr_t* phNewUSKey,
int32_t fIgnoreHKCU);
]]
local shlwapi = ffi.load("shlwapi")
-- shlwapi.SHRegOpenUSKeyA(pszPath, samDesired, hRelativeUSKey, phNewUSKey, fIgnoreHKCU)
-- pszPath : LPCSTR
-- samDesired : DWORD
-- hRelativeUSKey : INT_PTR optional
-- phNewUSKey : INT_PTR* out
-- fIgnoreHKCU : BOOL
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('SHLWAPI.dll');
const SHRegOpenUSKeyA = lib.func('__stdcall', 'SHRegOpenUSKeyA', 'uint32_t', ['str', 'uint32_t', 'intptr_t', 'intptr_t *', 'int32_t']);
// SHRegOpenUSKeyA(pszPath, samDesired, hRelativeUSKey, phNewUSKey, fIgnoreHKCU)
// pszPath : LPCSTR -> 'str'
// samDesired : DWORD -> 'uint32_t'
// hRelativeUSKey : INT_PTR optional -> 'intptr_t'
// phNewUSKey : INT_PTR* out -> 'intptr_t *'
// fIgnoreHKCU : BOOL -> 'int32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("SHLWAPI.dll", {
SHRegOpenUSKeyA: { parameters: ["buffer", "u32", "isize", "pointer", "i32"], result: "u32" },
});
// lib.symbols.SHRegOpenUSKeyA(pszPath, samDesired, hRelativeUSKey, phNewUSKey, fIgnoreHKCU)
// pszPath : LPCSTR -> "buffer"
// samDesired : DWORD -> "u32"
// hRelativeUSKey : INT_PTR optional -> "isize"
// phNewUSKey : INT_PTR* out -> "pointer"
// fIgnoreHKCU : BOOL -> "i32"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t SHRegOpenUSKeyA(
const char* pszPath,
uint32_t samDesired,
intptr_t hRelativeUSKey,
intptr_t* phNewUSKey,
int32_t fIgnoreHKCU);
C, "SHLWAPI.dll");
// $ffi->SHRegOpenUSKeyA(pszPath, samDesired, hRelativeUSKey, phNewUSKey, fIgnoreHKCU);
// pszPath : LPCSTR
// samDesired : DWORD
// hRelativeUSKey : INT_PTR optional
// phNewUSKey : INT_PTR* out
// fIgnoreHKCU : 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 Shlwapi extends StdCallLibrary {
Shlwapi INSTANCE = Native.load("shlwapi", Shlwapi.class, W32APIOptions.ASCII_OPTIONS);
int SHRegOpenUSKeyA(
String pszPath, // LPCSTR
int samDesired, // DWORD
long hRelativeUSKey, // INT_PTR optional
LongByReference phNewUSKey, // INT_PTR* out
boolean fIgnoreHKCU // BOOL
);
}@[Link("shlwapi")]
lib LibSHLWAPI
fun SHRegOpenUSKeyA = SHRegOpenUSKeyA(
pszPath : UInt8*, # LPCSTR
samDesired : UInt32, # DWORD
hRelativeUSKey : LibC::SSizeT, # INT_PTR optional
phNewUSKey : LibC::SSizeT*, # INT_PTR* out
fIgnoreHKCU : 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 SHRegOpenUSKeyANative = Uint32 Function(Pointer<Utf8>, Uint32, IntPtr, Pointer<IntPtr>, Int32);
typedef SHRegOpenUSKeyADart = int Function(Pointer<Utf8>, int, int, Pointer<IntPtr>, int);
final SHRegOpenUSKeyA = DynamicLibrary.open('SHLWAPI.dll')
.lookupFunction<SHRegOpenUSKeyANative, SHRegOpenUSKeyADart>('SHRegOpenUSKeyA');
// pszPath : LPCSTR -> Pointer<Utf8>
// samDesired : DWORD -> Uint32
// hRelativeUSKey : INT_PTR optional -> IntPtr
// phNewUSKey : INT_PTR* out -> Pointer<IntPtr>
// fIgnoreHKCU : BOOL -> Int32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function SHRegOpenUSKeyA(
pszPath: PAnsiChar; // LPCSTR
samDesired: DWORD; // DWORD
hRelativeUSKey: NativeInt; // INT_PTR optional
phNewUSKey: Pointer; // INT_PTR* out
fIgnoreHKCU: BOOL // BOOL
): DWORD; stdcall;
external 'SHLWAPI.dll' name 'SHRegOpenUSKeyA';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "SHRegOpenUSKeyA"
c_SHRegOpenUSKeyA :: CString -> Word32 -> CIntPtr -> Ptr CIntPtr -> CInt -> IO Word32
-- pszPath : LPCSTR -> CString
-- samDesired : DWORD -> Word32
-- hRelativeUSKey : INT_PTR optional -> CIntPtr
-- phNewUSKey : INT_PTR* out -> Ptr CIntPtr
-- fIgnoreHKCU : BOOL -> CInt
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let shregopenuskeya =
foreign "SHRegOpenUSKeyA"
(string @-> uint32_t @-> intptr_t @-> (ptr intptr_t) @-> int32_t @-> returning uint32_t)
(* pszPath : LPCSTR -> string *)
(* samDesired : DWORD -> uint32_t *)
(* hRelativeUSKey : INT_PTR optional -> intptr_t *)
(* phNewUSKey : INT_PTR* out -> (ptr intptr_t) *)
(* fIgnoreHKCU : BOOL -> int32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library shlwapi (t "SHLWAPI.dll"))
(cffi:use-foreign-library shlwapi)
(cffi:defcfun ("SHRegOpenUSKeyA" shreg-open-uskey-a :convention :stdcall) :uint32
(psz-path :string) ; LPCSTR
(sam-desired :uint32) ; DWORD
(h-relative-uskey :int64) ; INT_PTR optional
(ph-new-uskey :pointer) ; INT_PTR* out
(f-ignore-hkcu :int32)) ; BOOL
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $SHRegOpenUSKeyA = Win32::API::More->new('SHLWAPI',
'DWORD SHRegOpenUSKeyA(LPCSTR pszPath, DWORD samDesired, LPARAM hRelativeUSKey, LPVOID phNewUSKey, BOOL fIgnoreHKCU)');
# my $ret = $SHRegOpenUSKeyA->Call($pszPath, $samDesired, $hRelativeUSKey, $phNewUSKey, $fIgnoreHKCU);
# pszPath : LPCSTR -> LPCSTR
# samDesired : DWORD -> DWORD
# hRelativeUSKey : INT_PTR optional -> LPARAM
# phNewUSKey : INT_PTR* out -> LPVOID
# fIgnoreHKCU : BOOL -> BOOL
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
文字セット違い
- f SHRegOpenUSKeyW (Unicode版) — HKCUとHKLMを統合するユーザー単位レジストリキーを開く。
使用する型