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

SetupInstallFromInfSectionW

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

シグネチャ

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

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

パラメーター

名前方向説明
OwnerHWNDinoptionalインストール中に生成されるダイアログボックス (ディスクの挿入要求やファイルのコピーなど) を所有するウィンドウのウィンドウハンドルへの省略可能なポインター。Owner を指定しない場合、これらのダイアログボックスはトップレベルウィンドウになります。
InfHandlevoid*in処理対象のセクションを含む INF ファイルのハンドル。
SectionNameLPCWSTRin処理する INF ファイル内の Install セクションの名前。
FlagsDWORDin

実行する動作を制御します。フラグには次の値の組み合わせを指定できます。

SPINST_INIFILES

INI ファイル操作を実行します (処理対象の Install セクション内の UpdateInisUpdateIniFields 行)。

SPINST_REGISTRY

レジストリ操作を実行します (処理対象の Install セクション内の AddRegDelReg 行)。

SPINST_INI2REG

INI ファイルからレジストリへの操作を実行します (処理対象の Install セクション内の Ini2Reg 行)。

SPINST_LOGCONFIG

このフラグは、デバイスドライバーをインストールする場合にのみ使用されます。

論理構成操作を実行します (処理対象の Install セクション内の LogConf 行)。このフラグは、DeviceInfoSetDeviceInfoData が指定されている場合にのみ使用されます。

デバイスドライバーのインストール、LogConfDeviceInfoSetDeviceInfoData の詳細については、DDK の Programmer's Guide を参照してください。

SPINST_FILES

ファイル操作を実行します (処理対象の Install セクション内の CopyFilesDelFilesRenFiles 行)。

SPINST_ALL

すべてのインストール操作を実行します。

SPINST_REGISTERCALLBACKAWARE

Windows 2000 で RegisterDlls INF ディレクティブを使用して DLL を自己登録する場合、SetupInstallFromInfSection の呼び出し元は、各ファイルが登録または登録解除されるたびに通知を受け取ることができます。SPFILENOTIFY_STARTREGISTRATION または SPFILENOTIFY_ENDREGISTRATION の通知をコールバックルーチンへ送信するには、SPINST_REGISTERCALLBACKAWARE に加えて SPINST_REGSVR または SPINST_UNREGSVR のいずれかを指定します。呼び出し元は MsgHandler パラメーターも設定する必要があります。

SPINST_REGSVR

ファイルの登録時にコールバックルーチンへ通知を送信するには、FlagsSPINST_REGISTERCALLBACKAWARESPINST_REGSVR を指定します。呼び出し元は MsgHandler パラメーターも指定する必要があります。

SPINST_UNREGSVR

ファイルの登録解除時にコールバックルーチンへ通知を送信するには、FlagsSPINST_REGISTERCALLBACKAWARESPINST_UNREGSVR を指定します。呼び出し元は MsgHandler パラメーターも指定する必要があります。

RelativeKeyRootHKEYinoptionalFlagsSPINST_REGISTRY または SPINST_INI2REG が含まれる場合に指定する必要がある、省略可能なパラメーター。INF ファイルがキーとして HKR を指定したときに、ルートとして使用されるレジストリキーのハンドルです。SetupInstallFromInfSection を、省略可能な DeviceInfoSetDeviceInfoData を設定して呼び出した場合、このパラメーターは無視されることに注意してください。
SourceRootPathLPCWSTRinoptionalファイルコピーのソースルート。例としては A:\ や \pegasus\win\install があります。FlagsSPINST_FILES が含まれ、SourceRootPath が NULL の場合、システムは既定のルートパスを提供します。
CopyFlagsDWORDin

FlagsSPINST_FILES が含まれる場合に指定する必要がある、省略可能なパラメーター。ファイルがコピー用にキューへ登録されるときに SetupQueueCopySection 関数へ渡すフラグを指定します。これらのフラグには次の値の組み合わせを指定できます。

SP_COPY_DELETESOURCE

コピーに成功した後、ソースファイルを削除します。削除に失敗しても呼び出し元には通知されません。

SP_COPY_REPLACEONLY

コピー先パスにあるファイルを上書きすることになる場合にのみ、ファイルをコピーします。

SP_COPY_NEWER_OR_SAME

コピーする各ファイルについて、そのバージョンリソースが、コピー先にある既存のコピーと同じバージョンであるか、またはそれより新しくないことを示していないかを調べます。

バージョンチェックで使用されるファイルバージョン情報は、バージョン関数によって設定される VS_FIXEDFILEINFO 構造体の dwFileVersionMS メンバーと dwFileVersionLS メンバーで指定された情報です。いずれかのファイルにバージョンリソースがない場合、または両者のバージョン情報が同一の場合、ソースファイルの方が新しいと見なされます。

ソースファイルのバージョンが同じでも新しくもなく、CopyMsgHandler が指定されている場合、呼び出し元に通知され、コピーをキャンセルできます。CopyMsgHandler が指定されていない場合、ファイルはコピーされません。

SP_COPY_NEWER_ONLY

コピーする各ファイルについて、そのバージョンリソースが、コピー先にある既存のコピーより新しくないことを示していないかを調べます。ソースファイルの方が新しく、既存のコピー先とバージョンが一致しない場合、ファイルはコピーされます。

SP_COPY_NOOVERWRITE

コピー先のファイルが存在するかどうかを確認し、存在する場合は呼び出し元に通知して、コピーを拒否できるようにします。CopyMsgHandler が指定されていない場合、ファイルは上書きされません。

SP_COPY_NODECOMP

ファイルを展開しません。このフラグを設定すると、コピー先のファイルには (該当する場合でも) ソース名の非圧縮形式が付けられません。たとえば、f:/x86\cmd.ex_ を \install\temp へコピーすると、コピー先のファイルは \install\temp\cmd.ex_ になります。SP_COPY_NODECOMP フラグを指定しなかった場合、ファイルは展開され、コピー先は \install\temp\cmd.exe という名前になります。DestinationName が指定されている場合、そのファイル名部分は取り除かれ、ソースファイルのファイル名に置き換えられます。SP_COPY_NODECOMP を指定した場合、言語情報やバージョン情報はチェックできません。

SP_COPY_LANGUAGEAWARE

コピーする各ファイルについて、その言語が、コピー先に既に存在するファイルの言語と異なるかどうかを調べます。異なっており、かつ CopyMsgHandler が指定されている場合、呼び出し元に通知され、コピーをキャンセルできます。CopyMsgHandler が指定されていない場合、ファイルはコピーされません。

SP_COPY_SOURCE_ABSOLUTE

SourceFile は完全なソースパスです。INF ファイルの SourceDisksNames セクションでは検索しません。

SP_COPY_SOURCEPATH_ABSOLUTE

SourcePathRoot はソースファイルの完全なパス部分です。ファイルが格納されているソースメディアについて、INF ファイルの SourceDisksNames セクションで指定された相対ソースを無視します。SP_COPY_SOURCE_ABSOLUTE が指定されている場合、このフラグは無視されます。

SP_COPY_FORCE_IN_USE

コピー先が存在する場合、使用中であるかのように動作し、次回のシステム再起動時にコピーするようファイルをキューへ登録します。

SP_COPY_IN_USE_NEEDS_REBOOT

コピー操作中にファイルが使用中だった場合、システムの再起動が必要であることをユーザーに通知します。このフラグは、後で SetupPromptReboot または SetupScanFileQueue を呼び出す場合にのみ使用されます。

SP_COPY_NOSKIP

ファイルをスキップする選択肢をユーザーに提供しません。

SP_COPY_FORCE_NOOVERWRITE

コピー先のファイルが存在するかどうかを確認し、存在する場合はファイルを上書きしません。呼び出し元には通知されません。

SP_COPY_FORCE_NEWER

コピーする各ファイルについて、そのバージョンリソース (イメージファイル以外の場合はタイムスタンプ) が、コピー先にある既存のコピーより新しくないことを示していないかを調べます。コピーするファイルの方が新しくない場合、そのファイルはコピーされません。呼び出し元には通知されません。

SP_COPY_WARNIFSKIP

ユーザーがファイルをスキップしようとした場合に、ファイルをスキップするとインストールに影響する可能性があることを警告します (システムにとって重要なファイルに使用します)。

MsgHandlerPSP_FILE_CALLBACK_Winoptional

コールバックルーチンへのポインター。コールバックルーチンは FileCallback の形式である必要があります。詳細については、Notifications を参照してください。

このパラメーターは、Flags パラメーターに SPINST_FILESSPINST_REGISTERCALLBACKAWARESPINST_REGSVR の組み合わせ、または SPINST_UNREGSVR が含まれない場合にのみ省略できます。

FlagsSPINST_FILES が含まれる場合、MsgHandler を設定する必要があります。この場合、ファイルキューが SetupCommitFileQueue によってコミットされるときに、コールバックルーチンへ通知が送信されます。

FlagsSPINST_REGISTERCALLBACKAWARESPINST_REGSVR または SPINST_UNREGSVR が含まれる場合も、MsgHandler を設定する必要があります。この場合、Windows 2000 で RegisterDlls INF ディレクティブを使用してファイルが登録または登録解除されるたびに、SPFILENOTIFY_STARTREGISTRATION または SPFILENOTIFY_ENDREGISTRATION がコールバックルーチンへ 1 回送信されます。

Contextvoid*inoptionalこのルーチンが内部的に構築したファイルキューが SetupCommitFileQueue によってコミットされるときに、コールバック関数へ渡される値。Context パラメーターは、Flags パラメーターに SPINST_FILES が含まれない場合にのみ省略できます。FlagsSPINST_FILES が含まれる場合、このパラメーターを指定する必要があります。
DeviceInfoSetHDEVINFOinoptionalデバイス情報セットのハンドルへの、省略可能なポインター。Device Installer のセットアップ関数の詳細については、DDK の Programmer's Guide を参照してください。
DeviceInfoDataSP_DEVINFO_DATA*inoptional

DeviceInfoSet で指定されたセット内の特定の要素へのコンテキストを提供する SP_DEVINFO_DATA 構造体へのポインターへの、省略可能なポインター。Device Installer のセットアップ関数の詳細については、DDK の Programmer's Guide を参照してください。

- CopyFlags.SP_COPY_DELETESOURCE

コピーに成功した後、ソースファイルを削除します。削除に失敗しても呼び出し元には通知されません。

- CopyFlags.SP_COPY_FORCE_IN_USE

コピー先が存在する場合、使用中であるかのように動作し、次回のシステム再起動時にコピーするようファイルをキューへ登録します。

- CopyFlags.SP_COPY_FORCE_NEWER

コピーする各ファイルについて、そのバージョンリソース (イメージファイル以外の場合はタイムスタンプ) が、コピー先にある既存のコピーより新しくないことを示していないかを調べます。コピーするファイルの方が新しくない場合、そのファイルはコピーされません。呼び出し元には通知されません。

- CopyFlags.SP_COPY_FORCE_NOOVERWRITE

コピー先のファイルが存在するかどうかを確認し、存在する場合はファイルを上書きしません。呼び出し元には通知されません。

- CopyFlags.SP_COPY_IN_USE_NEEDS_REBOOT

コピー操作中にファイルが使用中だった場合、システムの再起動が必要であることをユーザーに通知します。このフラグは、後で SetupPromptReboot または SetupScanFileQueue を呼び出す場合にのみ使用されます。

- CopyFlags.SP_COPY_LANGUAGEAWARE

コピーする各ファイルについて、その言語が、コピー先に既に存在するファイルの言語と異なるかどうかを調べます。異なっており、かつ CopyMsgHandler が指定されている場合、呼び出し元に通知され、コピーをキャンセルできます。CopyMsgHandler が指定されていない場合、ファイルはコピーされません。

- CopyFlags.SP_COPY_NEWER_ONLY

コピーする各ファイルについて、そのバージョンリソースが、コピー先にある既存のコピーより新しくないことを示していないかを調べます。ソースファイルの方が新しく、既存のコピー先とバージョンが一致しない場合、ファイルはコピーされます。

- CopyFlags.SP_COPY_NEWER_OR_SAME

コピーする各ファイルについて、そのバージョンリソースが、コピー先にある既存のコピーと同じバージョンであるか、またはそれより新しくないことを示していないかを調べます。

バージョンチェックで使用されるファイルバージョン情報は、バージョン関数によって設定される VS_FIXEDFILEINFO 構造体の dwFileVersionMS メンバーと dwFileVersionLS メンバーで指定された情報です。いずれかのファイルにバージョンリソースがない場合、または両者のバージョン情報が同一の場合、ソースファイルの方が新しいと見なされます。

ソースファイルのバージョンが同じでも新しくもなく、CopyMsgHandler が指定されている場合、呼び出し元に通知され、コピーをキャンセルできます。CopyMsgHandler が指定されていない場合、ファイルはコピーされません。

- CopyFlags.SP_COPY_NODECOMP

ファイルを展開しません。このフラグを設定すると、コピー先のファイルには (該当する場合でも) ソース名の非圧縮形式が付けられません。たとえば、f:/x86\cmd.ex_ を \install\temp へコピーすると、コピー先のファイルは \install\temp\cmd.ex_ になります。SP_COPY_NODECOMP フラグを指定しなかった場合、ファイルは展開され、コピー先は \install\temp\cmd.exe という名前になります。DestinationName が指定されている場合、そのファイル名部分は取り除かれ、ソースファイルのファイル名に置き換えられます。SP_COPY_NODECOMP を指定した場合、言語情報やバージョン情報はチェックできません。

- CopyFlags.SP_COPY_NOOVERWRITE

コピー先のファイルが存在するかどうかを確認し、存在する場合は呼び出し元に通知して、コピーを拒否できるようにします。CopyMsgHandler が指定されていない場合、ファイルは上書きされません。

- CopyFlags.SP_COPY_NOSKIP

ファイルをスキップする選択肢をユーザーに提供しません。

- CopyFlags.SP_COPY_REPLACEONLY

コピー先パスにあるファイルを上書きすることになる場合にのみ、ファイルをコピーします。

- CopyFlags.SP_COPY_SOURCEPATH_ABSOLUTE

SourcePathRoot はソースファイルの完全なパス部分です。ファイルが格納されているソースメディアについて、INF ファイルの SourceDisksNames セクションで指定された相対ソースを無視します。SP_COPY_SOURCE_ABSOLUTE が指定されている場合、このフラグは無視されます。

- CopyFlags.SP_COPY_SOURCE_ABSOLUTE

SourceFile は完全なソースパスです。INF ファイルの SourceDisksNames セクションでは検索しません。

- CopyFlags.SP_COPY_WARNIFSKIP

ユーザーがファイルをスキップしようとした場合に、ファイルをスキップするとインストールに影響する可能性があることを警告します (システムにとって重要なファイルに使用します)。

- Flags.SPINST_ALL

すべてのインストール操作を実行します。

- Flags.SPINST_FILES

ファイル操作を実行します (処理対象の Install セクション内の CopyFilesDelFilesRenFiles 行)。

- Flags.SPINST_INI2REG

INI ファイルからレジストリへの操作を実行します (処理対象の Install セクション内の Ini2Reg 行)。

- Flags.SPINST_INIFILES

INI ファイル操作を実行します (処理対象の Install セクション内の UpdateInisUpdateIniFields 行)。

- Flags.SPINST_LOGCONFIG

このフラグは、デバイスドライバーをインストールする場合にのみ使用されます。

論理構成操作を実行します (処理対象の Install セクション内の LogConf 行)。このフラグは、DeviceInfoSetDeviceInfoData が指定されている場合にのみ使用されます。

デバイスドライバーのインストール、LogConfDeviceInfoSetDeviceInfoData の詳細については、DDK の Programmer's Guide を参照してください。

- Flags.SPINST_REGISTERCALLBACKAWARE

Windows 2000 で RegisterDlls INF ディレクティブを使用して DLL を自己登録する場合、SetupInstallFromInfSection の呼び出し元は、各ファイルが登録または登録解除されるたびに通知を受け取ることができます。SPFILENOTIFY_STARTREGISTRATION または SPFILENOTIFY_ENDREGISTRATION の通知をコールバックルーチンへ送信するには、SPINST_REGISTERCALLBACKAWARE に加えて SPINST_REGSVR または SPINST_UNREGSVR のいずれかを指定します。呼び出し元は MsgHandler パラメーターも設定する必要があります。

- Flags.SPINST_REGISTRY

レジストリ操作を実行します (処理対象の Install セクション内の AddRegDelReg 行)。

- Flags.SPINST_REGSVR

ファイルの登録時にコールバックルーチンへ通知を送信するには、FlagsSPINST_REGISTERCALLBACKAWARESPINST_REGSVR を指定します。呼び出し元は MsgHandler パラメーターも指定する必要があります。

- Flags.SPINST_UNREGSVR

ファイルの登録解除時にコールバックルーチンへ通知を送信するには、FlagsSPINST_REGISTERCALLBACKAWARESPINST_UNREGSVR を指定します。呼び出し元は MsgHandler パラメーターも指定する必要があります。

戻り値の型: BOOL

公式ドキュメント

SetupInstallFromInfSection 関数は、INF ファイルの Install セクションにあるすべてのディレクティブを実行します。(Unicode)

戻り値

関数が成功した場合、戻り値は 0 以外の値です。

関数が失敗した場合、戻り値は 0 です。拡張エラー情報を取得するには、GetLastError を呼び出します。

解説(Remarks)

ファイルコピー操作のコピー先ディレクトリとして UNC ディレクトリを指定する場合は、SetupInstallFromInfSection を呼び出す前に、そのディレクトリが存在することを確認する必要があります。セットアップ関数は UNC ディレクトリの存在を確認せず、作成も行いません。コピー先の UNC ディレクトリが存在しない場合、ファイルのインストールは失敗します。

この関数には Windows の INF ファイルが必要です。一部の古い形式の INF ファイルはサポートされない場合があります。

メモ

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

SetupInstallFromInfSection は、診断情報を SetupAPI アプリケーションインストールテキストログ に記録します。このログファイルは通常、既定では無効になっています。SetupAPI のログレベルの設定 で説明されているとおり、SetupAPI の LogLevel 値のうち 全般的なログレベル の部分を変更することで有効にできます。パフォーマンス上の理由から、このログファイルは問題のトラブルシューティング時にのみ有効にしてください。ログファイルを有効にすると、%windir%\inf\setupapi.app.log にログが出力されます。

出典・ライセンス: 上記「公式ドキュメント」の内容は 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 SetupInstallFromInfSectionW(
    HWND Owner,   // optional
    void* InfHandle,
    LPCWSTR SectionName,
    DWORD Flags,
    HKEY RelativeKeyRoot,   // optional
    LPCWSTR SourceRootPath,   // optional
    DWORD CopyFlags,
    PSP_FILE_CALLBACK_W MsgHandler,   // optional
    void* Context,   // optional
    HDEVINFO DeviceInfoSet,   // optional
    SP_DEVINFO_DATA* DeviceInfoData   // optional
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("SETUPAPI.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern bool SetupInstallFromInfSectionW(
    IntPtr Owner,   // HWND optional
    IntPtr InfHandle,   // void*
    [MarshalAs(UnmanagedType.LPWStr)] string SectionName,   // LPCWSTR
    uint Flags,   // DWORD
    IntPtr RelativeKeyRoot,   // HKEY optional
    [MarshalAs(UnmanagedType.LPWStr)] string SourceRootPath,   // LPCWSTR optional
    uint CopyFlags,   // DWORD
    IntPtr MsgHandler,   // PSP_FILE_CALLBACK_W optional
    IntPtr Context,   // void* optional
    IntPtr DeviceInfoSet,   // HDEVINFO optional
    IntPtr DeviceInfoData   // SP_DEVINFO_DATA* optional
);
<DllImport("SETUPAPI.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetupInstallFromInfSectionW(
    Owner As IntPtr,   ' HWND optional
    InfHandle As IntPtr,   ' void*
    <MarshalAs(UnmanagedType.LPWStr)> SectionName As String,   ' LPCWSTR
    Flags As UInteger,   ' DWORD
    RelativeKeyRoot As IntPtr,   ' HKEY optional
    <MarshalAs(UnmanagedType.LPWStr)> SourceRootPath As String,   ' LPCWSTR optional
    CopyFlags As UInteger,   ' DWORD
    MsgHandler As IntPtr,   ' PSP_FILE_CALLBACK_W 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 : LPCWSTR
' Flags : DWORD
' RelativeKeyRoot : HKEY optional
' SourceRootPath : LPCWSTR optional
' CopyFlags : DWORD
' MsgHandler : PSP_FILE_CALLBACK_W optional
' Context : void* optional
' DeviceInfoSet : HDEVINFO optional
' DeviceInfoData : SP_DEVINFO_DATA* optional
Declare PtrSafe Function SetupInstallFromInfSectionW Lib "setupapi" ( _
    ByVal Owner As LongPtr, _
    ByVal InfHandle As LongPtr, _
    ByVal SectionName As LongPtr, _
    ByVal Flags As Long, _
    ByVal RelativeKeyRoot As LongPtr, _
    ByVal SourceRootPath As LongPtr, _
    ByVal CopyFlags As Long, _
    ByVal MsgHandler As LongPtr, _
    ByVal Context As LongPtr, _
    ByVal DeviceInfoSet As LongPtr, _
    ByVal DeviceInfoData 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

SetupInstallFromInfSectionW = ctypes.windll.setupapi.SetupInstallFromInfSectionW
SetupInstallFromInfSectionW.restype = wintypes.BOOL
SetupInstallFromInfSectionW.argtypes = [
    wintypes.HANDLE,  # Owner : HWND optional
    ctypes.POINTER(None),  # InfHandle : void*
    wintypes.LPCWSTR,  # SectionName : LPCWSTR
    wintypes.DWORD,  # Flags : DWORD
    wintypes.HANDLE,  # RelativeKeyRoot : HKEY optional
    wintypes.LPCWSTR,  # SourceRootPath : LPCWSTR optional
    wintypes.DWORD,  # CopyFlags : DWORD
    ctypes.c_void_p,  # MsgHandler : PSP_FILE_CALLBACK_W 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')
SetupInstallFromInfSectionW = Fiddle::Function.new(
  lib['SetupInstallFromInfSectionW'],
  [
    Fiddle::TYPE_VOIDP,  # Owner : HWND optional
    Fiddle::TYPE_VOIDP,  # InfHandle : void*
    Fiddle::TYPE_VOIDP,  # SectionName : LPCWSTR
    -Fiddle::TYPE_INT,  # Flags : DWORD
    Fiddle::TYPE_VOIDP,  # RelativeKeyRoot : HKEY optional
    Fiddle::TYPE_VOIDP,  # SourceRootPath : LPCWSTR optional
    -Fiddle::TYPE_INT,  # CopyFlags : DWORD
    Fiddle::TYPE_VOIDP,  # MsgHandler : PSP_FILE_CALLBACK_W 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)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "setupapi")]
extern "system" {
    fn SetupInstallFromInfSectionW(
        Owner: *mut core::ffi::c_void,  // HWND optional
        InfHandle: *mut (),  // void*
        SectionName: *const u16,  // LPCWSTR
        Flags: u32,  // DWORD
        RelativeKeyRoot: *mut core::ffi::c_void,  // HKEY optional
        SourceRootPath: *const u16,  // LPCWSTR optional
        CopyFlags: u32,  // DWORD
        MsgHandler: *const core::ffi::c_void,  // PSP_FILE_CALLBACK_W 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.Unicode, SetLastError = true)]
public static extern bool SetupInstallFromInfSectionW(IntPtr Owner, IntPtr InfHandle, [MarshalAs(UnmanagedType.LPWStr)] string SectionName, uint Flags, IntPtr RelativeKeyRoot, [MarshalAs(UnmanagedType.LPWStr)] string SourceRootPath, uint CopyFlags, IntPtr MsgHandler, IntPtr Context, IntPtr DeviceInfoSet, IntPtr DeviceInfoData);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SETUPAPI_SetupInstallFromInfSectionW' -Namespace Win32 -PassThru
# $api::SetupInstallFromInfSectionW(Owner, InfHandle, SectionName, Flags, RelativeKeyRoot, SourceRootPath, CopyFlags, MsgHandler, Context, DeviceInfoSet, DeviceInfoData)
#uselib "SETUPAPI.dll"
#func global SetupInstallFromInfSectionW "SetupInstallFromInfSectionW" wptr, wptr, wptr, wptr, wptr, wptr, wptr, wptr, wptr, wptr, wptr
; SetupInstallFromInfSectionW Owner, InfHandle, SectionName, Flags, RelativeKeyRoot, SourceRootPath, CopyFlags, MsgHandler, Context, DeviceInfoSet, varptr(DeviceInfoData)   ; 戻り値は stat
; Owner : HWND optional -> "wptr"
; InfHandle : void* -> "wptr"
; SectionName : LPCWSTR -> "wptr"
; Flags : DWORD -> "wptr"
; RelativeKeyRoot : HKEY optional -> "wptr"
; SourceRootPath : LPCWSTR optional -> "wptr"
; CopyFlags : DWORD -> "wptr"
; MsgHandler : PSP_FILE_CALLBACK_W optional -> "wptr"
; Context : void* optional -> "wptr"
; DeviceInfoSet : HDEVINFO optional -> "wptr"
; DeviceInfoData : SP_DEVINFO_DATA* optional -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "SETUPAPI.dll"
#cfunc global SetupInstallFromInfSectionW "SetupInstallFromInfSectionW" sptr, sptr, wstr, int, sptr, wstr, int, sptr, sptr, sptr, var
; res = SetupInstallFromInfSectionW(Owner, InfHandle, SectionName, Flags, RelativeKeyRoot, SourceRootPath, CopyFlags, MsgHandler, Context, DeviceInfoSet, DeviceInfoData)
; Owner : HWND optional -> "sptr"
; InfHandle : void* -> "sptr"
; SectionName : LPCWSTR -> "wstr"
; Flags : DWORD -> "int"
; RelativeKeyRoot : HKEY optional -> "sptr"
; SourceRootPath : LPCWSTR optional -> "wstr"
; CopyFlags : DWORD -> "int"
; MsgHandler : PSP_FILE_CALLBACK_W optional -> "sptr"
; Context : void* optional -> "sptr"
; DeviceInfoSet : HDEVINFO optional -> "sptr"
; DeviceInfoData : SP_DEVINFO_DATA* optional -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL SetupInstallFromInfSectionW(HWND Owner, void* InfHandle, LPCWSTR SectionName, DWORD Flags, HKEY RelativeKeyRoot, LPCWSTR SourceRootPath, DWORD CopyFlags, PSP_FILE_CALLBACK_W MsgHandler, void* Context, HDEVINFO DeviceInfoSet, SP_DEVINFO_DATA* DeviceInfoData)
#uselib "SETUPAPI.dll"
#cfunc global SetupInstallFromInfSectionW "SetupInstallFromInfSectionW" intptr, intptr, wstr, int, intptr, wstr, int, intptr, intptr, intptr, var
; res = SetupInstallFromInfSectionW(Owner, InfHandle, SectionName, Flags, RelativeKeyRoot, SourceRootPath, CopyFlags, MsgHandler, Context, DeviceInfoSet, DeviceInfoData)
; Owner : HWND optional -> "intptr"
; InfHandle : void* -> "intptr"
; SectionName : LPCWSTR -> "wstr"
; Flags : DWORD -> "int"
; RelativeKeyRoot : HKEY optional -> "intptr"
; SourceRootPath : LPCWSTR optional -> "wstr"
; CopyFlags : DWORD -> "int"
; MsgHandler : PSP_FILE_CALLBACK_W 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")
	procSetupInstallFromInfSectionW = setupapi.NewProc("SetupInstallFromInfSectionW")
)

// Owner (HWND optional), InfHandle (void*), SectionName (LPCWSTR), Flags (DWORD), RelativeKeyRoot (HKEY optional), SourceRootPath (LPCWSTR optional), CopyFlags (DWORD), MsgHandler (PSP_FILE_CALLBACK_W optional), Context (void* optional), DeviceInfoSet (HDEVINFO optional), DeviceInfoData (SP_DEVINFO_DATA* optional)
r1, _, err := procSetupInstallFromInfSectionW.Call(
	uintptr(Owner),
	uintptr(InfHandle),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(SectionName))),
	uintptr(Flags),
	uintptr(RelativeKeyRoot),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(SourceRootPath))),
	uintptr(CopyFlags),
	uintptr(MsgHandler),
	uintptr(Context),
	uintptr(DeviceInfoSet),
	uintptr(DeviceInfoData),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function SetupInstallFromInfSectionW(
  Owner: THandle;   // HWND optional
  InfHandle: Pointer;   // void*
  SectionName: PWideChar;   // LPCWSTR
  Flags: DWORD;   // DWORD
  RelativeKeyRoot: THandle;   // HKEY optional
  SourceRootPath: PWideChar;   // LPCWSTR optional
  CopyFlags: DWORD;   // DWORD
  MsgHandler: Pointer;   // PSP_FILE_CALLBACK_W optional
  Context: Pointer;   // void* optional
  DeviceInfoSet: NativeInt;   // HDEVINFO optional
  DeviceInfoData: Pointer   // SP_DEVINFO_DATA* optional
): BOOL; stdcall;
  external 'SETUPAPI.dll' name 'SetupInstallFromInfSectionW';
result := DllCall("SETUPAPI\SetupInstallFromInfSectionW"
    , "Ptr", Owner   ; HWND optional
    , "Ptr", InfHandle   ; void*
    , "WStr", SectionName   ; LPCWSTR
    , "UInt", Flags   ; DWORD
    , "Ptr", RelativeKeyRoot   ; HKEY optional
    , "WStr", SourceRootPath   ; LPCWSTR optional
    , "UInt", CopyFlags   ; DWORD
    , "Ptr", MsgHandler   ; PSP_FILE_CALLBACK_W optional
    , "Ptr", Context   ; void* optional
    , "Ptr", DeviceInfoSet   ; HDEVINFO optional
    , "Ptr", DeviceInfoData   ; SP_DEVINFO_DATA* optional
    , "Int")   ; return: BOOL
●SetupInstallFromInfSectionW(Owner, InfHandle, SectionName, Flags, RelativeKeyRoot, SourceRootPath, CopyFlags, MsgHandler, Context, DeviceInfoSet, DeviceInfoData) = DLL("SETUPAPI.dll", "bool SetupInstallFromInfSectionW(void*, void*, char*, dword, void*, char*, dword, void*, void*, int, void*)")
# 呼び出し: SetupInstallFromInfSectionW(Owner, InfHandle, SectionName, Flags, RelativeKeyRoot, SourceRootPath, CopyFlags, MsgHandler, Context, DeviceInfoSet, DeviceInfoData)
# Owner : HWND optional -> "void*"
# InfHandle : void* -> "void*"
# SectionName : LPCWSTR -> "char*"
# Flags : DWORD -> "dword"
# RelativeKeyRoot : HKEY optional -> "void*"
# SourceRootPath : LPCWSTR optional -> "char*"
# CopyFlags : DWORD -> "dword"
# MsgHandler : PSP_FILE_CALLBACK_W 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)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。
const std = @import("std");

extern "setupapi" fn SetupInstallFromInfSectionW(
    Owner: ?*anyopaque, // HWND optional
    InfHandle: ?*anyopaque, // void*
    SectionName: [*c]const u16, // LPCWSTR
    Flags: u32, // DWORD
    RelativeKeyRoot: ?*anyopaque, // HKEY optional
    SourceRootPath: [*c]const u16, // LPCWSTR optional
    CopyFlags: u32, // DWORD
    MsgHandler: ?*anyopaque, // PSP_FILE_CALLBACK_W optional
    Context: ?*anyopaque, // void* optional
    DeviceInfoSet: isize, // HDEVINFO optional
    DeviceInfoData: [*c]SP_DEVINFO_DATA // SP_DEVINFO_DATA* optional
) callconv(std.os.windows.WINAPI) i32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。
proc SetupInstallFromInfSectionW(
    Owner: pointer,  # HWND optional
    InfHandle: pointer,  # void*
    SectionName: WideCString,  # LPCWSTR
    Flags: uint32,  # DWORD
    RelativeKeyRoot: pointer,  # HKEY optional
    SourceRootPath: WideCString,  # LPCWSTR optional
    CopyFlags: uint32,  # DWORD
    MsgHandler: pointer,  # PSP_FILE_CALLBACK_W optional
    Context: pointer,  # void* optional
    DeviceInfoSet: int,  # HDEVINFO optional
    DeviceInfoData: ptr SP_DEVINFO_DATA  # SP_DEVINFO_DATA* optional
): int32 {.importc: "SetupInstallFromInfSectionW", stdcall, dynlib: "SETUPAPI.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。
pragma(lib, "setupapi");
extern(Windows)
int SetupInstallFromInfSectionW(
    void* Owner,   // HWND optional
    void* InfHandle,   // void*
    const(wchar)* SectionName,   // LPCWSTR
    uint Flags,   // DWORD
    void* RelativeKeyRoot,   // HKEY optional
    const(wchar)* SourceRootPath,   // LPCWSTR optional
    uint CopyFlags,   // DWORD
    void* MsgHandler,   // PSP_FILE_CALLBACK_W optional
    void* Context,   // void* optional
    ptrdiff_t DeviceInfoSet,   // HDEVINFO optional
    SP_DEVINFO_DATA* DeviceInfoData   // SP_DEVINFO_DATA* optional
);
ccall((:SetupInstallFromInfSectionW, "SETUPAPI.dll"), stdcall, Int32,
      (Ptr{Cvoid}, Ptr{Cvoid}, Cwstring, UInt32, Ptr{Cvoid}, Cwstring, 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 : LPCWSTR -> Cwstring
# Flags : DWORD -> UInt32
# RelativeKeyRoot : HKEY optional -> Ptr{Cvoid}
# SourceRootPath : LPCWSTR optional -> Cwstring
# CopyFlags : DWORD -> UInt32
# MsgHandler : PSP_FILE_CALLBACK_W optional -> Ptr{Cvoid}
# Context : void* optional -> Ptr{Cvoid}
# DeviceInfoSet : HDEVINFO optional -> Int
# DeviceInfoData : SP_DEVINFO_DATA* optional -> Ptr{SP_DEVINFO_DATA}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。
local ffi = require("ffi")
ffi.cdef[[
int32_t SetupInstallFromInfSectionW(
    void* Owner,
    void* InfHandle,
    const uint16_t* SectionName,
    uint32_t Flags,
    void* RelativeKeyRoot,
    const uint16_t* SourceRootPath,
    uint32_t CopyFlags,
    void* MsgHandler,
    void* Context,
    intptr_t DeviceInfoSet,
    void* DeviceInfoData);
]]
local setupapi = ffi.load("setupapi")
-- setupapi.SetupInstallFromInfSectionW(Owner, InfHandle, SectionName, Flags, RelativeKeyRoot, SourceRootPath, CopyFlags, MsgHandler, Context, DeviceInfoSet, DeviceInfoData)
-- Owner : HWND optional
-- InfHandle : void*
-- SectionName : LPCWSTR
-- Flags : DWORD
-- RelativeKeyRoot : HKEY optional
-- SourceRootPath : LPCWSTR optional
-- CopyFlags : DWORD
-- MsgHandler : PSP_FILE_CALLBACK_W optional
-- Context : void* optional
-- DeviceInfoSet : HDEVINFO optional
-- DeviceInfoData : SP_DEVINFO_DATA* 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 SetupInstallFromInfSectionW = lib.func('__stdcall', 'SetupInstallFromInfSectionW', 'int32_t', ['void *', 'void *', 'str16', 'uint32_t', 'void *', 'str16', 'uint32_t', 'void *', 'void *', 'intptr_t', 'void *']);
// SetupInstallFromInfSectionW(Owner, InfHandle, SectionName, Flags, RelativeKeyRoot, SourceRootPath, CopyFlags, MsgHandler, Context, DeviceInfoSet, DeviceInfoData)
// Owner : HWND optional -> 'void *'
// InfHandle : void* -> 'void *'
// SectionName : LPCWSTR -> 'str16'
// Flags : DWORD -> 'uint32_t'
// RelativeKeyRoot : HKEY optional -> 'void *'
// SourceRootPath : LPCWSTR optional -> 'str16'
// CopyFlags : DWORD -> 'uint32_t'
// MsgHandler : PSP_FILE_CALLBACK_W 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", {
  SetupInstallFromInfSectionW: { parameters: ["pointer", "pointer", "buffer", "u32", "pointer", "buffer", "u32", "pointer", "pointer", "isize", "pointer"], result: "i32" },
});
// lib.symbols.SetupInstallFromInfSectionW(Owner, InfHandle, SectionName, Flags, RelativeKeyRoot, SourceRootPath, CopyFlags, MsgHandler, Context, DeviceInfoSet, DeviceInfoData)
// Owner : HWND optional -> "pointer"
// InfHandle : void* -> "pointer"
// SectionName : LPCWSTR -> "buffer"
// Flags : DWORD -> "u32"
// RelativeKeyRoot : HKEY optional -> "pointer"
// SourceRootPath : LPCWSTR optional -> "buffer"
// CopyFlags : DWORD -> "u32"
// MsgHandler : PSP_FILE_CALLBACK_W optional -> "pointer"
// Context : void* optional -> "pointer"
// DeviceInfoSet : HDEVINFO optional -> "isize"
// DeviceInfoData : SP_DEVINFO_DATA* optional -> "pointer"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t SetupInstallFromInfSectionW(
    void* Owner,
    void* InfHandle,
    const uint16_t* SectionName,
    uint32_t Flags,
    void* RelativeKeyRoot,
    const uint16_t* SourceRootPath,
    uint32_t CopyFlags,
    void* MsgHandler,
    void* Context,
    intptr_t DeviceInfoSet,
    void* DeviceInfoData);
C, "SETUPAPI.dll");
// $ffi->SetupInstallFromInfSectionW(Owner, InfHandle, SectionName, Flags, RelativeKeyRoot, SourceRootPath, CopyFlags, MsgHandler, Context, DeviceInfoSet, DeviceInfoData);
// Owner : HWND optional
// InfHandle : void*
// SectionName : LPCWSTR
// Flags : DWORD
// RelativeKeyRoot : HKEY optional
// SourceRootPath : LPCWSTR optional
// CopyFlags : DWORD
// MsgHandler : PSP_FILE_CALLBACK_W 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.UNICODE_OPTIONS);
    boolean SetupInstallFromInfSectionW(
        Pointer Owner,   // HWND optional
        Pointer InfHandle,   // void*
        WString SectionName,   // LPCWSTR
        int Flags,   // DWORD
        Pointer RelativeKeyRoot,   // HKEY optional
        WString SourceRootPath,   // LPCWSTR optional
        int CopyFlags,   // DWORD
        Callback MsgHandler,   // PSP_FILE_CALLBACK_W optional
        Pointer Context,   // void* optional
        long DeviceInfoSet,   // HDEVINFO optional
        Pointer DeviceInfoData   // SP_DEVINFO_DATA* optional
    );
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。
@[Link("setupapi")]
lib LibSETUPAPI
  fun SetupInstallFromInfSectionW = SetupInstallFromInfSectionW(
    Owner : Void*,   # HWND optional
    InfHandle : Void*,   # void*
    SectionName : UInt16*,   # LPCWSTR
    Flags : UInt32,   # DWORD
    RelativeKeyRoot : Void*,   # HKEY optional
    SourceRootPath : UInt16*,   # LPCWSTR optional
    CopyFlags : UInt32,   # DWORD
    MsgHandler : Void*,   # PSP_FILE_CALLBACK_W 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 SetupInstallFromInfSectionWNative = Int32 Function(Pointer<Void>, Pointer<Void>, Pointer<Utf16>, Uint32, Pointer<Void>, Pointer<Utf16>, Uint32, Pointer<Void>, Pointer<Void>, IntPtr, Pointer<Void>);
typedef SetupInstallFromInfSectionWDart = int Function(Pointer<Void>, Pointer<Void>, Pointer<Utf16>, int, Pointer<Void>, Pointer<Utf16>, int, Pointer<Void>, Pointer<Void>, int, Pointer<Void>);
final SetupInstallFromInfSectionW = DynamicLibrary.open('SETUPAPI.dll')
    .lookupFunction<SetupInstallFromInfSectionWNative, SetupInstallFromInfSectionWDart>('SetupInstallFromInfSectionW');
// Owner : HWND optional -> Pointer<Void>
// InfHandle : void* -> Pointer<Void>
// SectionName : LPCWSTR -> Pointer<Utf16>
// Flags : DWORD -> Uint32
// RelativeKeyRoot : HKEY optional -> Pointer<Void>
// SourceRootPath : LPCWSTR optional -> Pointer<Utf16>
// CopyFlags : DWORD -> Uint32
// MsgHandler : PSP_FILE_CALLBACK_W 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 SetupInstallFromInfSectionW(
  Owner: THandle;   // HWND optional
  InfHandle: Pointer;   // void*
  SectionName: PWideChar;   // LPCWSTR
  Flags: DWORD;   // DWORD
  RelativeKeyRoot: THandle;   // HKEY optional
  SourceRootPath: PWideChar;   // LPCWSTR optional
  CopyFlags: DWORD;   // DWORD
  MsgHandler: Pointer;   // PSP_FILE_CALLBACK_W optional
  Context: Pointer;   // void* optional
  DeviceInfoSet: NativeInt;   // HDEVINFO optional
  DeviceInfoData: Pointer   // SP_DEVINFO_DATA* optional
): BOOL; stdcall;
  external 'SETUPAPI.dll' name 'SetupInstallFromInfSectionW';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "SetupInstallFromInfSectionW"
  c_SetupInstallFromInfSectionW :: Ptr () -> Ptr () -> CWString -> Word32 -> Ptr () -> CWString -> Word32 -> Ptr () -> Ptr () -> CIntPtr -> Ptr () -> IO CInt
-- Owner : HWND optional -> Ptr ()
-- InfHandle : void* -> Ptr ()
-- SectionName : LPCWSTR -> CWString
-- Flags : DWORD -> Word32
-- RelativeKeyRoot : HKEY optional -> Ptr ()
-- SourceRootPath : LPCWSTR optional -> CWString
-- CopyFlags : DWORD -> Word32
-- MsgHandler : PSP_FILE_CALLBACK_W 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 setupinstallfrominfsectionw =
  foreign "SetupInstallFromInfSectionW"
    ((ptr void) @-> (ptr void) @-> (ptr uint16_t) @-> uint32_t @-> (ptr void) @-> (ptr uint16_t) @-> uint32_t @-> (ptr void) @-> (ptr void) @-> intptr_t @-> (ptr void) @-> returning int32_t)
(* Owner : HWND optional -> (ptr void) *)
(* InfHandle : void* -> (ptr void) *)
(* SectionName : LPCWSTR -> (ptr uint16_t) *)
(* Flags : DWORD -> uint32_t *)
(* RelativeKeyRoot : HKEY optional -> (ptr void) *)
(* SourceRootPath : LPCWSTR optional -> (ptr uint16_t) *)
(* CopyFlags : DWORD -> uint32_t *)
(* MsgHandler : PSP_FILE_CALLBACK_W 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 ("SetupInstallFromInfSectionW" setup-install-from-inf-section-w :convention :stdcall) :int32
  (owner :pointer)   ; HWND optional
  (inf-handle :pointer)   ; void*
  (section-name (:string :encoding :utf-16le))   ; LPCWSTR
  (flags :uint32)   ; DWORD
  (relative-key-root :pointer)   ; HKEY optional
  (source-root-path (:string :encoding :utf-16le))   ; LPCWSTR optional
  (copy-flags :uint32)   ; DWORD
  (msg-handler :pointer)   ; PSP_FILE_CALLBACK_W 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 $SetupInstallFromInfSectionW = Win32::API::More->new('SETUPAPI',
    'BOOL SetupInstallFromInfSectionW(HANDLE Owner, LPVOID InfHandle, LPCWSTR SectionName, DWORD Flags, HANDLE RelativeKeyRoot, LPCWSTR SourceRootPath, DWORD CopyFlags, LPVOID MsgHandler, LPVOID Context, LPARAM DeviceInfoSet, LPVOID DeviceInfoData)');
# my $ret = $SetupInstallFromInfSectionW->Call($Owner, $InfHandle, $SectionName, $Flags, $RelativeKeyRoot, $SourceRootPath, $CopyFlags, $MsgHandler, $Context, $DeviceInfoSet, $DeviceInfoData);
# Owner : HWND optional -> HANDLE
# InfHandle : void* -> LPVOID
# SectionName : LPCWSTR -> LPCWSTR
# Flags : DWORD -> DWORD
# RelativeKeyRoot : HKEY optional -> HANDLE
# SourceRootPath : LPCWSTR optional -> LPCWSTR
# CopyFlags : DWORD -> DWORD
# MsgHandler : PSP_FILE_CALLBACK_W 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 を使用してください。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。

関連項目

文字セット違い
公式の関連項目
使用する型