ホーム › System.WindowsProgramming › RegInstallW
RegInstallW
関数INFのレジストリセクションをインストールする(Unicode版)。
シグネチャ
// ADVPACK.dll (Unicode / -W)
#include <windows.h>
HRESULT RegInstallW(
HMODULE hmod,
LPCWSTR pszSection,
const STRTABLEW* pstTable
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hmod | HMODULE | in | INFスクリプトや文字列置換を含むモジュールのハンドル。 |
| pszSection | LPCWSTR | in | INF内で実行するセクション名を指す。 |
| pstTable | STRTABLEW* | in | 文字列置換の対応表を保持するSTRTABLEW構造体へのポインタ。NULL可。 |
戻り値の型: HRESULT
各言語での呼び出し定義
// ADVPACK.dll (Unicode / -W)
#include <windows.h>
HRESULT RegInstallW(
HMODULE hmod,
LPCWSTR pszSection,
const STRTABLEW* pstTable
);[DllImport("ADVPACK.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern int RegInstallW(
IntPtr hmod, // HMODULE
[MarshalAs(UnmanagedType.LPWStr)] string pszSection, // LPCWSTR
IntPtr pstTable // STRTABLEW*
);<DllImport("ADVPACK.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function RegInstallW(
hmod As IntPtr, ' HMODULE
<MarshalAs(UnmanagedType.LPWStr)> pszSection As String, ' LPCWSTR
pstTable As IntPtr ' STRTABLEW*
) As Integer
End Function' hmod : HMODULE
' pszSection : LPCWSTR
' pstTable : STRTABLEW*
Declare PtrSafe Function RegInstallW Lib "advpack" ( _
ByVal hmod As LongPtr, _
ByVal pszSection As LongPtr, _
ByVal pstTable 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
RegInstallW = ctypes.windll.advpack.RegInstallW
RegInstallW.restype = ctypes.c_int
RegInstallW.argtypes = [
wintypes.HANDLE, # hmod : HMODULE
wintypes.LPCWSTR, # pszSection : LPCWSTR
ctypes.c_void_p, # pstTable : STRTABLEW*
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('ADVPACK.dll')
RegInstallW = Fiddle::Function.new(
lib['RegInstallW'],
[
Fiddle::TYPE_VOIDP, # hmod : HMODULE
Fiddle::TYPE_VOIDP, # pszSection : LPCWSTR
Fiddle::TYPE_VOIDP, # pstTable : STRTABLEW*
],
Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "advpack")]
extern "system" {
fn RegInstallW(
hmod: *mut core::ffi::c_void, // HMODULE
pszSection: *const u16, // LPCWSTR
pstTable: *const STRTABLEW // STRTABLEW*
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("ADVPACK.dll", CharSet = CharSet.Unicode)]
public static extern int RegInstallW(IntPtr hmod, [MarshalAs(UnmanagedType.LPWStr)] string pszSection, IntPtr pstTable);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ADVPACK_RegInstallW' -Namespace Win32 -PassThru
# $api::RegInstallW(hmod, pszSection, pstTable)#uselib "ADVPACK.dll"
#func global RegInstallW "RegInstallW" wptr, wptr, wptr
; RegInstallW hmod, pszSection, varptr(pstTable) ; 戻り値は stat
; hmod : HMODULE -> "wptr"
; pszSection : LPCWSTR -> "wptr"
; pstTable : STRTABLEW* -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "ADVPACK.dll" #cfunc global RegInstallW "RegInstallW" sptr, wstr, var ; res = RegInstallW(hmod, pszSection, pstTable) ; hmod : HMODULE -> "sptr" ; pszSection : LPCWSTR -> "wstr" ; pstTable : STRTABLEW* -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "ADVPACK.dll" #cfunc global RegInstallW "RegInstallW" sptr, wstr, sptr ; res = RegInstallW(hmod, pszSection, varptr(pstTable)) ; hmod : HMODULE -> "sptr" ; pszSection : LPCWSTR -> "wstr" ; pstTable : STRTABLEW* -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; HRESULT RegInstallW(HMODULE hmod, LPCWSTR pszSection, STRTABLEW* pstTable) #uselib "ADVPACK.dll" #cfunc global RegInstallW "RegInstallW" intptr, wstr, var ; res = RegInstallW(hmod, pszSection, pstTable) ; hmod : HMODULE -> "intptr" ; pszSection : LPCWSTR -> "wstr" ; pstTable : STRTABLEW* -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; HRESULT RegInstallW(HMODULE hmod, LPCWSTR pszSection, STRTABLEW* pstTable) #uselib "ADVPACK.dll" #cfunc global RegInstallW "RegInstallW" intptr, wstr, intptr ; res = RegInstallW(hmod, pszSection, varptr(pstTable)) ; hmod : HMODULE -> "intptr" ; pszSection : LPCWSTR -> "wstr" ; pstTable : STRTABLEW* -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
advpack = windows.NewLazySystemDLL("ADVPACK.dll")
procRegInstallW = advpack.NewProc("RegInstallW")
)
// hmod (HMODULE), pszSection (LPCWSTR), pstTable (STRTABLEW*)
r1, _, err := procRegInstallW.Call(
uintptr(hmod),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszSection))),
uintptr(pstTable),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HRESULTfunction RegInstallW(
hmod: THandle; // HMODULE
pszSection: PWideChar; // LPCWSTR
pstTable: Pointer // STRTABLEW*
): Integer; stdcall;
external 'ADVPACK.dll' name 'RegInstallW';result := DllCall("ADVPACK\RegInstallW"
, "Ptr", hmod ; HMODULE
, "WStr", pszSection ; LPCWSTR
, "Ptr", pstTable ; STRTABLEW*
, "Int") ; return: HRESULT●RegInstallW(hmod, pszSection, pstTable) = DLL("ADVPACK.dll", "int RegInstallW(void*, char*, void*)")
# 呼び出し: RegInstallW(hmod, pszSection, pstTable)
# hmod : HMODULE -> "void*"
# pszSection : LPCWSTR -> "char*"
# pstTable : STRTABLEW* -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。const std = @import("std");
extern "advpack" fn RegInstallW(
hmod: ?*anyopaque, // HMODULE
pszSection: [*c]const u16, // LPCWSTR
pstTable: [*c]STRTABLEW // STRTABLEW*
) callconv(std.os.windows.WINAPI) i32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。proc RegInstallW(
hmod: pointer, # HMODULE
pszSection: WideCString, # LPCWSTR
pstTable: ptr STRTABLEW # STRTABLEW*
): int32 {.importc: "RegInstallW", stdcall, dynlib: "ADVPACK.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。pragma(lib, "advpack");
extern(Windows)
int RegInstallW(
void* hmod, // HMODULE
const(wchar)* pszSection, // LPCWSTR
STRTABLEW* pstTable // STRTABLEW*
);ccall((:RegInstallW, "ADVPACK.dll"), stdcall, Int32,
(Ptr{Cvoid}, Cwstring, Ptr{STRTABLEW}),
hmod, pszSection, pstTable)
# hmod : HMODULE -> Ptr{Cvoid}
# pszSection : LPCWSTR -> Cwstring
# pstTable : STRTABLEW* -> Ptr{STRTABLEW}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。local ffi = require("ffi")
ffi.cdef[[
int32_t RegInstallW(
void* hmod,
const uint16_t* pszSection,
void* pstTable);
]]
local advpack = ffi.load("advpack")
-- advpack.RegInstallW(hmod, pszSection, pstTable)
-- hmod : HMODULE
-- pszSection : LPCWSTR
-- pstTable : STRTABLEW*
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
-- Unicode(-W): uint16_t* には UTF-16LE のバッファ(ffi.new("uint16_t[?]", ...))を渡す。const koffi = require('koffi');
const lib = koffi.load('ADVPACK.dll');
const RegInstallW = lib.func('__stdcall', 'RegInstallW', 'int32_t', ['void *', 'str16', 'void *']);
// RegInstallW(hmod, pszSection, pstTable)
// hmod : HMODULE -> 'void *'
// pszSection : LPCWSTR -> 'str16'
// pstTable : STRTABLEW* -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("ADVPACK.dll", {
RegInstallW: { parameters: ["pointer", "buffer", "pointer"], result: "i32" },
});
// lib.symbols.RegInstallW(hmod, pszSection, pstTable)
// hmod : HMODULE -> "pointer"
// pszSection : LPCWSTR -> "buffer"
// pstTable : STRTABLEW* -> "pointer"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t RegInstallW(
void* hmod,
const uint16_t* pszSection,
void* pstTable);
C, "ADVPACK.dll");
// $ffi->RegInstallW(hmod, pszSection, pstTable);
// hmod : HMODULE
// pszSection : LPCWSTR
// pstTable : STRTABLEW*
// 構造体/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 Advpack extends StdCallLibrary {
Advpack INSTANCE = Native.load("advpack", Advpack.class, W32APIOptions.UNICODE_OPTIONS);
int RegInstallW(
Pointer hmod, // HMODULE
WString pszSection, // LPCWSTR
Pointer pstTable // STRTABLEW*
);
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。@[Link("advpack")]
lib LibADVPACK
fun RegInstallW = RegInstallW(
hmod : Void*, # HMODULE
pszSection : UInt16*, # LPCWSTR
pstTable : STRTABLEW* # STRTABLEW*
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef RegInstallWNative = Int32 Function(Pointer<Void>, Pointer<Utf16>, Pointer<Void>);
typedef RegInstallWDart = int Function(Pointer<Void>, Pointer<Utf16>, Pointer<Void>);
final RegInstallW = DynamicLibrary.open('ADVPACK.dll')
.lookupFunction<RegInstallWNative, RegInstallWDart>('RegInstallW');
// hmod : HMODULE -> Pointer<Void>
// pszSection : LPCWSTR -> Pointer<Utf16>
// pstTable : STRTABLEW* -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function RegInstallW(
hmod: THandle; // HMODULE
pszSection: PWideChar; // LPCWSTR
pstTable: Pointer // STRTABLEW*
): Integer; stdcall;
external 'ADVPACK.dll' name 'RegInstallW';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "RegInstallW"
c_RegInstallW :: Ptr () -> CWString -> Ptr () -> IO Int32
-- hmod : HMODULE -> Ptr ()
-- pszSection : LPCWSTR -> CWString
-- pstTable : STRTABLEW* -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let reginstallw =
foreign "RegInstallW"
((ptr void) @-> (ptr uint16_t) @-> (ptr void) @-> returning int32_t)
(* hmod : HMODULE -> (ptr void) *)
(* pszSection : LPCWSTR -> (ptr uint16_t) *)
(* pstTable : STRTABLEW* -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library advpack (t "ADVPACK.dll"))
(cffi:use-foreign-library advpack)
(cffi:defcfun ("RegInstallW" reg-install-w :convention :stdcall) :int32
(hmod :pointer) ; HMODULE
(psz-section (:string :encoding :utf-16le)) ; LPCWSTR
(pst-table :pointer)) ; STRTABLEW*
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $RegInstallW = Win32::API::More->new('ADVPACK',
'int RegInstallW(HANDLE hmod, LPCWSTR pszSection, LPVOID pstTable)');
# my $ret = $RegInstallW->Call($hmod, $pszSection, $pstTable);
# hmod : HMODULE -> HANDLE
# pszSection : LPCWSTR -> LPCWSTR
# pstTable : STRTABLEW* -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。関連項目
文字セット違い
- f RegInstallA (ANSI版) — INFのレジストリセクションをインストールする(ANSI版)。
使用する型