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

SetupDiGetActualSectionToInstallW

関数
INFでインストールに使用する実際のセクション名を取得する。
DLLSETUPAPI.dll文字セットUnicode (-W)呼出規約winapiSetLastErrorあり対応OSWindows 2000 以降

シグネチャ

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

BOOL SetupDiGetActualSectionToInstallW(
    void* InfHandle,
    LPCWSTR InfSectionName,
    LPWSTR InfSectionWithExt,   // optional
    DWORD InfSectionWithExtSize,
    DWORD* RequiredSize,   // optional
    LPWSTR* Extension   // optional
);

パラメーター

名前方向説明
InfHandlevoid*inDDInstall セクションを含む INF ファイルのハンドル。
InfSectionNameLPCWSTRinDDInstall セクション名(INF Models セクションで指定されたもの)へのポインター。セクション名の最大長は 254 文字です。
InfSectionWithExtLPWSTRoutoptionalDDInstall セクション名、そのプラットフォーム拡張、および NULL 終端文字を受け取る文字バッファーへのポインター。これはインストールに使用すべき装飾付きのセクション名です。このパラメーターが NULL の場合、InfSectionWithExtSize は 0 でなければなりません。このパラメーターが NULL の場合、関数は TRUE を返し、DDInstall セクション名、そのプラットフォーム拡張、および終端の NULL 文字を返すために必要なサイズ(文字数単位)を RequiredSize に設定します。
InfSectionWithExtSizeDWORDinInfSectionWithExt バッファーのサイズ(文字数単位)。InfSectionWithExtNULL の場合、このパラメーターは 0 でなければなりません。
RequiredSizeDWORD*outoptionalDDInstall セクション名、プラットフォーム拡張、および終端の NULL 文字を返すために必要なサイズ(文字数単位)を受け取る変数へのポインター。
ExtensionLPWSTR*outoptionalInfSectionWithExt バッファー内で拡張の開始を示す '.' 文字へのポインターを受け取る変数へのポインター。InfSectionWithExt バッファーが指定されていない場合、または小さすぎる場合、このパラメーターは設定されません。拡張へのポインターが不要な場合は、このパラメーターに NULL を設定してください。

戻り値の型: BOOL

公式ドキュメント

SetupDiGetActualSectionToInstall 関数は、ローカルコンピューター上でデバイス INF ファイルからデバイスをインストールする際に使用する、適切な INF DDInstall セクションを取得します。(Unicode)

戻り値

関数が成功した場合は TRUE を返します。関数が失敗した場合は FALSE を返します。拡張エラー情報を取得するには、GetLastError を呼び出します。

解説(Remarks)

この関数は、デバイスの OS 固有およびアーキテクチャ固有のインストール動作を指定するために使用される、DDInstall セクション名の拡張をサポートします。これらの拡張については、「Creating INF Files for Multiple Platforms and Operating Systems」を参照してください。SetupDiGetActualSectionToInstall は、以下に説明する方法でローカルコンピューターに一致する DDInstall セクション名を検索します。

関数はまず、指定された INF ファイル内で、指定された名前に一致し、かつローカルコンピューターのオペレーティングシステムとプロセッサアーキテクチャに一致する拡張を持つ、装飾付きのインストールセクション名を検索します。たとえば、セクション名として InstallSec を指定した場合、関数はローカルコンピューターのプロセッサアーキテクチャに応じて、次の装飾付き名のいずれかを検索します。

名前、オペレーティングシステム、およびプロセッサアーキテクチャの一致が見つかった場合、関数は検索を終了し、対応する装飾付き名を返します。そのような一致が見つからない場合、関数は名前が InstallSec.NT であるセクションを検索します。InstallSec.NT の一致が見つかった場合、関数は検索を終了し、この名前を返します。上記のいずれの検索でも一致が見つからない場合、関数は InstallSec を返しますが、INF ファイルに InstallSec という名前のインストールセクションが含まれているかどうかは確認しません。

DDInstall セクション名は、Hardware セクション名および Services セクション名のベースとして使用されます。たとえば、見つかった DDInstall セクション名が InstallSec.NTX86 である場合、Services セクション名は InstallSec.NTX86.Services という名前でなければなりません。

ドライバーノードで指定された元の DDInstall セクション名は、ドライバーのレジストリキーの InfSection 値エントリに書き込まれます。見つかった拡張は、REG_SZInfSectionExt としてそのキーに格納されます。例:

InfSection       : REG_SZ :    "InstallSec"
InfSectionExt    : REG_SZ :    ".NTX86"

指定されたデバイス情報要素に対してドライバーが選択されていない場合は、null ドライバーがインストールされます。関数から戻ると、デバイスの SP_DEVINSTALL_PARAMS 構造体のフラグが、デバイスを開始するためにシステムの再起動またはリブートが必要かどうかを示します。

メモ

setupapi.h ヘッダーは、UNICODE プリプロセッサ定数の定義に基づいてこの関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして SetupDiGetActualSectionToInstall を定義しています。エンコーディング中立のエイリアスの使用を、エンコーディング中立でないコードと混在させると、コンパイルエラーや実行時エラーの原因となる不一致が発生する可能性があります。詳細については、「Conventions for Function Prototypes」を参照してください。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

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

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

SetupDiGetActualSectionToInstallW = ctypes.windll.setupapi.SetupDiGetActualSectionToInstallW
SetupDiGetActualSectionToInstallW.restype = wintypes.BOOL
SetupDiGetActualSectionToInstallW.argtypes = [
    ctypes.POINTER(None),  # InfHandle : void*
    wintypes.LPCWSTR,  # InfSectionName : LPCWSTR
    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
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

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

var (
	setupapi = windows.NewLazySystemDLL("SETUPAPI.dll")
	procSetupDiGetActualSectionToInstallW = setupapi.NewProc("SetupDiGetActualSectionToInstallW")
)

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

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

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

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

let setupdigetactualsectiontoinstallw =
  foreign "SetupDiGetActualSectionToInstallW"
    ((ptr void) @-> (ptr uint16_t) @-> (ptr uint16_t) @-> uint32_t @-> (ptr uint32_t) @-> (ptr (ptr uint16_t)) @-> returning int32_t)
(* InfHandle : void* -> (ptr void) *)
(* InfSectionName : LPCWSTR -> (ptr uint16_t) *)
(* 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)) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library setupapi (t "SETUPAPI.dll"))
(cffi:use-foreign-library setupapi)

(cffi:defcfun ("SetupDiGetActualSectionToInstallW" setup-di-get-actual-section-to-install-w :convention :stdcall) :int32
  (inf-handle :pointer)   ; void*
  (inf-section-name (:string :encoding :utf-16le))   ; LPCWSTR
  (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
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $SetupDiGetActualSectionToInstallW = Win32::API::More->new('SETUPAPI',
    'BOOL SetupDiGetActualSectionToInstallW(LPVOID InfHandle, LPCWSTR InfSectionName, LPWSTR InfSectionWithExt, DWORD InfSectionWithExtSize, LPVOID RequiredSize, LPVOID Extension)');
# my $ret = $SetupDiGetActualSectionToInstallW->Call($InfHandle, $InfSectionName, $InfSectionWithExt, $InfSectionWithExtSize, $RequiredSize, $Extension);
# InfHandle : void* -> LPVOID
# InfSectionName : LPCWSTR -> LPCWSTR
# InfSectionWithExt : LPWSTR optional, out -> LPWSTR
# InfSectionWithExtSize : DWORD -> DWORD
# RequiredSize : DWORD* optional, out -> LPVOID
# Extension : LPWSTR* optional, out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。

関連項目

文字セット違い
類似 API
公式の関連項目