Win32 API 日本語リファレンス
ホームSystem.WindowsProgramming › RegInstallA

RegInstallA

関数
INFのレジストリセクションをインストールする(ANSI版)。
DLLADVPACK.dll文字セットANSI (-A)呼出規約winapi対応OSWindows 10 以降

シグネチャ

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

HRESULT RegInstallA(
    HMODULE hmod,
    LPCSTR pszSection,
    const STRTABLEA* pstTable
);

パラメーター

名前方向説明
hmodHMODULEinINFスクリプトや文字列置換を含むモジュールのハンドル。
pszSectionLPCSTRinINF内で実行するセクション名を指す。
pstTableSTRTABLEA*in文字列置換の対応表を保持するSTRTABLEA構造体へのポインタ。NULL可。

戻り値の型: HRESULT

各言語での呼び出し定義

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

HRESULT RegInstallA(
    HMODULE hmod,
    LPCSTR pszSection,
    const STRTABLEA* pstTable
);
[DllImport("ADVPACK.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern int RegInstallA(
    IntPtr hmod,   // HMODULE
    [MarshalAs(UnmanagedType.LPStr)] string pszSection,   // LPCSTR
    IntPtr pstTable   // STRTABLEA*
);
<DllImport("ADVPACK.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function RegInstallA(
    hmod As IntPtr,   ' HMODULE
    <MarshalAs(UnmanagedType.LPStr)> pszSection As String,   ' LPCSTR
    pstTable As IntPtr   ' STRTABLEA*
) As Integer
End Function
' hmod : HMODULE
' pszSection : LPCSTR
' pstTable : STRTABLEA*
Declare PtrSafe Function RegInstallA Lib "advpack" ( _
    ByVal hmod As LongPtr, _
    ByVal pszSection As String, _
    ByVal pstTable As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

RegInstallA = ctypes.windll.advpack.RegInstallA
RegInstallA.restype = ctypes.c_int
RegInstallA.argtypes = [
    wintypes.HANDLE,  # hmod : HMODULE
    wintypes.LPCSTR,  # pszSection : LPCSTR
    ctypes.c_void_p,  # pstTable : STRTABLEA*
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('ADVPACK.dll')
RegInstallA = Fiddle::Function.new(
  lib['RegInstallA'],
  [
    Fiddle::TYPE_VOIDP,  # hmod : HMODULE
    Fiddle::TYPE_VOIDP,  # pszSection : LPCSTR
    Fiddle::TYPE_VOIDP,  # pstTable : STRTABLEA*
  ],
  Fiddle::TYPE_INT)
#[link(name = "advpack")]
extern "system" {
    fn RegInstallA(
        hmod: *mut core::ffi::c_void,  // HMODULE
        pszSection: *const u8,  // LPCSTR
        pstTable: *const STRTABLEA  // STRTABLEA*
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("ADVPACK.dll", CharSet = CharSet.Ansi)]
public static extern int RegInstallA(IntPtr hmod, [MarshalAs(UnmanagedType.LPStr)] string pszSection, IntPtr pstTable);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ADVPACK_RegInstallA' -Namespace Win32 -PassThru
# $api::RegInstallA(hmod, pszSection, pstTable)
#uselib "ADVPACK.dll"
#func global RegInstallA "RegInstallA" sptr, sptr, sptr
; RegInstallA hmod, pszSection, varptr(pstTable)   ; 戻り値は stat
; hmod : HMODULE -> "sptr"
; pszSection : LPCSTR -> "sptr"
; pstTable : STRTABLEA* -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "ADVPACK.dll"
#cfunc global RegInstallA "RegInstallA" sptr, str, var
; res = RegInstallA(hmod, pszSection, pstTable)
; hmod : HMODULE -> "sptr"
; pszSection : LPCSTR -> "str"
; pstTable : STRTABLEA* -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; HRESULT RegInstallA(HMODULE hmod, LPCSTR pszSection, STRTABLEA* pstTable)
#uselib "ADVPACK.dll"
#cfunc global RegInstallA "RegInstallA" intptr, str, var
; res = RegInstallA(hmod, pszSection, pstTable)
; hmod : HMODULE -> "intptr"
; pszSection : LPCSTR -> "str"
; pstTable : STRTABLEA* -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	advpack = windows.NewLazySystemDLL("ADVPACK.dll")
	procRegInstallA = advpack.NewProc("RegInstallA")
)

// hmod (HMODULE), pszSection (LPCSTR), pstTable (STRTABLEA*)
r1, _, err := procRegInstallA.Call(
	uintptr(hmod),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(pszSection))),
	uintptr(pstTable),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function RegInstallA(
  hmod: THandle;   // HMODULE
  pszSection: PAnsiChar;   // LPCSTR
  pstTable: Pointer   // STRTABLEA*
): Integer; stdcall;
  external 'ADVPACK.dll' name 'RegInstallA';
result := DllCall("ADVPACK\RegInstallA"
    , "Ptr", hmod   ; HMODULE
    , "AStr", pszSection   ; LPCSTR
    , "Ptr", pstTable   ; STRTABLEA*
    , "Int")   ; return: HRESULT
●RegInstallA(hmod, pszSection, pstTable) = DLL("ADVPACK.dll", "int RegInstallA(void*, char*, void*)")
# 呼び出し: RegInstallA(hmod, pszSection, pstTable)
# hmod : HMODULE -> "void*"
# pszSection : LPCSTR -> "char*"
# pstTable : STRTABLEA* -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "advpack" fn RegInstallA(
    hmod: ?*anyopaque, // HMODULE
    pszSection: [*c]const u8, // LPCSTR
    pstTable: [*c]STRTABLEA // STRTABLEA*
) callconv(std.os.windows.WINAPI) i32;
proc RegInstallA(
    hmod: pointer,  # HMODULE
    pszSection: cstring,  # LPCSTR
    pstTable: ptr STRTABLEA  # STRTABLEA*
): int32 {.importc: "RegInstallA", stdcall, dynlib: "ADVPACK.dll".}
pragma(lib, "advpack");
extern(Windows)
int RegInstallA(
    void* hmod,   // HMODULE
    const(char)* pszSection,   // LPCSTR
    STRTABLEA* pstTable   // STRTABLEA*
);
ccall((:RegInstallA, "ADVPACK.dll"), stdcall, Int32,
      (Ptr{Cvoid}, Cstring, Ptr{STRTABLEA}),
      hmod, pszSection, pstTable)
# hmod : HMODULE -> Ptr{Cvoid}
# pszSection : LPCSTR -> Cstring
# pstTable : STRTABLEA* -> Ptr{STRTABLEA}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t RegInstallA(
    void* hmod,
    const char* pszSection,
    void* pstTable);
]]
local advpack = ffi.load("advpack")
-- advpack.RegInstallA(hmod, pszSection, pstTable)
-- hmod : HMODULE
-- pszSection : LPCSTR
-- pstTable : STRTABLEA*
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('ADVPACK.dll');
const RegInstallA = lib.func('__stdcall', 'RegInstallA', 'int32_t', ['void *', 'str', 'void *']);
// RegInstallA(hmod, pszSection, pstTable)
// hmod : HMODULE -> 'void *'
// pszSection : LPCSTR -> 'str'
// pstTable : STRTABLEA* -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("ADVPACK.dll", {
  RegInstallA: { parameters: ["pointer", "buffer", "pointer"], result: "i32" },
});
// lib.symbols.RegInstallA(hmod, pszSection, pstTable)
// hmod : HMODULE -> "pointer"
// pszSection : LPCSTR -> "buffer"
// pstTable : STRTABLEA* -> "pointer"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t RegInstallA(
    void* hmod,
    const char* pszSection,
    void* pstTable);
C, "ADVPACK.dll");
// $ffi->RegInstallA(hmod, pszSection, pstTable);
// hmod : HMODULE
// pszSection : LPCSTR
// pstTable : STRTABLEA*
// 構造体/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.ASCII_OPTIONS);
    int RegInstallA(
        Pointer hmod,   // HMODULE
        String pszSection,   // LPCSTR
        Pointer pstTable   // STRTABLEA*
    );
}
@[Link("advpack")]
lib LibADVPACK
  fun RegInstallA = RegInstallA(
    hmod : Void*,   # HMODULE
    pszSection : UInt8*,   # LPCSTR
    pstTable : STRTABLEA*   # STRTABLEA*
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef RegInstallANative = Int32 Function(Pointer<Void>, Pointer<Utf8>, Pointer<Void>);
typedef RegInstallADart = int Function(Pointer<Void>, Pointer<Utf8>, Pointer<Void>);
final RegInstallA = DynamicLibrary.open('ADVPACK.dll')
    .lookupFunction<RegInstallANative, RegInstallADart>('RegInstallA');
// hmod : HMODULE -> Pointer<Void>
// pszSection : LPCSTR -> Pointer<Utf8>
// pstTable : STRTABLEA* -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function RegInstallA(
  hmod: THandle;   // HMODULE
  pszSection: PAnsiChar;   // LPCSTR
  pstTable: Pointer   // STRTABLEA*
): Integer; stdcall;
  external 'ADVPACK.dll' name 'RegInstallA';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "RegInstallA"
  c_RegInstallA :: Ptr () -> CString -> Ptr () -> IO Int32
-- hmod : HMODULE -> Ptr ()
-- pszSection : LPCSTR -> CString
-- pstTable : STRTABLEA* -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let reginstalla =
  foreign "RegInstallA"
    ((ptr void) @-> string @-> (ptr void) @-> returning int32_t)
(* hmod : HMODULE -> (ptr void) *)
(* pszSection : LPCSTR -> string *)
(* pstTable : STRTABLEA* -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library advpack (t "ADVPACK.dll"))
(cffi:use-foreign-library advpack)

(cffi:defcfun ("RegInstallA" reg-install-a :convention :stdcall) :int32
  (hmod :pointer)   ; HMODULE
  (psz-section :string)   ; LPCSTR
  (pst-table :pointer))   ; STRTABLEA*
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $RegInstallA = Win32::API::More->new('ADVPACK',
    'int RegInstallA(HANDLE hmod, LPCSTR pszSection, LPVOID pstTable)');
# my $ret = $RegInstallA->Call($hmod, $pszSection, $pstTable);
# hmod : HMODULE -> HANDLE
# pszSection : LPCSTR -> LPCSTR
# pstTable : STRTABLEA* -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

文字セット違い
使用する型