Win32 API 日本語リファレンス
ホームDevices.DeviceAndDriverInstallation › InstallHinfSectionW

InstallHinfSectionW

関数
rundll32経由でINFセクションを実行するインストールエントリ。
DLLSETUPAPI.dll文字セットUnicode (-W)呼出規約winapi対応OSWindows XP 以降

シグネチャ

// SETUPAPI.dll  (Unicode / -W)
#include <windows.h>

void InstallHinfSectionW(
    HWND Window,
    HINSTANCE ModuleHandle,
    LPCWSTR CommandLine,
    INT ShowCommand
);

パラメーター

名前方向説明
WindowHWNDinrundll32経由で渡される親ウィンドウハンドル。
ModuleHandleHINSTANCEin呼び出し元モジュールのインスタンスハンドル。
CommandLineLPCWSTRinセクション名やINFパスを含むコマンドライン文字列(Unicode)。
ShowCommandINTinウィンドウ表示方法を示すSW_*値。

戻り値の型: void

各言語での呼び出し定義

// SETUPAPI.dll  (Unicode / -W)
#include <windows.h>

void InstallHinfSectionW(
    HWND Window,
    HINSTANCE ModuleHandle,
    LPCWSTR CommandLine,
    INT ShowCommand
);
[DllImport("SETUPAPI.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern void InstallHinfSectionW(
    IntPtr Window,   // HWND
    IntPtr ModuleHandle,   // HINSTANCE
    [MarshalAs(UnmanagedType.LPWStr)] string CommandLine,   // LPCWSTR
    int ShowCommand   // INT
);
<DllImport("SETUPAPI.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Sub InstallHinfSectionW(
    Window As IntPtr,   ' HWND
    ModuleHandle As IntPtr,   ' HINSTANCE
    <MarshalAs(UnmanagedType.LPWStr)> CommandLine As String,   ' LPCWSTR
    ShowCommand As Integer   ' INT
)
End Sub
' Window : HWND
' ModuleHandle : HINSTANCE
' CommandLine : LPCWSTR
' ShowCommand : INT
Declare PtrSafe Sub InstallHinfSectionW Lib "setupapi" ( _
    ByVal Window As LongPtr, _
    ByVal ModuleHandle As LongPtr, _
    ByVal CommandLine As LongPtr, _
    ByVal ShowCommand 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

InstallHinfSectionW = ctypes.windll.setupapi.InstallHinfSectionW
InstallHinfSectionW.restype = None
InstallHinfSectionW.argtypes = [
    wintypes.HANDLE,  # Window : HWND
    wintypes.HANDLE,  # ModuleHandle : HINSTANCE
    wintypes.LPCWSTR,  # CommandLine : LPCWSTR
    ctypes.c_int,  # ShowCommand : INT
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('SETUPAPI.dll')
InstallHinfSectionW = Fiddle::Function.new(
  lib['InstallHinfSectionW'],
  [
    Fiddle::TYPE_VOIDP,  # Window : HWND
    Fiddle::TYPE_VOIDP,  # ModuleHandle : HINSTANCE
    Fiddle::TYPE_VOIDP,  # CommandLine : LPCWSTR
    Fiddle::TYPE_INT,  # ShowCommand : INT
  ],
  Fiddle::TYPE_VOID)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "setupapi")]
extern "system" {
    fn InstallHinfSectionW(
        Window: *mut core::ffi::c_void,  // HWND
        ModuleHandle: *mut core::ffi::c_void,  // HINSTANCE
        CommandLine: *const u16,  // LPCWSTR
        ShowCommand: i32  // INT
    );
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("SETUPAPI.dll", CharSet = CharSet.Unicode)]
public static extern void InstallHinfSectionW(IntPtr Window, IntPtr ModuleHandle, [MarshalAs(UnmanagedType.LPWStr)] string CommandLine, int ShowCommand);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SETUPAPI_InstallHinfSectionW' -Namespace Win32 -PassThru
# $api::InstallHinfSectionW(Window, ModuleHandle, CommandLine, ShowCommand)
#uselib "SETUPAPI.dll"
#func global InstallHinfSectionW "InstallHinfSectionW" wptr, wptr, wptr, wptr
; InstallHinfSectionW Window, ModuleHandle, CommandLine, ShowCommand
; Window : HWND -> "wptr"
; ModuleHandle : HINSTANCE -> "wptr"
; CommandLine : LPCWSTR -> "wptr"
; ShowCommand : INT -> "wptr"
#uselib "SETUPAPI.dll"
#func global InstallHinfSectionW "InstallHinfSectionW" sptr, sptr, wstr, int
; InstallHinfSectionW Window, ModuleHandle, CommandLine, ShowCommand
; Window : HWND -> "sptr"
; ModuleHandle : HINSTANCE -> "sptr"
; CommandLine : LPCWSTR -> "wstr"
; ShowCommand : INT -> "int"
; void InstallHinfSectionW(HWND Window, HINSTANCE ModuleHandle, LPCWSTR CommandLine, INT ShowCommand)
#uselib "SETUPAPI.dll"
#func global InstallHinfSectionW "InstallHinfSectionW" intptr, intptr, wstr, int
; InstallHinfSectionW Window, ModuleHandle, CommandLine, ShowCommand
; Window : HWND -> "intptr"
; ModuleHandle : HINSTANCE -> "intptr"
; CommandLine : LPCWSTR -> "wstr"
; ShowCommand : INT -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	setupapi = windows.NewLazySystemDLL("SETUPAPI.dll")
	procInstallHinfSectionW = setupapi.NewProc("InstallHinfSectionW")
)

// Window (HWND), ModuleHandle (HINSTANCE), CommandLine (LPCWSTR), ShowCommand (INT)
r1, _, err := procInstallHinfSectionW.Call(
	uintptr(Window),
	uintptr(ModuleHandle),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(CommandLine))),
	uintptr(ShowCommand),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // void
procedure InstallHinfSectionW(
  Window: THandle;   // HWND
  ModuleHandle: THandle;   // HINSTANCE
  CommandLine: PWideChar;   // LPCWSTR
  ShowCommand: Integer   // INT
); stdcall;
  external 'SETUPAPI.dll' name 'InstallHinfSectionW';
result := DllCall("SETUPAPI\InstallHinfSectionW"
    , "Ptr", Window   ; HWND
    , "Ptr", ModuleHandle   ; HINSTANCE
    , "WStr", CommandLine   ; LPCWSTR
    , "Int", ShowCommand   ; INT
    , "Int")   ; return: void
●InstallHinfSectionW(Window, ModuleHandle, CommandLine, ShowCommand) = DLL("SETUPAPI.dll", "int InstallHinfSectionW(void*, void*, char*, int)")
# 呼び出し: InstallHinfSectionW(Window, ModuleHandle, CommandLine, ShowCommand)
# Window : HWND -> "void*"
# ModuleHandle : HINSTANCE -> "void*"
# CommandLine : LPCWSTR -> "char*"
# ShowCommand : INT -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。
const std = @import("std");

extern "setupapi" fn InstallHinfSectionW(
    Window: ?*anyopaque, // HWND
    ModuleHandle: ?*anyopaque, // HINSTANCE
    CommandLine: [*c]const u16, // LPCWSTR
    ShowCommand: i32 // INT
) callconv(std.os.windows.WINAPI) void;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。
proc InstallHinfSectionW(
    Window: pointer,  # HWND
    ModuleHandle: pointer,  # HINSTANCE
    CommandLine: WideCString,  # LPCWSTR
    ShowCommand: int32  # INT
) {.importc: "InstallHinfSectionW", stdcall, dynlib: "SETUPAPI.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。
pragma(lib, "setupapi");
extern(Windows)
void InstallHinfSectionW(
    void* Window,   // HWND
    void* ModuleHandle,   // HINSTANCE
    const(wchar)* CommandLine,   // LPCWSTR
    int ShowCommand   // INT
);
ccall((:InstallHinfSectionW, "SETUPAPI.dll"), stdcall, Cvoid,
      (Ptr{Cvoid}, Ptr{Cvoid}, Cwstring, Int32),
      Window, ModuleHandle, CommandLine, ShowCommand)
# Window : HWND -> Ptr{Cvoid}
# ModuleHandle : HINSTANCE -> Ptr{Cvoid}
# CommandLine : LPCWSTR -> Cwstring
# ShowCommand : INT -> Int32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。
local ffi = require("ffi")
ffi.cdef[[
void InstallHinfSectionW(
    void* Window,
    void* ModuleHandle,
    const uint16_t* CommandLine,
    int32_t ShowCommand);
]]
local setupapi = ffi.load("setupapi")
-- setupapi.InstallHinfSectionW(Window, ModuleHandle, CommandLine, ShowCommand)
-- Window : HWND
-- ModuleHandle : HINSTANCE
-- CommandLine : LPCWSTR
-- ShowCommand : INT
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
-- Unicode(-W): uint16_t* には UTF-16LE のバッファ(ffi.new("uint16_t[?]", ...))を渡す。
const koffi = require('koffi');
const lib = koffi.load('SETUPAPI.dll');
const InstallHinfSectionW = lib.func('__stdcall', 'InstallHinfSectionW', 'void', ['void *', 'void *', 'str16', 'int32_t']);
// InstallHinfSectionW(Window, ModuleHandle, CommandLine, ShowCommand)
// Window : HWND -> 'void *'
// ModuleHandle : HINSTANCE -> 'void *'
// CommandLine : LPCWSTR -> 'str16'
// ShowCommand : INT -> 'int32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("SETUPAPI.dll", {
  InstallHinfSectionW: { parameters: ["pointer", "pointer", "buffer", "i32"], result: "void" },
});
// lib.symbols.InstallHinfSectionW(Window, ModuleHandle, CommandLine, ShowCommand)
// Window : HWND -> "pointer"
// ModuleHandle : HINSTANCE -> "pointer"
// CommandLine : LPCWSTR -> "buffer"
// ShowCommand : INT -> "i32"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
void InstallHinfSectionW(
    void* Window,
    void* ModuleHandle,
    const uint16_t* CommandLine,
    int32_t ShowCommand);
C, "SETUPAPI.dll");
// $ffi->InstallHinfSectionW(Window, ModuleHandle, CommandLine, ShowCommand);
// Window : HWND
// ModuleHandle : HINSTANCE
// CommandLine : LPCWSTR
// 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.UNICODE_OPTIONS);
    void InstallHinfSectionW(
        Pointer Window,   // HWND
        Pointer ModuleHandle,   // HINSTANCE
        WString CommandLine,   // LPCWSTR
        int ShowCommand   // INT
    );
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。
@[Link("setupapi")]
lib LibSETUPAPI
  fun InstallHinfSectionW = InstallHinfSectionW(
    Window : Void*,   # HWND
    ModuleHandle : Void*,   # HINSTANCE
    CommandLine : UInt16*,   # LPCWSTR
    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 InstallHinfSectionWNative = Void Function(Pointer<Void>, Pointer<Void>, Pointer<Utf16>, Int32);
typedef InstallHinfSectionWDart = void Function(Pointer<Void>, Pointer<Void>, Pointer<Utf16>, int);
final InstallHinfSectionW = DynamicLibrary.open('SETUPAPI.dll')
    .lookupFunction<InstallHinfSectionWNative, InstallHinfSectionWDart>('InstallHinfSectionW');
// Window : HWND -> Pointer<Void>
// ModuleHandle : HINSTANCE -> Pointer<Void>
// CommandLine : LPCWSTR -> Pointer<Utf16>
// ShowCommand : INT -> Int32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
procedure InstallHinfSectionW(
  Window: THandle;   // HWND
  ModuleHandle: THandle;   // HINSTANCE
  CommandLine: PWideChar;   // LPCWSTR
  ShowCommand: Integer   // INT
); stdcall;
  external 'SETUPAPI.dll' name 'InstallHinfSectionW';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "InstallHinfSectionW"
  c_InstallHinfSectionW :: Ptr () -> Ptr () -> CWString -> Int32 -> IO ()
-- Window : HWND -> Ptr ()
-- ModuleHandle : HINSTANCE -> Ptr ()
-- CommandLine : LPCWSTR -> CWString
-- ShowCommand : INT -> Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let installhinfsectionw =
  foreign "InstallHinfSectionW"
    ((ptr void) @-> (ptr void) @-> (ptr uint16_t) @-> int32_t @-> returning void)
(* Window : HWND -> (ptr void) *)
(* ModuleHandle : HINSTANCE -> (ptr void) *)
(* CommandLine : LPCWSTR -> (ptr uint16_t) *)
(* 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 ("InstallHinfSectionW" install-hinf-section-w :convention :stdcall) :void
  (window :pointer)   ; HWND
  (module-handle :pointer)   ; HINSTANCE
  (command-line (:string :encoding :utf-16le))   ; LPCWSTR
  (show-command :int32))   ; INT
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $InstallHinfSectionW = Win32::API::More->new('SETUPAPI',
    'void InstallHinfSectionW(HANDLE Window, HANDLE ModuleHandle, LPCWSTR CommandLine, int ShowCommand)');
# my $ret = $InstallHinfSectionW->Call($Window, $ModuleHandle, $CommandLine, $ShowCommand);
# Window : HWND -> HANDLE
# ModuleHandle : HINSTANCE -> HANDLE
# CommandLine : LPCWSTR -> LPCWSTR
# ShowCommand : INT -> int
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。

関連項目

文字セット違い