OpenRegStream
関数レジストリ値を読み書きするIStreamを開く。
シグネチャ
// SHELL32.dll
#include <windows.h>
IStream* OpenRegStream(
HKEY hkey,
LPCWSTR pszSubkey, // optional
LPCWSTR pszValue, // optional
DWORD grfMode
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hkey | HKEY | in | 現在開いているキーへのハンドル。 |
| pszSubkey | LPCWSTR | inoptional | サブキーの名前を指定する、null で終端された Unicode 文字列。 |
| pszValue | LPCWSTR | inoptional | アクセスする値を指定する、null で終端された Unicode 文字列。 |
| grfMode | DWORD | in | ストリームに対するアクセスの種類。次のいずれかの値を指定できます。 STGM_READ読み取り用にストリームを開きます。 STGM_WRITE書き込み用にストリームを開きます。 STGM_READWRITE読み取りおよび書き込み用にストリームを開きます。 |
戻り値の型: IStream*
公式ドキュメント
OpenRegStream は変更されるか、利用できなくなる可能性があります。代わりに SHOpenRegStream2 または SHOpenRegStream を使用してください。
戻り値
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// SHELL32.dll
#include <windows.h>
IStream* OpenRegStream(
HKEY hkey,
LPCWSTR pszSubkey, // optional
LPCWSTR pszValue, // optional
DWORD grfMode
);[DllImport("SHELL32.dll", ExactSpelling = true)]
static extern IntPtr OpenRegStream(
IntPtr hkey, // HKEY
[MarshalAs(UnmanagedType.LPWStr)] string pszSubkey, // LPCWSTR optional
[MarshalAs(UnmanagedType.LPWStr)] string pszValue, // LPCWSTR optional
uint grfMode // DWORD
);<DllImport("SHELL32.dll", ExactSpelling:=True)>
Public Shared Function OpenRegStream(
hkey As IntPtr, ' HKEY
<MarshalAs(UnmanagedType.LPWStr)> pszSubkey As String, ' LPCWSTR optional
<MarshalAs(UnmanagedType.LPWStr)> pszValue As String, ' LPCWSTR optional
grfMode As UInteger ' DWORD
) As IntPtr
End Function' hkey : HKEY
' pszSubkey : LPCWSTR optional
' pszValue : LPCWSTR optional
' grfMode : DWORD
Declare PtrSafe Function OpenRegStream Lib "shell32" ( _
ByVal hkey As LongPtr, _
ByVal pszSubkey As LongPtr, _
ByVal pszValue As LongPtr, _
ByVal grfMode As Long) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
OpenRegStream = ctypes.windll.shell32.OpenRegStream
OpenRegStream.restype = ctypes.c_void_p
OpenRegStream.argtypes = [
wintypes.HANDLE, # hkey : HKEY
wintypes.LPCWSTR, # pszSubkey : LPCWSTR optional
wintypes.LPCWSTR, # pszValue : LPCWSTR optional
wintypes.DWORD, # grfMode : DWORD
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('SHELL32.dll')
OpenRegStream = Fiddle::Function.new(
lib['OpenRegStream'],
[
Fiddle::TYPE_VOIDP, # hkey : HKEY
Fiddle::TYPE_VOIDP, # pszSubkey : LPCWSTR optional
Fiddle::TYPE_VOIDP, # pszValue : LPCWSTR optional
-Fiddle::TYPE_INT, # grfMode : DWORD
],
Fiddle::TYPE_VOIDP)#[link(name = "shell32")]
extern "system" {
fn OpenRegStream(
hkey: *mut core::ffi::c_void, // HKEY
pszSubkey: *const u16, // LPCWSTR optional
pszValue: *const u16, // LPCWSTR optional
grfMode: u32 // DWORD
) -> *mut core::ffi::c_void;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("SHELL32.dll")]
public static extern IntPtr OpenRegStream(IntPtr hkey, [MarshalAs(UnmanagedType.LPWStr)] string pszSubkey, [MarshalAs(UnmanagedType.LPWStr)] string pszValue, uint grfMode);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SHELL32_OpenRegStream' -Namespace Win32 -PassThru
# $api::OpenRegStream(hkey, pszSubkey, pszValue, grfMode)#uselib "SHELL32.dll"
#func global OpenRegStream "OpenRegStream" sptr, sptr, sptr, sptr
; OpenRegStream hkey, pszSubkey, pszValue, grfMode ; 戻り値は stat
; hkey : HKEY -> "sptr"
; pszSubkey : LPCWSTR optional -> "sptr"
; pszValue : LPCWSTR optional -> "sptr"
; grfMode : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "SHELL32.dll"
#cfunc global OpenRegStream "OpenRegStream" sptr, wstr, wstr, int
; res = OpenRegStream(hkey, pszSubkey, pszValue, grfMode)
; hkey : HKEY -> "sptr"
; pszSubkey : LPCWSTR optional -> "wstr"
; pszValue : LPCWSTR optional -> "wstr"
; grfMode : DWORD -> "int"; IStream* OpenRegStream(HKEY hkey, LPCWSTR pszSubkey, LPCWSTR pszValue, DWORD grfMode)
#uselib "SHELL32.dll"
#cfunc global OpenRegStream "OpenRegStream" intptr, wstr, wstr, int
; res = OpenRegStream(hkey, pszSubkey, pszValue, grfMode)
; hkey : HKEY -> "intptr"
; pszSubkey : LPCWSTR optional -> "wstr"
; pszValue : LPCWSTR optional -> "wstr"
; grfMode : DWORD -> "int"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
shell32 = windows.NewLazySystemDLL("SHELL32.dll")
procOpenRegStream = shell32.NewProc("OpenRegStream")
)
// hkey (HKEY), pszSubkey (LPCWSTR optional), pszValue (LPCWSTR optional), grfMode (DWORD)
r1, _, err := procOpenRegStream.Call(
uintptr(hkey),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszSubkey))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszValue))),
uintptr(grfMode),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // IStream*function OpenRegStream(
hkey: THandle; // HKEY
pszSubkey: PWideChar; // LPCWSTR optional
pszValue: PWideChar; // LPCWSTR optional
grfMode: DWORD // DWORD
): Pointer; stdcall;
external 'SHELL32.dll' name 'OpenRegStream';result := DllCall("SHELL32\OpenRegStream"
, "Ptr", hkey ; HKEY
, "WStr", pszSubkey ; LPCWSTR optional
, "WStr", pszValue ; LPCWSTR optional
, "UInt", grfMode ; DWORD
, "Ptr") ; return: IStream*●OpenRegStream(hkey, pszSubkey, pszValue, grfMode) = DLL("SHELL32.dll", "void* OpenRegStream(void*, char*, char*, dword)")
# 呼び出し: OpenRegStream(hkey, pszSubkey, pszValue, grfMode)
# hkey : HKEY -> "void*"
# pszSubkey : LPCWSTR optional -> "char*"
# pszValue : LPCWSTR optional -> "char*"
# grfMode : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "shell32" fn OpenRegStream(
hkey: ?*anyopaque, // HKEY
pszSubkey: [*c]const u16, // LPCWSTR optional
pszValue: [*c]const u16, // LPCWSTR optional
grfMode: u32 // DWORD
) callconv(std.os.windows.WINAPI) ?*anyopaque;proc OpenRegStream(
hkey: pointer, # HKEY
pszSubkey: WideCString, # LPCWSTR optional
pszValue: WideCString, # LPCWSTR optional
grfMode: uint32 # DWORD
): pointer {.importc: "OpenRegStream", stdcall, dynlib: "SHELL32.dll".}pragma(lib, "shell32");
extern(Windows)
void* OpenRegStream(
void* hkey, // HKEY
const(wchar)* pszSubkey, // LPCWSTR optional
const(wchar)* pszValue, // LPCWSTR optional
uint grfMode // DWORD
);ccall((:OpenRegStream, "SHELL32.dll"), stdcall, Ptr{Cvoid},
(Ptr{Cvoid}, Cwstring, Cwstring, UInt32),
hkey, pszSubkey, pszValue, grfMode)
# hkey : HKEY -> Ptr{Cvoid}
# pszSubkey : LPCWSTR optional -> Cwstring
# pszValue : LPCWSTR optional -> Cwstring
# grfMode : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
void* OpenRegStream(
void* hkey,
const uint16_t* pszSubkey,
const uint16_t* pszValue,
uint32_t grfMode);
]]
local shell32 = ffi.load("shell32")
-- shell32.OpenRegStream(hkey, pszSubkey, pszValue, grfMode)
-- hkey : HKEY
-- pszSubkey : LPCWSTR optional
-- pszValue : LPCWSTR optional
-- grfMode : DWORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('SHELL32.dll');
const OpenRegStream = lib.func('__stdcall', 'OpenRegStream', 'void *', ['void *', 'str16', 'str16', 'uint32_t']);
// OpenRegStream(hkey, pszSubkey, pszValue, grfMode)
// hkey : HKEY -> 'void *'
// pszSubkey : LPCWSTR optional -> 'str16'
// pszValue : LPCWSTR optional -> 'str16'
// grfMode : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("SHELL32.dll", {
OpenRegStream: { parameters: ["pointer", "buffer", "buffer", "u32"], result: "pointer" },
});
// lib.symbols.OpenRegStream(hkey, pszSubkey, pszValue, grfMode)
// hkey : HKEY -> "pointer"
// pszSubkey : LPCWSTR optional -> "buffer"
// pszValue : LPCWSTR optional -> "buffer"
// grfMode : DWORD -> "u32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
void* OpenRegStream(
void* hkey,
const uint16_t* pszSubkey,
const uint16_t* pszValue,
uint32_t grfMode);
C, "SHELL32.dll");
// $ffi->OpenRegStream(hkey, pszSubkey, pszValue, grfMode);
// hkey : HKEY
// pszSubkey : LPCWSTR optional
// pszValue : LPCWSTR optional
// grfMode : DWORD
// 構造体/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 Shell32 extends StdCallLibrary {
Shell32 INSTANCE = Native.load("shell32", Shell32.class);
Pointer OpenRegStream(
Pointer hkey, // HKEY
WString pszSubkey, // LPCWSTR optional
WString pszValue, // LPCWSTR optional
int grfMode // DWORD
);
}@[Link("shell32")]
lib LibSHELL32
fun OpenRegStream = OpenRegStream(
hkey : Void*, # HKEY
pszSubkey : UInt16*, # LPCWSTR optional
pszValue : UInt16*, # LPCWSTR optional
grfMode : UInt32 # DWORD
) : Void*
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef OpenRegStreamNative = Pointer<Void> Function(Pointer<Void>, Pointer<Utf16>, Pointer<Utf16>, Uint32);
typedef OpenRegStreamDart = Pointer<Void> Function(Pointer<Void>, Pointer<Utf16>, Pointer<Utf16>, int);
final OpenRegStream = DynamicLibrary.open('SHELL32.dll')
.lookupFunction<OpenRegStreamNative, OpenRegStreamDart>('OpenRegStream');
// hkey : HKEY -> Pointer<Void>
// pszSubkey : LPCWSTR optional -> Pointer<Utf16>
// pszValue : LPCWSTR optional -> Pointer<Utf16>
// grfMode : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function OpenRegStream(
hkey: THandle; // HKEY
pszSubkey: PWideChar; // LPCWSTR optional
pszValue: PWideChar; // LPCWSTR optional
grfMode: DWORD // DWORD
): Pointer; stdcall;
external 'SHELL32.dll' name 'OpenRegStream';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "OpenRegStream"
c_OpenRegStream :: Ptr () -> CWString -> CWString -> Word32 -> IO (Ptr ())
-- hkey : HKEY -> Ptr ()
-- pszSubkey : LPCWSTR optional -> CWString
-- pszValue : LPCWSTR optional -> CWString
-- grfMode : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let openregstream =
foreign "OpenRegStream"
((ptr void) @-> (ptr uint16_t) @-> (ptr uint16_t) @-> uint32_t @-> returning (ptr void))
(* hkey : HKEY -> (ptr void) *)
(* pszSubkey : LPCWSTR optional -> (ptr uint16_t) *)
(* pszValue : LPCWSTR optional -> (ptr uint16_t) *)
(* grfMode : DWORD -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library shell32 (t "SHELL32.dll"))
(cffi:use-foreign-library shell32)
(cffi:defcfun ("OpenRegStream" open-reg-stream :convention :stdcall) :pointer
(hkey :pointer) ; HKEY
(psz-subkey (:string :encoding :utf-16le)) ; LPCWSTR optional
(psz-value (:string :encoding :utf-16le)) ; LPCWSTR optional
(grf-mode :uint32)) ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $OpenRegStream = Win32::API::More->new('SHELL32',
'LPVOID OpenRegStream(HANDLE hkey, LPCWSTR pszSubkey, LPCWSTR pszValue, DWORD grfMode)');
# my $ret = $OpenRegStream->Call($hkey, $pszSubkey, $pszValue, $grfMode);
# hkey : HKEY -> HANDLE
# pszSubkey : LPCWSTR optional -> LPCWSTR
# pszValue : LPCWSTR optional -> LPCWSTR
# grfMode : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
使用する型