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

SetupInstallFromInfSectionA

関数
INFのセクションに従いファイルコピーやレジストリ設定を実行する。
DLLSETUPAPI.dll文字セットANSI (-A)呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

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

BOOL SetupInstallFromInfSectionA(
    HWND Owner,   // optional
    void* InfHandle,
    LPCSTR SectionName,
    DWORD Flags,
    HKEY RelativeKeyRoot,   // optional
    LPCSTR SourceRootPath,   // optional
    DWORD CopyFlags,
    PSP_FILE_CALLBACK_A MsgHandler,   // optional
    void* Context,   // optional
    HDEVINFO DeviceInfoSet,   // optional
    SP_DEVINFO_DATA* DeviceInfoData   // optional
);

パラメーター

名前方向説明
OwnerHWNDinoptional進捗ダイアログの親ウィンドウハンドル。NULL可。
InfHandlevoid*inインストール情報を持つINFファイルのハンドル。
SectionNameLPCSTRin実行するInstallセクションの名前(ANSI)。
FlagsDWORDinSPINST_*系の処理対象を示すフラグ(レジストリ/ファイル等)。
RelativeKeyRootHKEYinoptionalAddRegで使う相対レジストリのルートキーハンドル。
SourceRootPathLPCSTRinoptionalコピー元ファイルのルートパス(ANSI)。NULL可。
CopyFlagsDWORDinファイルコピー時に適用するSP_COPY_*フラグ。
MsgHandlerPSP_FILE_CALLBACK_Ainoptionalコピー進捗を受け取るコールバック関数(ANSI)。NULL可。
Contextvoid*inoptionalコールバックへ渡すコンテキストポインタ。
DeviceInfoSetHDEVINFOinoptional関連付けるデバイス情報セットのハンドル。NULL可。
DeviceInfoDataSP_DEVINFO_DATA*inoptional対象デバイスを示すSP_DEVINFO_DATA構造体へのポインタ。NULL可。

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL SetupInstallFromInfSectionA(
    HWND Owner,   // optional
    void* InfHandle,
    LPCSTR SectionName,
    DWORD Flags,
    HKEY RelativeKeyRoot,   // optional
    LPCSTR SourceRootPath,   // optional
    DWORD CopyFlags,
    PSP_FILE_CALLBACK_A MsgHandler,   // optional
    void* Context,   // optional
    HDEVINFO DeviceInfoSet,   // optional
    SP_DEVINFO_DATA* DeviceInfoData   // optional
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("SETUPAPI.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern bool SetupInstallFromInfSectionA(
    IntPtr Owner,   // HWND optional
    IntPtr InfHandle,   // void*
    [MarshalAs(UnmanagedType.LPStr)] string SectionName,   // LPCSTR
    uint Flags,   // DWORD
    IntPtr RelativeKeyRoot,   // HKEY optional
    [MarshalAs(UnmanagedType.LPStr)] string SourceRootPath,   // LPCSTR optional
    uint CopyFlags,   // DWORD
    IntPtr MsgHandler,   // PSP_FILE_CALLBACK_A optional
    IntPtr Context,   // void* optional
    IntPtr DeviceInfoSet,   // HDEVINFO optional
    IntPtr DeviceInfoData   // SP_DEVINFO_DATA* optional
);
<DllImport("SETUPAPI.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetupInstallFromInfSectionA(
    Owner As IntPtr,   ' HWND optional
    InfHandle As IntPtr,   ' void*
    <MarshalAs(UnmanagedType.LPStr)> SectionName As String,   ' LPCSTR
    Flags As UInteger,   ' DWORD
    RelativeKeyRoot As IntPtr,   ' HKEY optional
    <MarshalAs(UnmanagedType.LPStr)> SourceRootPath As String,   ' LPCSTR optional
    CopyFlags As UInteger,   ' DWORD
    MsgHandler As IntPtr,   ' PSP_FILE_CALLBACK_A optional
    Context As IntPtr,   ' void* optional
    DeviceInfoSet As IntPtr,   ' HDEVINFO optional
    DeviceInfoData As IntPtr   ' SP_DEVINFO_DATA* optional
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
' Owner : HWND optional
' InfHandle : void*
' SectionName : LPCSTR
' Flags : DWORD
' RelativeKeyRoot : HKEY optional
' SourceRootPath : LPCSTR optional
' CopyFlags : DWORD
' MsgHandler : PSP_FILE_CALLBACK_A optional
' Context : void* optional
' DeviceInfoSet : HDEVINFO optional
' DeviceInfoData : SP_DEVINFO_DATA* optional
Declare PtrSafe Function SetupInstallFromInfSectionA Lib "setupapi" ( _
    ByVal Owner As LongPtr, _
    ByVal InfHandle As LongPtr, _
    ByVal SectionName As String, _
    ByVal Flags As Long, _
    ByVal RelativeKeyRoot As LongPtr, _
    ByVal SourceRootPath As String, _
    ByVal CopyFlags As Long, _
    ByVal MsgHandler As LongPtr, _
    ByVal Context As LongPtr, _
    ByVal DeviceInfoSet As LongPtr, _
    ByVal DeviceInfoData As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SetupInstallFromInfSectionA = ctypes.windll.setupapi.SetupInstallFromInfSectionA
SetupInstallFromInfSectionA.restype = wintypes.BOOL
SetupInstallFromInfSectionA.argtypes = [
    wintypes.HANDLE,  # Owner : HWND optional
    ctypes.POINTER(None),  # InfHandle : void*
    wintypes.LPCSTR,  # SectionName : LPCSTR
    wintypes.DWORD,  # Flags : DWORD
    wintypes.HANDLE,  # RelativeKeyRoot : HKEY optional
    wintypes.LPCSTR,  # SourceRootPath : LPCSTR optional
    wintypes.DWORD,  # CopyFlags : DWORD
    ctypes.c_void_p,  # MsgHandler : PSP_FILE_CALLBACK_A optional
    ctypes.POINTER(None),  # Context : void* optional
    ctypes.c_ssize_t,  # DeviceInfoSet : HDEVINFO optional
    ctypes.c_void_p,  # DeviceInfoData : SP_DEVINFO_DATA* optional
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('SETUPAPI.dll')
SetupInstallFromInfSectionA = Fiddle::Function.new(
  lib['SetupInstallFromInfSectionA'],
  [
    Fiddle::TYPE_VOIDP,  # Owner : HWND optional
    Fiddle::TYPE_VOIDP,  # InfHandle : void*
    Fiddle::TYPE_VOIDP,  # SectionName : LPCSTR
    -Fiddle::TYPE_INT,  # Flags : DWORD
    Fiddle::TYPE_VOIDP,  # RelativeKeyRoot : HKEY optional
    Fiddle::TYPE_VOIDP,  # SourceRootPath : LPCSTR optional
    -Fiddle::TYPE_INT,  # CopyFlags : DWORD
    Fiddle::TYPE_VOIDP,  # MsgHandler : PSP_FILE_CALLBACK_A optional
    Fiddle::TYPE_VOIDP,  # Context : void* optional
    Fiddle::TYPE_INTPTR_T,  # DeviceInfoSet : HDEVINFO optional
    Fiddle::TYPE_VOIDP,  # DeviceInfoData : SP_DEVINFO_DATA* optional
  ],
  Fiddle::TYPE_INT)
#[link(name = "setupapi")]
extern "system" {
    fn SetupInstallFromInfSectionA(
        Owner: *mut core::ffi::c_void,  // HWND optional
        InfHandle: *mut (),  // void*
        SectionName: *const u8,  // LPCSTR
        Flags: u32,  // DWORD
        RelativeKeyRoot: *mut core::ffi::c_void,  // HKEY optional
        SourceRootPath: *const u8,  // LPCSTR optional
        CopyFlags: u32,  // DWORD
        MsgHandler: *const core::ffi::c_void,  // PSP_FILE_CALLBACK_A optional
        Context: *mut (),  // void* optional
        DeviceInfoSet: isize,  // HDEVINFO optional
        DeviceInfoData: *mut SP_DEVINFO_DATA  // SP_DEVINFO_DATA* optional
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("SETUPAPI.dll", CharSet = CharSet.Ansi, SetLastError = true)]
public static extern bool SetupInstallFromInfSectionA(IntPtr Owner, IntPtr InfHandle, [MarshalAs(UnmanagedType.LPStr)] string SectionName, uint Flags, IntPtr RelativeKeyRoot, [MarshalAs(UnmanagedType.LPStr)] string SourceRootPath, uint CopyFlags, IntPtr MsgHandler, IntPtr Context, IntPtr DeviceInfoSet, IntPtr DeviceInfoData);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SETUPAPI_SetupInstallFromInfSectionA' -Namespace Win32 -PassThru
# $api::SetupInstallFromInfSectionA(Owner, InfHandle, SectionName, Flags, RelativeKeyRoot, SourceRootPath, CopyFlags, MsgHandler, Context, DeviceInfoSet, DeviceInfoData)
#uselib "SETUPAPI.dll"
#func global SetupInstallFromInfSectionA "SetupInstallFromInfSectionA" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; SetupInstallFromInfSectionA Owner, InfHandle, SectionName, Flags, RelativeKeyRoot, SourceRootPath, CopyFlags, MsgHandler, Context, DeviceInfoSet, varptr(DeviceInfoData)   ; 戻り値は stat
; Owner : HWND optional -> "sptr"
; InfHandle : void* -> "sptr"
; SectionName : LPCSTR -> "sptr"
; Flags : DWORD -> "sptr"
; RelativeKeyRoot : HKEY optional -> "sptr"
; SourceRootPath : LPCSTR optional -> "sptr"
; CopyFlags : DWORD -> "sptr"
; MsgHandler : PSP_FILE_CALLBACK_A optional -> "sptr"
; Context : void* optional -> "sptr"
; DeviceInfoSet : HDEVINFO optional -> "sptr"
; DeviceInfoData : SP_DEVINFO_DATA* optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "SETUPAPI.dll"
#cfunc global SetupInstallFromInfSectionA "SetupInstallFromInfSectionA" sptr, sptr, str, int, sptr, str, int, sptr, sptr, sptr, var
; res = SetupInstallFromInfSectionA(Owner, InfHandle, SectionName, Flags, RelativeKeyRoot, SourceRootPath, CopyFlags, MsgHandler, Context, DeviceInfoSet, DeviceInfoData)
; Owner : HWND optional -> "sptr"
; InfHandle : void* -> "sptr"
; SectionName : LPCSTR -> "str"
; Flags : DWORD -> "int"
; RelativeKeyRoot : HKEY optional -> "sptr"
; SourceRootPath : LPCSTR optional -> "str"
; CopyFlags : DWORD -> "int"
; MsgHandler : PSP_FILE_CALLBACK_A optional -> "sptr"
; Context : void* optional -> "sptr"
; DeviceInfoSet : HDEVINFO optional -> "sptr"
; DeviceInfoData : SP_DEVINFO_DATA* optional -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL SetupInstallFromInfSectionA(HWND Owner, void* InfHandle, LPCSTR SectionName, DWORD Flags, HKEY RelativeKeyRoot, LPCSTR SourceRootPath, DWORD CopyFlags, PSP_FILE_CALLBACK_A MsgHandler, void* Context, HDEVINFO DeviceInfoSet, SP_DEVINFO_DATA* DeviceInfoData)
#uselib "SETUPAPI.dll"
#cfunc global SetupInstallFromInfSectionA "SetupInstallFromInfSectionA" intptr, intptr, str, int, intptr, str, int, intptr, intptr, intptr, var
; res = SetupInstallFromInfSectionA(Owner, InfHandle, SectionName, Flags, RelativeKeyRoot, SourceRootPath, CopyFlags, MsgHandler, Context, DeviceInfoSet, DeviceInfoData)
; Owner : HWND optional -> "intptr"
; InfHandle : void* -> "intptr"
; SectionName : LPCSTR -> "str"
; Flags : DWORD -> "int"
; RelativeKeyRoot : HKEY optional -> "intptr"
; SourceRootPath : LPCSTR optional -> "str"
; CopyFlags : DWORD -> "int"
; MsgHandler : PSP_FILE_CALLBACK_A optional -> "intptr"
; Context : void* optional -> "intptr"
; DeviceInfoSet : HDEVINFO optional -> "intptr"
; DeviceInfoData : SP_DEVINFO_DATA* optional -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	setupapi = windows.NewLazySystemDLL("SETUPAPI.dll")
	procSetupInstallFromInfSectionA = setupapi.NewProc("SetupInstallFromInfSectionA")
)

// Owner (HWND optional), InfHandle (void*), SectionName (LPCSTR), Flags (DWORD), RelativeKeyRoot (HKEY optional), SourceRootPath (LPCSTR optional), CopyFlags (DWORD), MsgHandler (PSP_FILE_CALLBACK_A optional), Context (void* optional), DeviceInfoSet (HDEVINFO optional), DeviceInfoData (SP_DEVINFO_DATA* optional)
r1, _, err := procSetupInstallFromInfSectionA.Call(
	uintptr(Owner),
	uintptr(InfHandle),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(SectionName))),
	uintptr(Flags),
	uintptr(RelativeKeyRoot),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(SourceRootPath))),
	uintptr(CopyFlags),
	uintptr(MsgHandler),
	uintptr(Context),
	uintptr(DeviceInfoSet),
	uintptr(DeviceInfoData),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function SetupInstallFromInfSectionA(
  Owner: THandle;   // HWND optional
  InfHandle: Pointer;   // void*
  SectionName: PAnsiChar;   // LPCSTR
  Flags: DWORD;   // DWORD
  RelativeKeyRoot: THandle;   // HKEY optional
  SourceRootPath: PAnsiChar;   // LPCSTR optional
  CopyFlags: DWORD;   // DWORD
  MsgHandler: Pointer;   // PSP_FILE_CALLBACK_A optional
  Context: Pointer;   // void* optional
  DeviceInfoSet: NativeInt;   // HDEVINFO optional
  DeviceInfoData: Pointer   // SP_DEVINFO_DATA* optional
): BOOL; stdcall;
  external 'SETUPAPI.dll' name 'SetupInstallFromInfSectionA';
result := DllCall("SETUPAPI\SetupInstallFromInfSectionA"
    , "Ptr", Owner   ; HWND optional
    , "Ptr", InfHandle   ; void*
    , "AStr", SectionName   ; LPCSTR
    , "UInt", Flags   ; DWORD
    , "Ptr", RelativeKeyRoot   ; HKEY optional
    , "AStr", SourceRootPath   ; LPCSTR optional
    , "UInt", CopyFlags   ; DWORD
    , "Ptr", MsgHandler   ; PSP_FILE_CALLBACK_A optional
    , "Ptr", Context   ; void* optional
    , "Ptr", DeviceInfoSet   ; HDEVINFO optional
    , "Ptr", DeviceInfoData   ; SP_DEVINFO_DATA* optional
    , "Int")   ; return: BOOL
●SetupInstallFromInfSectionA(Owner, InfHandle, SectionName, Flags, RelativeKeyRoot, SourceRootPath, CopyFlags, MsgHandler, Context, DeviceInfoSet, DeviceInfoData) = DLL("SETUPAPI.dll", "bool SetupInstallFromInfSectionA(void*, void*, char*, dword, void*, char*, dword, void*, void*, int, void*)")
# 呼び出し: SetupInstallFromInfSectionA(Owner, InfHandle, SectionName, Flags, RelativeKeyRoot, SourceRootPath, CopyFlags, MsgHandler, Context, DeviceInfoSet, DeviceInfoData)
# Owner : HWND optional -> "void*"
# InfHandle : void* -> "void*"
# SectionName : LPCSTR -> "char*"
# Flags : DWORD -> "dword"
# RelativeKeyRoot : HKEY optional -> "void*"
# SourceRootPath : LPCSTR optional -> "char*"
# CopyFlags : DWORD -> "dword"
# MsgHandler : PSP_FILE_CALLBACK_A optional -> "void*"
# Context : void* optional -> "void*"
# DeviceInfoSet : HDEVINFO optional -> "int"
# DeviceInfoData : SP_DEVINFO_DATA* optional -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "setupapi" fn SetupInstallFromInfSectionA(
    Owner: ?*anyopaque, // HWND optional
    InfHandle: ?*anyopaque, // void*
    SectionName: [*c]const u8, // LPCSTR
    Flags: u32, // DWORD
    RelativeKeyRoot: ?*anyopaque, // HKEY optional
    SourceRootPath: [*c]const u8, // LPCSTR optional
    CopyFlags: u32, // DWORD
    MsgHandler: ?*anyopaque, // PSP_FILE_CALLBACK_A optional
    Context: ?*anyopaque, // void* optional
    DeviceInfoSet: isize, // HDEVINFO optional
    DeviceInfoData: [*c]SP_DEVINFO_DATA // SP_DEVINFO_DATA* optional
) callconv(std.os.windows.WINAPI) i32;
proc SetupInstallFromInfSectionA(
    Owner: pointer,  # HWND optional
    InfHandle: pointer,  # void*
    SectionName: cstring,  # LPCSTR
    Flags: uint32,  # DWORD
    RelativeKeyRoot: pointer,  # HKEY optional
    SourceRootPath: cstring,  # LPCSTR optional
    CopyFlags: uint32,  # DWORD
    MsgHandler: pointer,  # PSP_FILE_CALLBACK_A optional
    Context: pointer,  # void* optional
    DeviceInfoSet: int,  # HDEVINFO optional
    DeviceInfoData: ptr SP_DEVINFO_DATA  # SP_DEVINFO_DATA* optional
): int32 {.importc: "SetupInstallFromInfSectionA", stdcall, dynlib: "SETUPAPI.dll".}
pragma(lib, "setupapi");
extern(Windows)
int SetupInstallFromInfSectionA(
    void* Owner,   // HWND optional
    void* InfHandle,   // void*
    const(char)* SectionName,   // LPCSTR
    uint Flags,   // DWORD
    void* RelativeKeyRoot,   // HKEY optional
    const(char)* SourceRootPath,   // LPCSTR optional
    uint CopyFlags,   // DWORD
    void* MsgHandler,   // PSP_FILE_CALLBACK_A optional
    void* Context,   // void* optional
    ptrdiff_t DeviceInfoSet,   // HDEVINFO optional
    SP_DEVINFO_DATA* DeviceInfoData   // SP_DEVINFO_DATA* optional
);
ccall((:SetupInstallFromInfSectionA, "SETUPAPI.dll"), stdcall, Int32,
      (Ptr{Cvoid}, Ptr{Cvoid}, Cstring, UInt32, Ptr{Cvoid}, Cstring, UInt32, Ptr{Cvoid}, Ptr{Cvoid}, Int, Ptr{SP_DEVINFO_DATA}),
      Owner, InfHandle, SectionName, Flags, RelativeKeyRoot, SourceRootPath, CopyFlags, MsgHandler, Context, DeviceInfoSet, DeviceInfoData)
# Owner : HWND optional -> Ptr{Cvoid}
# InfHandle : void* -> Ptr{Cvoid}
# SectionName : LPCSTR -> Cstring
# Flags : DWORD -> UInt32
# RelativeKeyRoot : HKEY optional -> Ptr{Cvoid}
# SourceRootPath : LPCSTR optional -> Cstring
# CopyFlags : DWORD -> UInt32
# MsgHandler : PSP_FILE_CALLBACK_A optional -> Ptr{Cvoid}
# Context : void* optional -> Ptr{Cvoid}
# DeviceInfoSet : HDEVINFO optional -> Int
# DeviceInfoData : SP_DEVINFO_DATA* optional -> Ptr{SP_DEVINFO_DATA}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t SetupInstallFromInfSectionA(
    void* Owner,
    void* InfHandle,
    const char* SectionName,
    uint32_t Flags,
    void* RelativeKeyRoot,
    const char* SourceRootPath,
    uint32_t CopyFlags,
    void* MsgHandler,
    void* Context,
    intptr_t DeviceInfoSet,
    void* DeviceInfoData);
]]
local setupapi = ffi.load("setupapi")
-- setupapi.SetupInstallFromInfSectionA(Owner, InfHandle, SectionName, Flags, RelativeKeyRoot, SourceRootPath, CopyFlags, MsgHandler, Context, DeviceInfoSet, DeviceInfoData)
-- Owner : HWND optional
-- InfHandle : void*
-- SectionName : LPCSTR
-- Flags : DWORD
-- RelativeKeyRoot : HKEY optional
-- SourceRootPath : LPCSTR optional
-- CopyFlags : DWORD
-- MsgHandler : PSP_FILE_CALLBACK_A optional
-- Context : void* optional
-- DeviceInfoSet : HDEVINFO optional
-- DeviceInfoData : SP_DEVINFO_DATA* optional
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('SETUPAPI.dll');
const SetupInstallFromInfSectionA = lib.func('__stdcall', 'SetupInstallFromInfSectionA', 'int32_t', ['void *', 'void *', 'str', 'uint32_t', 'void *', 'str', 'uint32_t', 'void *', 'void *', 'intptr_t', 'void *']);
// SetupInstallFromInfSectionA(Owner, InfHandle, SectionName, Flags, RelativeKeyRoot, SourceRootPath, CopyFlags, MsgHandler, Context, DeviceInfoSet, DeviceInfoData)
// Owner : HWND optional -> 'void *'
// InfHandle : void* -> 'void *'
// SectionName : LPCSTR -> 'str'
// Flags : DWORD -> 'uint32_t'
// RelativeKeyRoot : HKEY optional -> 'void *'
// SourceRootPath : LPCSTR optional -> 'str'
// CopyFlags : DWORD -> 'uint32_t'
// MsgHandler : PSP_FILE_CALLBACK_A optional -> 'void *'
// Context : void* optional -> 'void *'
// DeviceInfoSet : HDEVINFO optional -> 'intptr_t'
// DeviceInfoData : SP_DEVINFO_DATA* optional -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
// コールバック(関数ポインタ)は koffi.proto/koffi.register で型を定義して渡す(素の void* では JS 関数を渡せない)。
const lib = Deno.dlopen("SETUPAPI.dll", {
  SetupInstallFromInfSectionA: { parameters: ["pointer", "pointer", "buffer", "u32", "pointer", "buffer", "u32", "pointer", "pointer", "isize", "pointer"], result: "i32" },
});
// lib.symbols.SetupInstallFromInfSectionA(Owner, InfHandle, SectionName, Flags, RelativeKeyRoot, SourceRootPath, CopyFlags, MsgHandler, Context, DeviceInfoSet, DeviceInfoData)
// Owner : HWND optional -> "pointer"
// InfHandle : void* -> "pointer"
// SectionName : LPCSTR -> "buffer"
// Flags : DWORD -> "u32"
// RelativeKeyRoot : HKEY optional -> "pointer"
// SourceRootPath : LPCSTR optional -> "buffer"
// CopyFlags : DWORD -> "u32"
// MsgHandler : PSP_FILE_CALLBACK_A optional -> "pointer"
// Context : void* optional -> "pointer"
// DeviceInfoSet : HDEVINFO optional -> "isize"
// DeviceInfoData : SP_DEVINFO_DATA* optional -> "pointer"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t SetupInstallFromInfSectionA(
    void* Owner,
    void* InfHandle,
    const char* SectionName,
    uint32_t Flags,
    void* RelativeKeyRoot,
    const char* SourceRootPath,
    uint32_t CopyFlags,
    void* MsgHandler,
    void* Context,
    intptr_t DeviceInfoSet,
    void* DeviceInfoData);
C, "SETUPAPI.dll");
// $ffi->SetupInstallFromInfSectionA(Owner, InfHandle, SectionName, Flags, RelativeKeyRoot, SourceRootPath, CopyFlags, MsgHandler, Context, DeviceInfoSet, DeviceInfoData);
// Owner : HWND optional
// InfHandle : void*
// SectionName : LPCSTR
// Flags : DWORD
// RelativeKeyRoot : HKEY optional
// SourceRootPath : LPCSTR optional
// CopyFlags : DWORD
// MsgHandler : PSP_FILE_CALLBACK_A optional
// Context : void* optional
// DeviceInfoSet : HDEVINFO optional
// DeviceInfoData : SP_DEVINFO_DATA* optional
// 構造体/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);
    boolean SetupInstallFromInfSectionA(
        Pointer Owner,   // HWND optional
        Pointer InfHandle,   // void*
        String SectionName,   // LPCSTR
        int Flags,   // DWORD
        Pointer RelativeKeyRoot,   // HKEY optional
        String SourceRootPath,   // LPCSTR optional
        int CopyFlags,   // DWORD
        Callback MsgHandler,   // PSP_FILE_CALLBACK_A optional
        Pointer Context,   // void* optional
        long DeviceInfoSet,   // HDEVINFO optional
        Pointer DeviceInfoData   // SP_DEVINFO_DATA* optional
    );
}
@[Link("setupapi")]
lib LibSETUPAPI
  fun SetupInstallFromInfSectionA = SetupInstallFromInfSectionA(
    Owner : Void*,   # HWND optional
    InfHandle : Void*,   # void*
    SectionName : UInt8*,   # LPCSTR
    Flags : UInt32,   # DWORD
    RelativeKeyRoot : Void*,   # HKEY optional
    SourceRootPath : UInt8*,   # LPCSTR optional
    CopyFlags : UInt32,   # DWORD
    MsgHandler : Void*,   # PSP_FILE_CALLBACK_A optional
    Context : Void*,   # void* optional
    DeviceInfoSet : LibC::SSizeT,   # HDEVINFO optional
    DeviceInfoData : SP_DEVINFO_DATA*   # SP_DEVINFO_DATA* optional
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef SetupInstallFromInfSectionANative = Int32 Function(Pointer<Void>, Pointer<Void>, Pointer<Utf8>, Uint32, Pointer<Void>, Pointer<Utf8>, Uint32, Pointer<Void>, Pointer<Void>, IntPtr, Pointer<Void>);
typedef SetupInstallFromInfSectionADart = int Function(Pointer<Void>, Pointer<Void>, Pointer<Utf8>, int, Pointer<Void>, Pointer<Utf8>, int, Pointer<Void>, Pointer<Void>, int, Pointer<Void>);
final SetupInstallFromInfSectionA = DynamicLibrary.open('SETUPAPI.dll')
    .lookupFunction<SetupInstallFromInfSectionANative, SetupInstallFromInfSectionADart>('SetupInstallFromInfSectionA');
// Owner : HWND optional -> Pointer<Void>
// InfHandle : void* -> Pointer<Void>
// SectionName : LPCSTR -> Pointer<Utf8>
// Flags : DWORD -> Uint32
// RelativeKeyRoot : HKEY optional -> Pointer<Void>
// SourceRootPath : LPCSTR optional -> Pointer<Utf8>
// CopyFlags : DWORD -> Uint32
// MsgHandler : PSP_FILE_CALLBACK_A optional -> Pointer<Void>
// Context : void* optional -> Pointer<Void>
// DeviceInfoSet : HDEVINFO optional -> IntPtr
// DeviceInfoData : SP_DEVINFO_DATA* optional -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function SetupInstallFromInfSectionA(
  Owner: THandle;   // HWND optional
  InfHandle: Pointer;   // void*
  SectionName: PAnsiChar;   // LPCSTR
  Flags: DWORD;   // DWORD
  RelativeKeyRoot: THandle;   // HKEY optional
  SourceRootPath: PAnsiChar;   // LPCSTR optional
  CopyFlags: DWORD;   // DWORD
  MsgHandler: Pointer;   // PSP_FILE_CALLBACK_A optional
  Context: Pointer;   // void* optional
  DeviceInfoSet: NativeInt;   // HDEVINFO optional
  DeviceInfoData: Pointer   // SP_DEVINFO_DATA* optional
): BOOL; stdcall;
  external 'SETUPAPI.dll' name 'SetupInstallFromInfSectionA';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "SetupInstallFromInfSectionA"
  c_SetupInstallFromInfSectionA :: Ptr () -> Ptr () -> CString -> Word32 -> Ptr () -> CString -> Word32 -> Ptr () -> Ptr () -> CIntPtr -> Ptr () -> IO CInt
-- Owner : HWND optional -> Ptr ()
-- InfHandle : void* -> Ptr ()
-- SectionName : LPCSTR -> CString
-- Flags : DWORD -> Word32
-- RelativeKeyRoot : HKEY optional -> Ptr ()
-- SourceRootPath : LPCSTR optional -> CString
-- CopyFlags : DWORD -> Word32
-- MsgHandler : PSP_FILE_CALLBACK_A optional -> Ptr ()
-- Context : void* optional -> Ptr ()
-- DeviceInfoSet : HDEVINFO optional -> CIntPtr
-- DeviceInfoData : SP_DEVINFO_DATA* optional -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let setupinstallfrominfsectiona =
  foreign "SetupInstallFromInfSectionA"
    ((ptr void) @-> (ptr void) @-> string @-> uint32_t @-> (ptr void) @-> string @-> uint32_t @-> (ptr void) @-> (ptr void) @-> intptr_t @-> (ptr void) @-> returning int32_t)
(* Owner : HWND optional -> (ptr void) *)
(* InfHandle : void* -> (ptr void) *)
(* SectionName : LPCSTR -> string *)
(* Flags : DWORD -> uint32_t *)
(* RelativeKeyRoot : HKEY optional -> (ptr void) *)
(* SourceRootPath : LPCSTR optional -> string *)
(* CopyFlags : DWORD -> uint32_t *)
(* MsgHandler : PSP_FILE_CALLBACK_A optional -> (ptr void) *)
(* Context : void* optional -> (ptr void) *)
(* DeviceInfoSet : HDEVINFO optional -> intptr_t *)
(* DeviceInfoData : SP_DEVINFO_DATA* optional -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library setupapi (t "SETUPAPI.dll"))
(cffi:use-foreign-library setupapi)

(cffi:defcfun ("SetupInstallFromInfSectionA" setup-install-from-inf-section-a :convention :stdcall) :int32
  (owner :pointer)   ; HWND optional
  (inf-handle :pointer)   ; void*
  (section-name :string)   ; LPCSTR
  (flags :uint32)   ; DWORD
  (relative-key-root :pointer)   ; HKEY optional
  (source-root-path :string)   ; LPCSTR optional
  (copy-flags :uint32)   ; DWORD
  (msg-handler :pointer)   ; PSP_FILE_CALLBACK_A optional
  (context :pointer)   ; void* optional
  (device-info-set :int64)   ; HDEVINFO optional
  (device-info-data :pointer))   ; SP_DEVINFO_DATA* optional
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $SetupInstallFromInfSectionA = Win32::API::More->new('SETUPAPI',
    'BOOL SetupInstallFromInfSectionA(HANDLE Owner, LPVOID InfHandle, LPCSTR SectionName, DWORD Flags, HANDLE RelativeKeyRoot, LPCSTR SourceRootPath, DWORD CopyFlags, LPVOID MsgHandler, LPVOID Context, LPARAM DeviceInfoSet, LPVOID DeviceInfoData)');
# my $ret = $SetupInstallFromInfSectionA->Call($Owner, $InfHandle, $SectionName, $Flags, $RelativeKeyRoot, $SourceRootPath, $CopyFlags, $MsgHandler, $Context, $DeviceInfoSet, $DeviceInfoData);
# Owner : HWND optional -> HANDLE
# InfHandle : void* -> LPVOID
# SectionName : LPCSTR -> LPCSTR
# Flags : DWORD -> DWORD
# RelativeKeyRoot : HKEY optional -> HANDLE
# SourceRootPath : LPCSTR optional -> LPCSTR
# CopyFlags : DWORD -> DWORD
# MsgHandler : PSP_FILE_CALLBACK_A optional -> LPVOID
# Context : void* optional -> LPVOID
# DeviceInfoSet : HDEVINFO optional -> LPARAM
# DeviceInfoData : SP_DEVINFO_DATA* optional -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# コールバック(関数ポインタ)は Perl sub を直接渡せません。Win32::API::Callback を使用してください。

関連項目

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