Win32 API 日本語リファレンス
ホームUI.Shell › SHOpenRegStream2A

SHOpenRegStream2A

関数
レジストリ値の内容を扱うストリームを開く拡張版である。
DLLSHLWAPI.dll文字セットANSI (-A)呼出規約winapi対応OSWindows 2000 以降

シグネチャ

// SHLWAPI.dll  (ANSI / -A)
#include <windows.h>

IStream* SHOpenRegStream2A(
    HKEY hkey,
    LPCSTR pszSubkey,   // optional
    LPCSTR pszValue,   // optional
    DWORD grfMode
);

パラメーター

名前方向
hkeyHKEYin
pszSubkeyLPCSTRinoptional
pszValueLPCSTRinoptional
grfModeDWORDin

戻り値の型: IStream*

各言語での呼び出し定義

// SHLWAPI.dll  (ANSI / -A)
#include <windows.h>

IStream* SHOpenRegStream2A(
    HKEY hkey,
    LPCSTR pszSubkey,   // optional
    LPCSTR pszValue,   // optional
    DWORD grfMode
);
[DllImport("SHLWAPI.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern IntPtr SHOpenRegStream2A(
    IntPtr hkey,   // HKEY
    [MarshalAs(UnmanagedType.LPStr)] string pszSubkey,   // LPCSTR optional
    [MarshalAs(UnmanagedType.LPStr)] string pszValue,   // LPCSTR optional
    uint grfMode   // DWORD
);
<DllImport("SHLWAPI.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function SHOpenRegStream2A(
    hkey As IntPtr,   ' HKEY
    <MarshalAs(UnmanagedType.LPStr)> pszSubkey As String,   ' LPCSTR optional
    <MarshalAs(UnmanagedType.LPStr)> pszValue As String,   ' LPCSTR optional
    grfMode As UInteger   ' DWORD
) As IntPtr
End Function
' hkey : HKEY
' pszSubkey : LPCSTR optional
' pszValue : LPCSTR optional
' grfMode : DWORD
Declare PtrSafe Function SHOpenRegStream2A Lib "shlwapi" ( _
    ByVal hkey As LongPtr, _
    ByVal pszSubkey As String, _
    ByVal pszValue As String, _
    ByVal grfMode As Long) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SHOpenRegStream2A = ctypes.windll.shlwapi.SHOpenRegStream2A
SHOpenRegStream2A.restype = ctypes.c_void_p
SHOpenRegStream2A.argtypes = [
    wintypes.HANDLE,  # hkey : HKEY
    wintypes.LPCSTR,  # pszSubkey : LPCSTR optional
    wintypes.LPCSTR,  # pszValue : LPCSTR optional
    wintypes.DWORD,  # grfMode : DWORD
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('SHLWAPI.dll')
SHOpenRegStream2A = Fiddle::Function.new(
  lib['SHOpenRegStream2A'],
  [
    Fiddle::TYPE_VOIDP,  # hkey : HKEY
    Fiddle::TYPE_VOIDP,  # pszSubkey : LPCSTR optional
    Fiddle::TYPE_VOIDP,  # pszValue : LPCSTR optional
    -Fiddle::TYPE_INT,  # grfMode : DWORD
  ],
  Fiddle::TYPE_VOIDP)
#[link(name = "shlwapi")]
extern "system" {
    fn SHOpenRegStream2A(
        hkey: *mut core::ffi::c_void,  // HKEY
        pszSubkey: *const u8,  // LPCSTR optional
        pszValue: *const u8,  // LPCSTR optional
        grfMode: u32  // DWORD
    ) -> *mut core::ffi::c_void;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("SHLWAPI.dll", CharSet = CharSet.Ansi)]
public static extern IntPtr SHOpenRegStream2A(IntPtr hkey, [MarshalAs(UnmanagedType.LPStr)] string pszSubkey, [MarshalAs(UnmanagedType.LPStr)] string pszValue, uint grfMode);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SHLWAPI_SHOpenRegStream2A' -Namespace Win32 -PassThru
# $api::SHOpenRegStream2A(hkey, pszSubkey, pszValue, grfMode)
#uselib "SHLWAPI.dll"
#func global SHOpenRegStream2A "SHOpenRegStream2A" sptr, sptr, sptr, sptr
; SHOpenRegStream2A hkey, pszSubkey, pszValue, grfMode   ; 戻り値は stat
; hkey : HKEY -> "sptr"
; pszSubkey : LPCSTR optional -> "sptr"
; pszValue : LPCSTR optional -> "sptr"
; grfMode : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "SHLWAPI.dll"
#cfunc global SHOpenRegStream2A "SHOpenRegStream2A" sptr, str, str, int
; res = SHOpenRegStream2A(hkey, pszSubkey, pszValue, grfMode)
; hkey : HKEY -> "sptr"
; pszSubkey : LPCSTR optional -> "str"
; pszValue : LPCSTR optional -> "str"
; grfMode : DWORD -> "int"
; IStream* SHOpenRegStream2A(HKEY hkey, LPCSTR pszSubkey, LPCSTR pszValue, DWORD grfMode)
#uselib "SHLWAPI.dll"
#cfunc global SHOpenRegStream2A "SHOpenRegStream2A" intptr, str, str, int
; res = SHOpenRegStream2A(hkey, pszSubkey, pszValue, grfMode)
; hkey : HKEY -> "intptr"
; pszSubkey : LPCSTR optional -> "str"
; pszValue : LPCSTR optional -> "str"
; grfMode : DWORD -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	shlwapi = windows.NewLazySystemDLL("SHLWAPI.dll")
	procSHOpenRegStream2A = shlwapi.NewProc("SHOpenRegStream2A")
)

// hkey (HKEY), pszSubkey (LPCSTR optional), pszValue (LPCSTR optional), grfMode (DWORD)
r1, _, err := procSHOpenRegStream2A.Call(
	uintptr(hkey),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(pszSubkey))),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(pszValue))),
	uintptr(grfMode),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // IStream*
function SHOpenRegStream2A(
  hkey: THandle;   // HKEY
  pszSubkey: PAnsiChar;   // LPCSTR optional
  pszValue: PAnsiChar;   // LPCSTR optional
  grfMode: DWORD   // DWORD
): Pointer; stdcall;
  external 'SHLWAPI.dll' name 'SHOpenRegStream2A';
result := DllCall("SHLWAPI\SHOpenRegStream2A"
    , "Ptr", hkey   ; HKEY
    , "AStr", pszSubkey   ; LPCSTR optional
    , "AStr", pszValue   ; LPCSTR optional
    , "UInt", grfMode   ; DWORD
    , "Ptr")   ; return: IStream*
●SHOpenRegStream2A(hkey, pszSubkey, pszValue, grfMode) = DLL("SHLWAPI.dll", "void* SHOpenRegStream2A(void*, char*, char*, dword)")
# 呼び出し: SHOpenRegStream2A(hkey, pszSubkey, pszValue, grfMode)
# hkey : HKEY -> "void*"
# pszSubkey : LPCSTR optional -> "char*"
# pszValue : LPCSTR optional -> "char*"
# grfMode : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。