ホーム › Devices.DeviceAndDriverInstallation › InstallHinfSectionA
InstallHinfSectionA
関数rundll32経由でINFセクションを実行するインストールエントリ。
シグネチャ
// SETUPAPI.dll (ANSI / -A)
#include <windows.h>
void InstallHinfSectionA(
HWND Window,
HINSTANCE ModuleHandle,
LPCSTR CommandLine,
INT ShowCommand
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| Window | HWND | in | rundll32経由で渡される親ウィンドウハンドル。 |
| ModuleHandle | HINSTANCE | in | 呼び出し元モジュールのインスタンスハンドル。 |
| CommandLine | LPCSTR | in | セクション名やINFパスを含むコマンドライン文字列(ANSI)。 |
| ShowCommand | INT | in | ウィンドウ表示方法を示すSW_*値。 |
戻り値の型: void
各言語での呼び出し定義
// SETUPAPI.dll (ANSI / -A)
#include <windows.h>
void InstallHinfSectionA(
HWND Window,
HINSTANCE ModuleHandle,
LPCSTR CommandLine,
INT ShowCommand
);[DllImport("SETUPAPI.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern void InstallHinfSectionA(
IntPtr Window, // HWND
IntPtr ModuleHandle, // HINSTANCE
[MarshalAs(UnmanagedType.LPStr)] string CommandLine, // LPCSTR
int ShowCommand // INT
);<DllImport("SETUPAPI.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Sub InstallHinfSectionA(
Window As IntPtr, ' HWND
ModuleHandle As IntPtr, ' HINSTANCE
<MarshalAs(UnmanagedType.LPStr)> CommandLine As String, ' LPCSTR
ShowCommand As Integer ' INT
)
End Sub' Window : HWND
' ModuleHandle : HINSTANCE
' CommandLine : LPCSTR
' ShowCommand : INT
Declare PtrSafe Sub InstallHinfSectionA Lib "setupapi" ( _
ByVal Window As LongPtr, _
ByVal ModuleHandle As LongPtr, _
ByVal CommandLine As String, _
ByVal ShowCommand As Long)
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
InstallHinfSectionA = ctypes.windll.setupapi.InstallHinfSectionA
InstallHinfSectionA.restype = None
InstallHinfSectionA.argtypes = [
wintypes.HANDLE, # Window : HWND
wintypes.HANDLE, # ModuleHandle : HINSTANCE
wintypes.LPCSTR, # CommandLine : LPCSTR
ctypes.c_int, # ShowCommand : INT
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('SETUPAPI.dll')
InstallHinfSectionA = Fiddle::Function.new(
lib['InstallHinfSectionA'],
[
Fiddle::TYPE_VOIDP, # Window : HWND
Fiddle::TYPE_VOIDP, # ModuleHandle : HINSTANCE
Fiddle::TYPE_VOIDP, # CommandLine : LPCSTR
Fiddle::TYPE_INT, # ShowCommand : INT
],
Fiddle::TYPE_VOID)#[link(name = "setupapi")]
extern "system" {
fn InstallHinfSectionA(
Window: *mut core::ffi::c_void, // HWND
ModuleHandle: *mut core::ffi::c_void, // HINSTANCE
CommandLine: *const u8, // LPCSTR
ShowCommand: i32 // INT
);
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("SETUPAPI.dll", CharSet = CharSet.Ansi)]
public static extern void InstallHinfSectionA(IntPtr Window, IntPtr ModuleHandle, [MarshalAs(UnmanagedType.LPStr)] string CommandLine, int ShowCommand);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SETUPAPI_InstallHinfSectionA' -Namespace Win32 -PassThru
# $api::InstallHinfSectionA(Window, ModuleHandle, CommandLine, ShowCommand)#uselib "SETUPAPI.dll"
#func global InstallHinfSectionA "InstallHinfSectionA" sptr, sptr, sptr, sptr
; InstallHinfSectionA Window, ModuleHandle, CommandLine, ShowCommand
; Window : HWND -> "sptr"
; ModuleHandle : HINSTANCE -> "sptr"
; CommandLine : LPCSTR -> "sptr"
; ShowCommand : INT -> "sptr"#uselib "SETUPAPI.dll"
#func global InstallHinfSectionA "InstallHinfSectionA" sptr, sptr, str, int
; InstallHinfSectionA Window, ModuleHandle, CommandLine, ShowCommand
; Window : HWND -> "sptr"
; ModuleHandle : HINSTANCE -> "sptr"
; CommandLine : LPCSTR -> "str"
; ShowCommand : INT -> "int"; void InstallHinfSectionA(HWND Window, HINSTANCE ModuleHandle, LPCSTR CommandLine, INT ShowCommand)
#uselib "SETUPAPI.dll"
#func global InstallHinfSectionA "InstallHinfSectionA" intptr, intptr, str, int
; InstallHinfSectionA Window, ModuleHandle, CommandLine, ShowCommand
; Window : HWND -> "intptr"
; ModuleHandle : HINSTANCE -> "intptr"
; CommandLine : LPCSTR -> "str"
; ShowCommand : INT -> "int"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
setupapi = windows.NewLazySystemDLL("SETUPAPI.dll")
procInstallHinfSectionA = setupapi.NewProc("InstallHinfSectionA")
)
// Window (HWND), ModuleHandle (HINSTANCE), CommandLine (LPCSTR), ShowCommand (INT)
r1, _, err := procInstallHinfSectionA.Call(
uintptr(Window),
uintptr(ModuleHandle),
uintptr(unsafe.Pointer(windows.BytePtrFromString(CommandLine))),
uintptr(ShowCommand),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // voidprocedure InstallHinfSectionA(
Window: THandle; // HWND
ModuleHandle: THandle; // HINSTANCE
CommandLine: PAnsiChar; // LPCSTR
ShowCommand: Integer // INT
); stdcall;
external 'SETUPAPI.dll' name 'InstallHinfSectionA';result := DllCall("SETUPAPI\InstallHinfSectionA"
, "Ptr", Window ; HWND
, "Ptr", ModuleHandle ; HINSTANCE
, "AStr", CommandLine ; LPCSTR
, "Int", ShowCommand ; INT
, "Int") ; return: void●InstallHinfSectionA(Window, ModuleHandle, CommandLine, ShowCommand) = DLL("SETUPAPI.dll", "int InstallHinfSectionA(void*, void*, char*, int)")
# 呼び出し: InstallHinfSectionA(Window, ModuleHandle, CommandLine, ShowCommand)
# Window : HWND -> "void*"
# ModuleHandle : HINSTANCE -> "void*"
# CommandLine : LPCSTR -> "char*"
# ShowCommand : INT -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "setupapi" fn InstallHinfSectionA(
Window: ?*anyopaque, // HWND
ModuleHandle: ?*anyopaque, // HINSTANCE
CommandLine: [*c]const u8, // LPCSTR
ShowCommand: i32 // INT
) callconv(std.os.windows.WINAPI) void;proc InstallHinfSectionA(
Window: pointer, # HWND
ModuleHandle: pointer, # HINSTANCE
CommandLine: cstring, # LPCSTR
ShowCommand: int32 # INT
) {.importc: "InstallHinfSectionA", stdcall, dynlib: "SETUPAPI.dll".}pragma(lib, "setupapi");
extern(Windows)
void InstallHinfSectionA(
void* Window, // HWND
void* ModuleHandle, // HINSTANCE
const(char)* CommandLine, // LPCSTR
int ShowCommand // INT
);ccall((:InstallHinfSectionA, "SETUPAPI.dll"), stdcall, Cvoid,
(Ptr{Cvoid}, Ptr{Cvoid}, Cstring, Int32),
Window, ModuleHandle, CommandLine, ShowCommand)
# Window : HWND -> Ptr{Cvoid}
# ModuleHandle : HINSTANCE -> Ptr{Cvoid}
# CommandLine : LPCSTR -> Cstring
# ShowCommand : INT -> Int32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
void InstallHinfSectionA(
void* Window,
void* ModuleHandle,
const char* CommandLine,
int32_t ShowCommand);
]]
local setupapi = ffi.load("setupapi")
-- setupapi.InstallHinfSectionA(Window, ModuleHandle, CommandLine, ShowCommand)
-- Window : HWND
-- ModuleHandle : HINSTANCE
-- CommandLine : LPCSTR
-- ShowCommand : INT
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('SETUPAPI.dll');
const InstallHinfSectionA = lib.func('__stdcall', 'InstallHinfSectionA', 'void', ['void *', 'void *', 'str', 'int32_t']);
// InstallHinfSectionA(Window, ModuleHandle, CommandLine, ShowCommand)
// Window : HWND -> 'void *'
// ModuleHandle : HINSTANCE -> 'void *'
// CommandLine : LPCSTR -> 'str'
// ShowCommand : INT -> 'int32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("SETUPAPI.dll", {
InstallHinfSectionA: { parameters: ["pointer", "pointer", "buffer", "i32"], result: "void" },
});
// lib.symbols.InstallHinfSectionA(Window, ModuleHandle, CommandLine, ShowCommand)
// Window : HWND -> "pointer"
// ModuleHandle : HINSTANCE -> "pointer"
// CommandLine : LPCSTR -> "buffer"
// ShowCommand : INT -> "i32"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
void InstallHinfSectionA(
void* Window,
void* ModuleHandle,
const char* CommandLine,
int32_t ShowCommand);
C, "SETUPAPI.dll");
// $ffi->InstallHinfSectionA(Window, ModuleHandle, CommandLine, ShowCommand);
// Window : HWND
// ModuleHandle : HINSTANCE
// CommandLine : LPCSTR
// ShowCommand : INT
// 構造体/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 Setupapi extends StdCallLibrary {
Setupapi INSTANCE = Native.load("setupapi", Setupapi.class, W32APIOptions.ASCII_OPTIONS);
void InstallHinfSectionA(
Pointer Window, // HWND
Pointer ModuleHandle, // HINSTANCE
String CommandLine, // LPCSTR
int ShowCommand // INT
);
}@[Link("setupapi")]
lib LibSETUPAPI
fun InstallHinfSectionA = InstallHinfSectionA(
Window : Void*, # HWND
ModuleHandle : Void*, # HINSTANCE
CommandLine : UInt8*, # LPCSTR
ShowCommand : Int32 # INT
) : Void
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef InstallHinfSectionANative = Void Function(Pointer<Void>, Pointer<Void>, Pointer<Utf8>, Int32);
typedef InstallHinfSectionADart = void Function(Pointer<Void>, Pointer<Void>, Pointer<Utf8>, int);
final InstallHinfSectionA = DynamicLibrary.open('SETUPAPI.dll')
.lookupFunction<InstallHinfSectionANative, InstallHinfSectionADart>('InstallHinfSectionA');
// Window : HWND -> Pointer<Void>
// ModuleHandle : HINSTANCE -> Pointer<Void>
// CommandLine : LPCSTR -> Pointer<Utf8>
// ShowCommand : INT -> Int32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
procedure InstallHinfSectionA(
Window: THandle; // HWND
ModuleHandle: THandle; // HINSTANCE
CommandLine: PAnsiChar; // LPCSTR
ShowCommand: Integer // INT
); stdcall;
external 'SETUPAPI.dll' name 'InstallHinfSectionA';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "InstallHinfSectionA"
c_InstallHinfSectionA :: Ptr () -> Ptr () -> CString -> Int32 -> IO ()
-- Window : HWND -> Ptr ()
-- ModuleHandle : HINSTANCE -> Ptr ()
-- CommandLine : LPCSTR -> CString
-- ShowCommand : INT -> Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let installhinfsectiona =
foreign "InstallHinfSectionA"
((ptr void) @-> (ptr void) @-> string @-> int32_t @-> returning void)
(* Window : HWND -> (ptr void) *)
(* ModuleHandle : HINSTANCE -> (ptr void) *)
(* CommandLine : LPCSTR -> string *)
(* ShowCommand : INT -> int32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library setupapi (t "SETUPAPI.dll"))
(cffi:use-foreign-library setupapi)
(cffi:defcfun ("InstallHinfSectionA" install-hinf-section-a :convention :stdcall) :void
(window :pointer) ; HWND
(module-handle :pointer) ; HINSTANCE
(command-line :string) ; LPCSTR
(show-command :int32)) ; INT
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $InstallHinfSectionA = Win32::API::More->new('SETUPAPI',
'void InstallHinfSectionA(HANDLE Window, HANDLE ModuleHandle, LPCSTR CommandLine, int ShowCommand)');
# my $ret = $InstallHinfSectionA->Call($Window, $ModuleHandle, $CommandLine, $ShowCommand);
# Window : HWND -> HANDLE
# ModuleHandle : HINSTANCE -> HANDLE
# CommandLine : LPCSTR -> LPCSTR
# ShowCommand : INT -> int
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
文字セット違い
- f InstallHinfSectionW (Unicode版) — rundll32経由でINFセクションを実行するインストールエントリ。