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

SetupDiGetActualSectionToInstallExW

関数
指定プラットフォームでインストールする実際のINFセクション名を取得する。
DLLSETUPAPI.dll文字セットUnicode (-W)呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

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

BOOL SetupDiGetActualSectionToInstallExW(
    void* InfHandle,
    LPCWSTR InfSectionName,
    SP_ALTPLATFORM_INFO_V2* AlternatePlatformInfo,   // optional
    LPWSTR InfSectionWithExt,   // optional
    DWORD InfSectionWithExtSize,
    DWORD* RequiredSize,   // optional
    LPWSTR* Extension,   // optional
    void* Reserved   // optional
);

パラメーター

名前方向説明
InfHandlevoid*in対象INFファイルのハンドル。SetupOpenInfFile等で取得する。
InfSectionNameLPCWSTRin基本のインストールセクション名(Unicode)。
AlternatePlatformInfoSP_ALTPLATFORM_INFO_V2*inoptional対象プラットフォーム情報を示す構造体。NULL指定で現在のプラットフォームを使う。
InfSectionWithExtLPWSTRoutoptional装飾付き実セクション名を受け取るバッファ(Unicode)。
InfSectionWithExtSizeDWORDinInfSectionWithExtバッファの文字数。
RequiredSizeDWORD*outoptional必要な文字数を受け取るポインタ。不足判定に使う。NULL可。
ExtensionLPWSTR*outoptional実セクション名の拡張子部分への先頭ポインタを受け取る。不要ならNULL。
Reservedvoid*optional予約済み。NULLを指定する。

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL SetupDiGetActualSectionToInstallExW(
    void* InfHandle,
    LPCWSTR InfSectionName,
    SP_ALTPLATFORM_INFO_V2* AlternatePlatformInfo,   // optional
    LPWSTR InfSectionWithExt,   // optional
    DWORD InfSectionWithExtSize,
    DWORD* RequiredSize,   // optional
    LPWSTR* Extension,   // optional
    void* Reserved   // optional
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("SETUPAPI.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern bool SetupDiGetActualSectionToInstallExW(
    IntPtr InfHandle,   // void*
    [MarshalAs(UnmanagedType.LPWStr)] string InfSectionName,   // LPCWSTR
    IntPtr AlternatePlatformInfo,   // SP_ALTPLATFORM_INFO_V2* optional
    [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder InfSectionWithExt,   // LPWSTR optional, out
    uint InfSectionWithExtSize,   // DWORD
    IntPtr RequiredSize,   // DWORD* optional, out
    IntPtr Extension,   // LPWSTR* optional, out
    IntPtr Reserved   // void* optional
);
<DllImport("SETUPAPI.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetupDiGetActualSectionToInstallExW(
    InfHandle As IntPtr,   ' void*
    <MarshalAs(UnmanagedType.LPWStr)> InfSectionName As String,   ' LPCWSTR
    AlternatePlatformInfo As IntPtr,   ' SP_ALTPLATFORM_INFO_V2* optional
    <MarshalAs(UnmanagedType.LPWStr)> InfSectionWithExt As System.Text.StringBuilder,   ' LPWSTR optional, out
    InfSectionWithExtSize As UInteger,   ' DWORD
    RequiredSize As IntPtr,   ' DWORD* optional, out
    Extension As IntPtr,   ' LPWSTR* optional, out
    Reserved As IntPtr   ' void* optional
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
' InfHandle : void*
' InfSectionName : LPCWSTR
' AlternatePlatformInfo : SP_ALTPLATFORM_INFO_V2* optional
' InfSectionWithExt : LPWSTR optional, out
' InfSectionWithExtSize : DWORD
' RequiredSize : DWORD* optional, out
' Extension : LPWSTR* optional, out
' Reserved : void* optional
Declare PtrSafe Function SetupDiGetActualSectionToInstallExW Lib "setupapi" ( _
    ByVal InfHandle As LongPtr, _
    ByVal InfSectionName As LongPtr, _
    ByVal AlternatePlatformInfo As LongPtr, _
    ByVal InfSectionWithExt As LongPtr, _
    ByVal InfSectionWithExtSize As Long, _
    ByVal RequiredSize As LongPtr, _
    ByVal Extension As LongPtr, _
    ByVal Reserved 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

SetupDiGetActualSectionToInstallExW = ctypes.windll.setupapi.SetupDiGetActualSectionToInstallExW
SetupDiGetActualSectionToInstallExW.restype = wintypes.BOOL
SetupDiGetActualSectionToInstallExW.argtypes = [
    ctypes.POINTER(None),  # InfHandle : void*
    wintypes.LPCWSTR,  # InfSectionName : LPCWSTR
    ctypes.c_void_p,  # AlternatePlatformInfo : SP_ALTPLATFORM_INFO_V2* optional
    wintypes.LPWSTR,  # InfSectionWithExt : LPWSTR optional, out
    wintypes.DWORD,  # InfSectionWithExtSize : DWORD
    ctypes.POINTER(wintypes.DWORD),  # RequiredSize : DWORD* optional, out
    ctypes.c_void_p,  # Extension : LPWSTR* optional, out
    ctypes.POINTER(None),  # Reserved : void* optional
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('SETUPAPI.dll')
SetupDiGetActualSectionToInstallExW = Fiddle::Function.new(
  lib['SetupDiGetActualSectionToInstallExW'],
  [
    Fiddle::TYPE_VOIDP,  # InfHandle : void*
    Fiddle::TYPE_VOIDP,  # InfSectionName : LPCWSTR
    Fiddle::TYPE_VOIDP,  # AlternatePlatformInfo : SP_ALTPLATFORM_INFO_V2* optional
    Fiddle::TYPE_VOIDP,  # InfSectionWithExt : LPWSTR optional, out
    -Fiddle::TYPE_INT,  # InfSectionWithExtSize : DWORD
    Fiddle::TYPE_VOIDP,  # RequiredSize : DWORD* optional, out
    Fiddle::TYPE_VOIDP,  # Extension : LPWSTR* optional, out
    Fiddle::TYPE_VOIDP,  # Reserved : void* optional
  ],
  Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "setupapi")]
extern "system" {
    fn SetupDiGetActualSectionToInstallExW(
        InfHandle: *mut (),  // void*
        InfSectionName: *const u16,  // LPCWSTR
        AlternatePlatformInfo: *mut SP_ALTPLATFORM_INFO_V2,  // SP_ALTPLATFORM_INFO_V2* optional
        InfSectionWithExt: *mut u16,  // LPWSTR optional, out
        InfSectionWithExtSize: u32,  // DWORD
        RequiredSize: *mut u32,  // DWORD* optional, out
        Extension: *mut *mut u16,  // LPWSTR* optional, out
        Reserved: *mut ()  // void* optional
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("SETUPAPI.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern bool SetupDiGetActualSectionToInstallExW(IntPtr InfHandle, [MarshalAs(UnmanagedType.LPWStr)] string InfSectionName, IntPtr AlternatePlatformInfo, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder InfSectionWithExt, uint InfSectionWithExtSize, IntPtr RequiredSize, IntPtr Extension, IntPtr Reserved);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SETUPAPI_SetupDiGetActualSectionToInstallExW' -Namespace Win32 -PassThru
# $api::SetupDiGetActualSectionToInstallExW(InfHandle, InfSectionName, AlternatePlatformInfo, InfSectionWithExt, InfSectionWithExtSize, RequiredSize, Extension, Reserved)
#uselib "SETUPAPI.dll"
#func global SetupDiGetActualSectionToInstallExW "SetupDiGetActualSectionToInstallExW" wptr, wptr, wptr, wptr, wptr, wptr, wptr, wptr
; SetupDiGetActualSectionToInstallExW InfHandle, InfSectionName, varptr(AlternatePlatformInfo), varptr(InfSectionWithExt), InfSectionWithExtSize, varptr(RequiredSize), varptr(Extension), Reserved   ; 戻り値は stat
; InfHandle : void* -> "wptr"
; InfSectionName : LPCWSTR -> "wptr"
; AlternatePlatformInfo : SP_ALTPLATFORM_INFO_V2* optional -> "wptr"
; InfSectionWithExt : LPWSTR optional, out -> "wptr"
; InfSectionWithExtSize : DWORD -> "wptr"
; RequiredSize : DWORD* optional, out -> "wptr"
; Extension : LPWSTR* optional, out -> "wptr"
; Reserved : void* optional -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "SETUPAPI.dll"
#cfunc global SetupDiGetActualSectionToInstallExW "SetupDiGetActualSectionToInstallExW" sptr, wstr, var, var, int, var, var, sptr
; res = SetupDiGetActualSectionToInstallExW(InfHandle, InfSectionName, AlternatePlatformInfo, InfSectionWithExt, InfSectionWithExtSize, RequiredSize, Extension, Reserved)
; InfHandle : void* -> "sptr"
; InfSectionName : LPCWSTR -> "wstr"
; AlternatePlatformInfo : SP_ALTPLATFORM_INFO_V2* optional -> "var"
; InfSectionWithExt : LPWSTR optional, out -> "var"
; InfSectionWithExtSize : DWORD -> "int"
; RequiredSize : DWORD* optional, out -> "var"
; Extension : LPWSTR* optional, out -> "var"
; Reserved : void* optional -> "sptr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL SetupDiGetActualSectionToInstallExW(void* InfHandle, LPCWSTR InfSectionName, SP_ALTPLATFORM_INFO_V2* AlternatePlatformInfo, LPWSTR InfSectionWithExt, DWORD InfSectionWithExtSize, DWORD* RequiredSize, LPWSTR* Extension, void* Reserved)
#uselib "SETUPAPI.dll"
#cfunc global SetupDiGetActualSectionToInstallExW "SetupDiGetActualSectionToInstallExW" intptr, wstr, var, var, int, var, var, intptr
; res = SetupDiGetActualSectionToInstallExW(InfHandle, InfSectionName, AlternatePlatformInfo, InfSectionWithExt, InfSectionWithExtSize, RequiredSize, Extension, Reserved)
; InfHandle : void* -> "intptr"
; InfSectionName : LPCWSTR -> "wstr"
; AlternatePlatformInfo : SP_ALTPLATFORM_INFO_V2* optional -> "var"
; InfSectionWithExt : LPWSTR optional, out -> "var"
; InfSectionWithExtSize : DWORD -> "int"
; RequiredSize : DWORD* optional, out -> "var"
; Extension : LPWSTR* optional, out -> "var"
; Reserved : void* optional -> "intptr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	setupapi = windows.NewLazySystemDLL("SETUPAPI.dll")
	procSetupDiGetActualSectionToInstallExW = setupapi.NewProc("SetupDiGetActualSectionToInstallExW")
)

// InfHandle (void*), InfSectionName (LPCWSTR), AlternatePlatformInfo (SP_ALTPLATFORM_INFO_V2* optional), InfSectionWithExt (LPWSTR optional, out), InfSectionWithExtSize (DWORD), RequiredSize (DWORD* optional, out), Extension (LPWSTR* optional, out), Reserved (void* optional)
r1, _, err := procSetupDiGetActualSectionToInstallExW.Call(
	uintptr(InfHandle),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(InfSectionName))),
	uintptr(AlternatePlatformInfo),
	uintptr(InfSectionWithExt),
	uintptr(InfSectionWithExtSize),
	uintptr(RequiredSize),
	uintptr(Extension),
	uintptr(Reserved),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function SetupDiGetActualSectionToInstallExW(
  InfHandle: Pointer;   // void*
  InfSectionName: PWideChar;   // LPCWSTR
  AlternatePlatformInfo: Pointer;   // SP_ALTPLATFORM_INFO_V2* optional
  InfSectionWithExt: PWideChar;   // LPWSTR optional, out
  InfSectionWithExtSize: DWORD;   // DWORD
  RequiredSize: Pointer;   // DWORD* optional, out
  Extension: PPWideChar;   // LPWSTR* optional, out
  Reserved: Pointer   // void* optional
): BOOL; stdcall;
  external 'SETUPAPI.dll' name 'SetupDiGetActualSectionToInstallExW';
result := DllCall("SETUPAPI\SetupDiGetActualSectionToInstallExW"
    , "Ptr", InfHandle   ; void*
    , "WStr", InfSectionName   ; LPCWSTR
    , "Ptr", AlternatePlatformInfo   ; SP_ALTPLATFORM_INFO_V2* optional
    , "Ptr", InfSectionWithExt   ; LPWSTR optional, out
    , "UInt", InfSectionWithExtSize   ; DWORD
    , "Ptr", RequiredSize   ; DWORD* optional, out
    , "Ptr", Extension   ; LPWSTR* optional, out
    , "Ptr", Reserved   ; void* optional
    , "Int")   ; return: BOOL
●SetupDiGetActualSectionToInstallExW(InfHandle, InfSectionName, AlternatePlatformInfo, InfSectionWithExt, InfSectionWithExtSize, RequiredSize, Extension, Reserved) = DLL("SETUPAPI.dll", "bool SetupDiGetActualSectionToInstallExW(void*, char*, void*, char*, dword, void*, void*, void*)")
# 呼び出し: SetupDiGetActualSectionToInstallExW(InfHandle, InfSectionName, AlternatePlatformInfo, InfSectionWithExt, InfSectionWithExtSize, RequiredSize, Extension, Reserved)
# InfHandle : void* -> "void*"
# InfSectionName : LPCWSTR -> "char*"
# AlternatePlatformInfo : SP_ALTPLATFORM_INFO_V2* optional -> "void*"
# InfSectionWithExt : LPWSTR optional, out -> "char*"
# InfSectionWithExtSize : DWORD -> "dword"
# RequiredSize : DWORD* optional, out -> "void*"
# Extension : LPWSTR* optional, out -> "void*"
# Reserved : void* optional -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。
const std = @import("std");

extern "setupapi" fn SetupDiGetActualSectionToInstallExW(
    InfHandle: ?*anyopaque, // void*
    InfSectionName: [*c]const u16, // LPCWSTR
    AlternatePlatformInfo: [*c]SP_ALTPLATFORM_INFO_V2, // SP_ALTPLATFORM_INFO_V2* optional
    InfSectionWithExt: [*c]u16, // LPWSTR optional, out
    InfSectionWithExtSize: u32, // DWORD
    RequiredSize: [*c]u32, // DWORD* optional, out
    Extension: [*c][*c]u16, // LPWSTR* optional, out
    Reserved: ?*anyopaque // void* optional
) callconv(std.os.windows.WINAPI) i32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。
proc SetupDiGetActualSectionToInstallExW(
    InfHandle: pointer,  # void*
    InfSectionName: WideCString,  # LPCWSTR
    AlternatePlatformInfo: ptr SP_ALTPLATFORM_INFO_V2,  # SP_ALTPLATFORM_INFO_V2* optional
    InfSectionWithExt: ptr uint16,  # LPWSTR optional, out
    InfSectionWithExtSize: uint32,  # DWORD
    RequiredSize: ptr uint32,  # DWORD* optional, out
    Extension: ptr WideCString,  # LPWSTR* optional, out
    Reserved: pointer  # void* optional
): int32 {.importc: "SetupDiGetActualSectionToInstallExW", stdcall, dynlib: "SETUPAPI.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。
pragma(lib, "setupapi");
extern(Windows)
int SetupDiGetActualSectionToInstallExW(
    void* InfHandle,   // void*
    const(wchar)* InfSectionName,   // LPCWSTR
    SP_ALTPLATFORM_INFO_V2* AlternatePlatformInfo,   // SP_ALTPLATFORM_INFO_V2* optional
    wchar* InfSectionWithExt,   // LPWSTR optional, out
    uint InfSectionWithExtSize,   // DWORD
    uint* RequiredSize,   // DWORD* optional, out
    wchar** Extension,   // LPWSTR* optional, out
    void* Reserved   // void* optional
);
ccall((:SetupDiGetActualSectionToInstallExW, "SETUPAPI.dll"), stdcall, Int32,
      (Ptr{Cvoid}, Cwstring, Ptr{SP_ALTPLATFORM_INFO_V2}, Ptr{UInt16}, UInt32, Ptr{UInt32}, Ptr{Ptr{UInt16}}, Ptr{Cvoid}),
      InfHandle, InfSectionName, AlternatePlatformInfo, InfSectionWithExt, InfSectionWithExtSize, RequiredSize, Extension, Reserved)
# InfHandle : void* -> Ptr{Cvoid}
# InfSectionName : LPCWSTR -> Cwstring
# AlternatePlatformInfo : SP_ALTPLATFORM_INFO_V2* optional -> Ptr{SP_ALTPLATFORM_INFO_V2}
# InfSectionWithExt : LPWSTR optional, out -> Ptr{UInt16}
# InfSectionWithExtSize : DWORD -> UInt32
# RequiredSize : DWORD* optional, out -> Ptr{UInt32}
# Extension : LPWSTR* optional, out -> Ptr{Ptr{UInt16}}
# Reserved : void* optional -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。
local ffi = require("ffi")
ffi.cdef[[
int32_t SetupDiGetActualSectionToInstallExW(
    void* InfHandle,
    const uint16_t* InfSectionName,
    void* AlternatePlatformInfo,
    uint16_t* InfSectionWithExt,
    uint32_t InfSectionWithExtSize,
    uint32_t* RequiredSize,
    uint16_t** Extension,
    void* Reserved);
]]
local setupapi = ffi.load("setupapi")
-- setupapi.SetupDiGetActualSectionToInstallExW(InfHandle, InfSectionName, AlternatePlatformInfo, InfSectionWithExt, InfSectionWithExtSize, RequiredSize, Extension, Reserved)
-- InfHandle : void*
-- InfSectionName : LPCWSTR
-- AlternatePlatformInfo : SP_ALTPLATFORM_INFO_V2* optional
-- InfSectionWithExt : LPWSTR optional, out
-- InfSectionWithExtSize : DWORD
-- RequiredSize : DWORD* optional, out
-- Extension : LPWSTR* optional, out
-- Reserved : void* optional
-- 構造体/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 SetupDiGetActualSectionToInstallExW = lib.func('__stdcall', 'SetupDiGetActualSectionToInstallExW', 'int32_t', ['void *', 'str16', 'void *', 'uint16_t *', 'uint32_t', 'uint32_t *', 'void *', 'void *']);
// SetupDiGetActualSectionToInstallExW(InfHandle, InfSectionName, AlternatePlatformInfo, InfSectionWithExt, InfSectionWithExtSize, RequiredSize, Extension, Reserved)
// InfHandle : void* -> 'void *'
// InfSectionName : LPCWSTR -> 'str16'
// AlternatePlatformInfo : SP_ALTPLATFORM_INFO_V2* optional -> 'void *'
// InfSectionWithExt : LPWSTR optional, out -> 'uint16_t *'
// InfSectionWithExtSize : DWORD -> 'uint32_t'
// RequiredSize : DWORD* optional, out -> 'uint32_t *'
// Extension : LPWSTR* optional, out -> 'void *'
// Reserved : void* optional -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("SETUPAPI.dll", {
  SetupDiGetActualSectionToInstallExW: { parameters: ["pointer", "buffer", "pointer", "buffer", "u32", "pointer", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.SetupDiGetActualSectionToInstallExW(InfHandle, InfSectionName, AlternatePlatformInfo, InfSectionWithExt, InfSectionWithExtSize, RequiredSize, Extension, Reserved)
// InfHandle : void* -> "pointer"
// InfSectionName : LPCWSTR -> "buffer"
// AlternatePlatformInfo : SP_ALTPLATFORM_INFO_V2* optional -> "pointer"
// InfSectionWithExt : LPWSTR optional, out -> "buffer"
// InfSectionWithExtSize : DWORD -> "u32"
// RequiredSize : DWORD* optional, out -> "pointer"
// Extension : LPWSTR* optional, out -> "pointer"
// Reserved : void* optional -> "pointer"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t SetupDiGetActualSectionToInstallExW(
    void* InfHandle,
    const uint16_t* InfSectionName,
    void* AlternatePlatformInfo,
    uint16_t* InfSectionWithExt,
    uint32_t InfSectionWithExtSize,
    uint32_t* RequiredSize,
    uint16_t** Extension,
    void* Reserved);
C, "SETUPAPI.dll");
// $ffi->SetupDiGetActualSectionToInstallExW(InfHandle, InfSectionName, AlternatePlatformInfo, InfSectionWithExt, InfSectionWithExtSize, RequiredSize, Extension, Reserved);
// InfHandle : void*
// InfSectionName : LPCWSTR
// AlternatePlatformInfo : SP_ALTPLATFORM_INFO_V2* optional
// InfSectionWithExt : LPWSTR optional, out
// InfSectionWithExtSize : DWORD
// RequiredSize : DWORD* optional, out
// Extension : LPWSTR* optional, out
// Reserved : void* 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.UNICODE_OPTIONS);
    boolean SetupDiGetActualSectionToInstallExW(
        Pointer InfHandle,   // void*
        WString InfSectionName,   // LPCWSTR
        Pointer AlternatePlatformInfo,   // SP_ALTPLATFORM_INFO_V2* optional
        char[] InfSectionWithExt,   // LPWSTR optional, out
        int InfSectionWithExtSize,   // DWORD
        IntByReference RequiredSize,   // DWORD* optional, out
        PointerByReference Extension,   // LPWSTR* optional, out
        Pointer Reserved   // void* optional
    );
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。
@[Link("setupapi")]
lib LibSETUPAPI
  fun SetupDiGetActualSectionToInstallExW = SetupDiGetActualSectionToInstallExW(
    InfHandle : Void*,   # void*
    InfSectionName : UInt16*,   # LPCWSTR
    AlternatePlatformInfo : SP_ALTPLATFORM_INFO_V2*,   # SP_ALTPLATFORM_INFO_V2* optional
    InfSectionWithExt : UInt16*,   # LPWSTR optional, out
    InfSectionWithExtSize : UInt32,   # DWORD
    RequiredSize : UInt32*,   # DWORD* optional, out
    Extension : UInt16**,   # LPWSTR* optional, out
    Reserved : Void*   # void* optional
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef SetupDiGetActualSectionToInstallExWNative = Int32 Function(Pointer<Void>, Pointer<Utf16>, Pointer<Void>, Pointer<Utf16>, Uint32, Pointer<Uint32>, Pointer<Pointer<Utf16>>, Pointer<Void>);
typedef SetupDiGetActualSectionToInstallExWDart = int Function(Pointer<Void>, Pointer<Utf16>, Pointer<Void>, Pointer<Utf16>, int, Pointer<Uint32>, Pointer<Pointer<Utf16>>, Pointer<Void>);
final SetupDiGetActualSectionToInstallExW = DynamicLibrary.open('SETUPAPI.dll')
    .lookupFunction<SetupDiGetActualSectionToInstallExWNative, SetupDiGetActualSectionToInstallExWDart>('SetupDiGetActualSectionToInstallExW');
// InfHandle : void* -> Pointer<Void>
// InfSectionName : LPCWSTR -> Pointer<Utf16>
// AlternatePlatformInfo : SP_ALTPLATFORM_INFO_V2* optional -> Pointer<Void>
// InfSectionWithExt : LPWSTR optional, out -> Pointer<Utf16>
// InfSectionWithExtSize : DWORD -> Uint32
// RequiredSize : DWORD* optional, out -> Pointer<Uint32>
// Extension : LPWSTR* optional, out -> Pointer<Pointer<Utf16>>
// Reserved : void* optional -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function SetupDiGetActualSectionToInstallExW(
  InfHandle: Pointer;   // void*
  InfSectionName: PWideChar;   // LPCWSTR
  AlternatePlatformInfo: Pointer;   // SP_ALTPLATFORM_INFO_V2* optional
  InfSectionWithExt: PWideChar;   // LPWSTR optional, out
  InfSectionWithExtSize: DWORD;   // DWORD
  RequiredSize: Pointer;   // DWORD* optional, out
  Extension: PPWideChar;   // LPWSTR* optional, out
  Reserved: Pointer   // void* optional
): BOOL; stdcall;
  external 'SETUPAPI.dll' name 'SetupDiGetActualSectionToInstallExW';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "SetupDiGetActualSectionToInstallExW"
  c_SetupDiGetActualSectionToInstallExW :: Ptr () -> CWString -> Ptr () -> CWString -> Word32 -> Ptr Word32 -> Ptr CWString -> Ptr () -> IO CInt
-- InfHandle : void* -> Ptr ()
-- InfSectionName : LPCWSTR -> CWString
-- AlternatePlatformInfo : SP_ALTPLATFORM_INFO_V2* optional -> Ptr ()
-- InfSectionWithExt : LPWSTR optional, out -> CWString
-- InfSectionWithExtSize : DWORD -> Word32
-- RequiredSize : DWORD* optional, out -> Ptr Word32
-- Extension : LPWSTR* optional, out -> Ptr CWString
-- Reserved : void* optional -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let setupdigetactualsectiontoinstallexw =
  foreign "SetupDiGetActualSectionToInstallExW"
    ((ptr void) @-> (ptr uint16_t) @-> (ptr void) @-> (ptr uint16_t) @-> uint32_t @-> (ptr uint32_t) @-> (ptr (ptr uint16_t)) @-> (ptr void) @-> returning int32_t)
(* InfHandle : void* -> (ptr void) *)
(* InfSectionName : LPCWSTR -> (ptr uint16_t) *)
(* AlternatePlatformInfo : SP_ALTPLATFORM_INFO_V2* optional -> (ptr void) *)
(* InfSectionWithExt : LPWSTR optional, out -> (ptr uint16_t) *)
(* InfSectionWithExtSize : DWORD -> uint32_t *)
(* RequiredSize : DWORD* optional, out -> (ptr uint32_t) *)
(* Extension : LPWSTR* optional, out -> (ptr (ptr uint16_t)) *)
(* Reserved : void* 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 ("SetupDiGetActualSectionToInstallExW" setup-di-get-actual-section-to-install-ex-w :convention :stdcall) :int32
  (inf-handle :pointer)   ; void*
  (inf-section-name (:string :encoding :utf-16le))   ; LPCWSTR
  (alternate-platform-info :pointer)   ; SP_ALTPLATFORM_INFO_V2* optional
  (inf-section-with-ext :pointer)   ; LPWSTR optional, out
  (inf-section-with-ext-size :uint32)   ; DWORD
  (required-size :pointer)   ; DWORD* optional, out
  (extension :pointer)   ; LPWSTR* optional, out
  (reserved :pointer))   ; void* optional
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $SetupDiGetActualSectionToInstallExW = Win32::API::More->new('SETUPAPI',
    'BOOL SetupDiGetActualSectionToInstallExW(LPVOID InfHandle, LPCWSTR InfSectionName, LPVOID AlternatePlatformInfo, LPWSTR InfSectionWithExt, DWORD InfSectionWithExtSize, LPVOID RequiredSize, LPVOID Extension, LPVOID Reserved)');
# my $ret = $SetupDiGetActualSectionToInstallExW->Call($InfHandle, $InfSectionName, $AlternatePlatformInfo, $InfSectionWithExt, $InfSectionWithExtSize, $RequiredSize, $Extension, $Reserved);
# InfHandle : void* -> LPVOID
# InfSectionName : LPCWSTR -> LPCWSTR
# AlternatePlatformInfo : SP_ALTPLATFORM_INFO_V2* optional -> LPVOID
# InfSectionWithExt : LPWSTR optional, out -> LPWSTR
# InfSectionWithExtSize : DWORD -> DWORD
# RequiredSize : DWORD* optional, out -> LPVOID
# Extension : LPWSTR* optional, out -> LPVOID
# Reserved : void* optional -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。

関連項目

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