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

SetupPromptForDiskA

関数
ソースディスクの挿入を求めるダイアログを表示する(ANSI)。
DLLSETUPAPI.dll文字セットANSI (-A)呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

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

DWORD SetupPromptForDiskA(
    HWND hwndParent,
    LPCSTR DialogTitle,   // optional
    LPCSTR DiskName,   // optional
    LPCSTR PathToSource,   // optional
    LPCSTR FileSought,
    LPCSTR TagFile,   // optional
    DWORD DiskPromptStyle,
    LPSTR PathBuffer,   // optional
    DWORD PathBufferSize,
    DWORD* PathRequiredSize   // optional
);

パラメーター

名前方向説明
hwndParentHWNDinダイアログの親ウィンドウハンドル。NULL可。
DialogTitleLPCSTRinoptionalダイアログのタイトル文字列(ANSI)。NULLで既定値を使う。
DiskNameLPCSTRinoptional要求するディスク/メディアの表示名(ANSI)。NULL可。
PathToSourceLPCSTRinoptionalソースの既定検索パス(ANSI)。NULL可。
FileSoughtLPCSTRin存在確認の対象ファイル名(ANSI)。
TagFileLPCSTRinoptionalメディア識別用のタグファイル名(ANSI)。NULL可。
DiskPromptStyleDWORDinダイアログの表示動作を制御するスタイルフラグ。
PathBufferLPSTRoutoptionalユーザーが選択したソースパスを受け取るバッファ(ANSI)。NULLでサイズ取得のみ可。
PathBufferSizeDWORDinPathBufferのサイズ(文字数)。
PathRequiredSizeDWORD*outoptionalパスに必要なバッファサイズを受け取る出力ポインタ。NULL可。

戻り値の型: DWORD

各言語での呼び出し定義

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

DWORD SetupPromptForDiskA(
    HWND hwndParent,
    LPCSTR DialogTitle,   // optional
    LPCSTR DiskName,   // optional
    LPCSTR PathToSource,   // optional
    LPCSTR FileSought,
    LPCSTR TagFile,   // optional
    DWORD DiskPromptStyle,
    LPSTR PathBuffer,   // optional
    DWORD PathBufferSize,
    DWORD* PathRequiredSize   // optional
);
[DllImport("SETUPAPI.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern uint SetupPromptForDiskA(
    IntPtr hwndParent,   // HWND
    [MarshalAs(UnmanagedType.LPStr)] string DialogTitle,   // LPCSTR optional
    [MarshalAs(UnmanagedType.LPStr)] string DiskName,   // LPCSTR optional
    [MarshalAs(UnmanagedType.LPStr)] string PathToSource,   // LPCSTR optional
    [MarshalAs(UnmanagedType.LPStr)] string FileSought,   // LPCSTR
    [MarshalAs(UnmanagedType.LPStr)] string TagFile,   // LPCSTR optional
    uint DiskPromptStyle,   // DWORD
    [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder PathBuffer,   // LPSTR optional, out
    uint PathBufferSize,   // DWORD
    IntPtr PathRequiredSize   // DWORD* optional, out
);
<DllImport("SETUPAPI.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetupPromptForDiskA(
    hwndParent As IntPtr,   ' HWND
    <MarshalAs(UnmanagedType.LPStr)> DialogTitle As String,   ' LPCSTR optional
    <MarshalAs(UnmanagedType.LPStr)> DiskName As String,   ' LPCSTR optional
    <MarshalAs(UnmanagedType.LPStr)> PathToSource As String,   ' LPCSTR optional
    <MarshalAs(UnmanagedType.LPStr)> FileSought As String,   ' LPCSTR
    <MarshalAs(UnmanagedType.LPStr)> TagFile As String,   ' LPCSTR optional
    DiskPromptStyle As UInteger,   ' DWORD
    <MarshalAs(UnmanagedType.LPStr)> PathBuffer As System.Text.StringBuilder,   ' LPSTR optional, out
    PathBufferSize As UInteger,   ' DWORD
    PathRequiredSize As IntPtr   ' DWORD* optional, out
) As UInteger
End Function
' hwndParent : HWND
' DialogTitle : LPCSTR optional
' DiskName : LPCSTR optional
' PathToSource : LPCSTR optional
' FileSought : LPCSTR
' TagFile : LPCSTR optional
' DiskPromptStyle : DWORD
' PathBuffer : LPSTR optional, out
' PathBufferSize : DWORD
' PathRequiredSize : DWORD* optional, out
Declare PtrSafe Function SetupPromptForDiskA Lib "setupapi" ( _
    ByVal hwndParent As LongPtr, _
    ByVal DialogTitle As String, _
    ByVal DiskName As String, _
    ByVal PathToSource As String, _
    ByVal FileSought As String, _
    ByVal TagFile As String, _
    ByVal DiskPromptStyle As Long, _
    ByVal PathBuffer As String, _
    ByVal PathBufferSize As Long, _
    ByVal PathRequiredSize As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SetupPromptForDiskA = ctypes.windll.setupapi.SetupPromptForDiskA
SetupPromptForDiskA.restype = wintypes.DWORD
SetupPromptForDiskA.argtypes = [
    wintypes.HANDLE,  # hwndParent : HWND
    wintypes.LPCSTR,  # DialogTitle : LPCSTR optional
    wintypes.LPCSTR,  # DiskName : LPCSTR optional
    wintypes.LPCSTR,  # PathToSource : LPCSTR optional
    wintypes.LPCSTR,  # FileSought : LPCSTR
    wintypes.LPCSTR,  # TagFile : LPCSTR optional
    wintypes.DWORD,  # DiskPromptStyle : DWORD
    wintypes.LPSTR,  # PathBuffer : LPSTR optional, out
    wintypes.DWORD,  # PathBufferSize : DWORD
    ctypes.POINTER(wintypes.DWORD),  # PathRequiredSize : DWORD* optional, out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('SETUPAPI.dll')
SetupPromptForDiskA = Fiddle::Function.new(
  lib['SetupPromptForDiskA'],
  [
    Fiddle::TYPE_VOIDP,  # hwndParent : HWND
    Fiddle::TYPE_VOIDP,  # DialogTitle : LPCSTR optional
    Fiddle::TYPE_VOIDP,  # DiskName : LPCSTR optional
    Fiddle::TYPE_VOIDP,  # PathToSource : LPCSTR optional
    Fiddle::TYPE_VOIDP,  # FileSought : LPCSTR
    Fiddle::TYPE_VOIDP,  # TagFile : LPCSTR optional
    -Fiddle::TYPE_INT,  # DiskPromptStyle : DWORD
    Fiddle::TYPE_VOIDP,  # PathBuffer : LPSTR optional, out
    -Fiddle::TYPE_INT,  # PathBufferSize : DWORD
    Fiddle::TYPE_VOIDP,  # PathRequiredSize : DWORD* optional, out
  ],
  -Fiddle::TYPE_INT)
#[link(name = "setupapi")]
extern "system" {
    fn SetupPromptForDiskA(
        hwndParent: *mut core::ffi::c_void,  // HWND
        DialogTitle: *const u8,  // LPCSTR optional
        DiskName: *const u8,  // LPCSTR optional
        PathToSource: *const u8,  // LPCSTR optional
        FileSought: *const u8,  // LPCSTR
        TagFile: *const u8,  // LPCSTR optional
        DiskPromptStyle: u32,  // DWORD
        PathBuffer: *mut u8,  // LPSTR optional, out
        PathBufferSize: u32,  // DWORD
        PathRequiredSize: *mut u32  // DWORD* optional, out
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("SETUPAPI.dll", CharSet = CharSet.Ansi, SetLastError = true)]
public static extern uint SetupPromptForDiskA(IntPtr hwndParent, [MarshalAs(UnmanagedType.LPStr)] string DialogTitle, [MarshalAs(UnmanagedType.LPStr)] string DiskName, [MarshalAs(UnmanagedType.LPStr)] string PathToSource, [MarshalAs(UnmanagedType.LPStr)] string FileSought, [MarshalAs(UnmanagedType.LPStr)] string TagFile, uint DiskPromptStyle, [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder PathBuffer, uint PathBufferSize, IntPtr PathRequiredSize);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SETUPAPI_SetupPromptForDiskA' -Namespace Win32 -PassThru
# $api::SetupPromptForDiskA(hwndParent, DialogTitle, DiskName, PathToSource, FileSought, TagFile, DiskPromptStyle, PathBuffer, PathBufferSize, PathRequiredSize)
#uselib "SETUPAPI.dll"
#func global SetupPromptForDiskA "SetupPromptForDiskA" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; SetupPromptForDiskA hwndParent, DialogTitle, DiskName, PathToSource, FileSought, TagFile, DiskPromptStyle, varptr(PathBuffer), PathBufferSize, varptr(PathRequiredSize)   ; 戻り値は stat
; hwndParent : HWND -> "sptr"
; DialogTitle : LPCSTR optional -> "sptr"
; DiskName : LPCSTR optional -> "sptr"
; PathToSource : LPCSTR optional -> "sptr"
; FileSought : LPCSTR -> "sptr"
; TagFile : LPCSTR optional -> "sptr"
; DiskPromptStyle : DWORD -> "sptr"
; PathBuffer : LPSTR optional, out -> "sptr"
; PathBufferSize : DWORD -> "sptr"
; PathRequiredSize : DWORD* optional, out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "SETUPAPI.dll"
#cfunc global SetupPromptForDiskA "SetupPromptForDiskA" sptr, str, str, str, str, str, int, var, int, var
; res = SetupPromptForDiskA(hwndParent, DialogTitle, DiskName, PathToSource, FileSought, TagFile, DiskPromptStyle, PathBuffer, PathBufferSize, PathRequiredSize)
; hwndParent : HWND -> "sptr"
; DialogTitle : LPCSTR optional -> "str"
; DiskName : LPCSTR optional -> "str"
; PathToSource : LPCSTR optional -> "str"
; FileSought : LPCSTR -> "str"
; TagFile : LPCSTR optional -> "str"
; DiskPromptStyle : DWORD -> "int"
; PathBuffer : LPSTR optional, out -> "var"
; PathBufferSize : DWORD -> "int"
; PathRequiredSize : DWORD* optional, out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; DWORD SetupPromptForDiskA(HWND hwndParent, LPCSTR DialogTitle, LPCSTR DiskName, LPCSTR PathToSource, LPCSTR FileSought, LPCSTR TagFile, DWORD DiskPromptStyle, LPSTR PathBuffer, DWORD PathBufferSize, DWORD* PathRequiredSize)
#uselib "SETUPAPI.dll"
#cfunc global SetupPromptForDiskA "SetupPromptForDiskA" intptr, str, str, str, str, str, int, var, int, var
; res = SetupPromptForDiskA(hwndParent, DialogTitle, DiskName, PathToSource, FileSought, TagFile, DiskPromptStyle, PathBuffer, PathBufferSize, PathRequiredSize)
; hwndParent : HWND -> "intptr"
; DialogTitle : LPCSTR optional -> "str"
; DiskName : LPCSTR optional -> "str"
; PathToSource : LPCSTR optional -> "str"
; FileSought : LPCSTR -> "str"
; TagFile : LPCSTR optional -> "str"
; DiskPromptStyle : DWORD -> "int"
; PathBuffer : LPSTR optional, out -> "var"
; PathBufferSize : DWORD -> "int"
; PathRequiredSize : DWORD* optional, out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	setupapi = windows.NewLazySystemDLL("SETUPAPI.dll")
	procSetupPromptForDiskA = setupapi.NewProc("SetupPromptForDiskA")
)

// hwndParent (HWND), DialogTitle (LPCSTR optional), DiskName (LPCSTR optional), PathToSource (LPCSTR optional), FileSought (LPCSTR), TagFile (LPCSTR optional), DiskPromptStyle (DWORD), PathBuffer (LPSTR optional, out), PathBufferSize (DWORD), PathRequiredSize (DWORD* optional, out)
r1, _, err := procSetupPromptForDiskA.Call(
	uintptr(hwndParent),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(DialogTitle))),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(DiskName))),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(PathToSource))),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(FileSought))),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(TagFile))),
	uintptr(DiskPromptStyle),
	uintptr(PathBuffer),
	uintptr(PathBufferSize),
	uintptr(PathRequiredSize),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function SetupPromptForDiskA(
  hwndParent: THandle;   // HWND
  DialogTitle: PAnsiChar;   // LPCSTR optional
  DiskName: PAnsiChar;   // LPCSTR optional
  PathToSource: PAnsiChar;   // LPCSTR optional
  FileSought: PAnsiChar;   // LPCSTR
  TagFile: PAnsiChar;   // LPCSTR optional
  DiskPromptStyle: DWORD;   // DWORD
  PathBuffer: PAnsiChar;   // LPSTR optional, out
  PathBufferSize: DWORD;   // DWORD
  PathRequiredSize: Pointer   // DWORD* optional, out
): DWORD; stdcall;
  external 'SETUPAPI.dll' name 'SetupPromptForDiskA';
result := DllCall("SETUPAPI\SetupPromptForDiskA"
    , "Ptr", hwndParent   ; HWND
    , "AStr", DialogTitle   ; LPCSTR optional
    , "AStr", DiskName   ; LPCSTR optional
    , "AStr", PathToSource   ; LPCSTR optional
    , "AStr", FileSought   ; LPCSTR
    , "AStr", TagFile   ; LPCSTR optional
    , "UInt", DiskPromptStyle   ; DWORD
    , "Ptr", PathBuffer   ; LPSTR optional, out
    , "UInt", PathBufferSize   ; DWORD
    , "Ptr", PathRequiredSize   ; DWORD* optional, out
    , "UInt")   ; return: DWORD
●SetupPromptForDiskA(hwndParent, DialogTitle, DiskName, PathToSource, FileSought, TagFile, DiskPromptStyle, PathBuffer, PathBufferSize, PathRequiredSize) = DLL("SETUPAPI.dll", "dword SetupPromptForDiskA(void*, char*, char*, char*, char*, char*, dword, char*, dword, void*)")
# 呼び出し: SetupPromptForDiskA(hwndParent, DialogTitle, DiskName, PathToSource, FileSought, TagFile, DiskPromptStyle, PathBuffer, PathBufferSize, PathRequiredSize)
# hwndParent : HWND -> "void*"
# DialogTitle : LPCSTR optional -> "char*"
# DiskName : LPCSTR optional -> "char*"
# PathToSource : LPCSTR optional -> "char*"
# FileSought : LPCSTR -> "char*"
# TagFile : LPCSTR optional -> "char*"
# DiskPromptStyle : DWORD -> "dword"
# PathBuffer : LPSTR optional, out -> "char*"
# PathBufferSize : DWORD -> "dword"
# PathRequiredSize : DWORD* optional, out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "setupapi" fn SetupPromptForDiskA(
    hwndParent: ?*anyopaque, // HWND
    DialogTitle: [*c]const u8, // LPCSTR optional
    DiskName: [*c]const u8, // LPCSTR optional
    PathToSource: [*c]const u8, // LPCSTR optional
    FileSought: [*c]const u8, // LPCSTR
    TagFile: [*c]const u8, // LPCSTR optional
    DiskPromptStyle: u32, // DWORD
    PathBuffer: [*c]u8, // LPSTR optional, out
    PathBufferSize: u32, // DWORD
    PathRequiredSize: [*c]u32 // DWORD* optional, out
) callconv(std.os.windows.WINAPI) u32;
proc SetupPromptForDiskA(
    hwndParent: pointer,  # HWND
    DialogTitle: cstring,  # LPCSTR optional
    DiskName: cstring,  # LPCSTR optional
    PathToSource: cstring,  # LPCSTR optional
    FileSought: cstring,  # LPCSTR
    TagFile: cstring,  # LPCSTR optional
    DiskPromptStyle: uint32,  # DWORD
    PathBuffer: ptr char,  # LPSTR optional, out
    PathBufferSize: uint32,  # DWORD
    PathRequiredSize: ptr uint32  # DWORD* optional, out
): uint32 {.importc: "SetupPromptForDiskA", stdcall, dynlib: "SETUPAPI.dll".}
pragma(lib, "setupapi");
extern(Windows)
uint SetupPromptForDiskA(
    void* hwndParent,   // HWND
    const(char)* DialogTitle,   // LPCSTR optional
    const(char)* DiskName,   // LPCSTR optional
    const(char)* PathToSource,   // LPCSTR optional
    const(char)* FileSought,   // LPCSTR
    const(char)* TagFile,   // LPCSTR optional
    uint DiskPromptStyle,   // DWORD
    char* PathBuffer,   // LPSTR optional, out
    uint PathBufferSize,   // DWORD
    uint* PathRequiredSize   // DWORD* optional, out
);
ccall((:SetupPromptForDiskA, "SETUPAPI.dll"), stdcall, UInt32,
      (Ptr{Cvoid}, Cstring, Cstring, Cstring, Cstring, Cstring, UInt32, Ptr{UInt8}, UInt32, Ptr{UInt32}),
      hwndParent, DialogTitle, DiskName, PathToSource, FileSought, TagFile, DiskPromptStyle, PathBuffer, PathBufferSize, PathRequiredSize)
# hwndParent : HWND -> Ptr{Cvoid}
# DialogTitle : LPCSTR optional -> Cstring
# DiskName : LPCSTR optional -> Cstring
# PathToSource : LPCSTR optional -> Cstring
# FileSought : LPCSTR -> Cstring
# TagFile : LPCSTR optional -> Cstring
# DiskPromptStyle : DWORD -> UInt32
# PathBuffer : LPSTR optional, out -> Ptr{UInt8}
# PathBufferSize : DWORD -> UInt32
# PathRequiredSize : DWORD* optional, out -> Ptr{UInt32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
uint32_t SetupPromptForDiskA(
    void* hwndParent,
    const char* DialogTitle,
    const char* DiskName,
    const char* PathToSource,
    const char* FileSought,
    const char* TagFile,
    uint32_t DiskPromptStyle,
    char* PathBuffer,
    uint32_t PathBufferSize,
    uint32_t* PathRequiredSize);
]]
local setupapi = ffi.load("setupapi")
-- setupapi.SetupPromptForDiskA(hwndParent, DialogTitle, DiskName, PathToSource, FileSought, TagFile, DiskPromptStyle, PathBuffer, PathBufferSize, PathRequiredSize)
-- hwndParent : HWND
-- DialogTitle : LPCSTR optional
-- DiskName : LPCSTR optional
-- PathToSource : LPCSTR optional
-- FileSought : LPCSTR
-- TagFile : LPCSTR optional
-- DiskPromptStyle : DWORD
-- PathBuffer : LPSTR optional, out
-- PathBufferSize : DWORD
-- PathRequiredSize : DWORD* optional, out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('SETUPAPI.dll');
const SetupPromptForDiskA = lib.func('__stdcall', 'SetupPromptForDiskA', 'uint32_t', ['void *', 'str', 'str', 'str', 'str', 'str', 'uint32_t', 'char *', 'uint32_t', 'uint32_t *']);
// SetupPromptForDiskA(hwndParent, DialogTitle, DiskName, PathToSource, FileSought, TagFile, DiskPromptStyle, PathBuffer, PathBufferSize, PathRequiredSize)
// hwndParent : HWND -> 'void *'
// DialogTitle : LPCSTR optional -> 'str'
// DiskName : LPCSTR optional -> 'str'
// PathToSource : LPCSTR optional -> 'str'
// FileSought : LPCSTR -> 'str'
// TagFile : LPCSTR optional -> 'str'
// DiskPromptStyle : DWORD -> 'uint32_t'
// PathBuffer : LPSTR optional, out -> 'char *'
// PathBufferSize : DWORD -> 'uint32_t'
// PathRequiredSize : DWORD* optional, out -> 'uint32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("SETUPAPI.dll", {
  SetupPromptForDiskA: { parameters: ["pointer", "buffer", "buffer", "buffer", "buffer", "buffer", "u32", "buffer", "u32", "pointer"], result: "u32" },
});
// lib.symbols.SetupPromptForDiskA(hwndParent, DialogTitle, DiskName, PathToSource, FileSought, TagFile, DiskPromptStyle, PathBuffer, PathBufferSize, PathRequiredSize)
// hwndParent : HWND -> "pointer"
// DialogTitle : LPCSTR optional -> "buffer"
// DiskName : LPCSTR optional -> "buffer"
// PathToSource : LPCSTR optional -> "buffer"
// FileSought : LPCSTR -> "buffer"
// TagFile : LPCSTR optional -> "buffer"
// DiskPromptStyle : DWORD -> "u32"
// PathBuffer : LPSTR optional, out -> "buffer"
// PathBufferSize : DWORD -> "u32"
// PathRequiredSize : DWORD* optional, out -> "pointer"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
uint32_t SetupPromptForDiskA(
    void* hwndParent,
    const char* DialogTitle,
    const char* DiskName,
    const char* PathToSource,
    const char* FileSought,
    const char* TagFile,
    uint32_t DiskPromptStyle,
    char* PathBuffer,
    uint32_t PathBufferSize,
    uint32_t* PathRequiredSize);
C, "SETUPAPI.dll");
// $ffi->SetupPromptForDiskA(hwndParent, DialogTitle, DiskName, PathToSource, FileSought, TagFile, DiskPromptStyle, PathBuffer, PathBufferSize, PathRequiredSize);
// hwndParent : HWND
// DialogTitle : LPCSTR optional
// DiskName : LPCSTR optional
// PathToSource : LPCSTR optional
// FileSought : LPCSTR
// TagFile : LPCSTR optional
// DiskPromptStyle : DWORD
// PathBuffer : LPSTR optional, out
// PathBufferSize : DWORD
// PathRequiredSize : DWORD* 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.ASCII_OPTIONS);
    int SetupPromptForDiskA(
        Pointer hwndParent,   // HWND
        String DialogTitle,   // LPCSTR optional
        String DiskName,   // LPCSTR optional
        String PathToSource,   // LPCSTR optional
        String FileSought,   // LPCSTR
        String TagFile,   // LPCSTR optional
        int DiskPromptStyle,   // DWORD
        byte[] PathBuffer,   // LPSTR optional, out
        int PathBufferSize,   // DWORD
        IntByReference PathRequiredSize   // DWORD* optional, out
    );
}
@[Link("setupapi")]
lib LibSETUPAPI
  fun SetupPromptForDiskA = SetupPromptForDiskA(
    hwndParent : Void*,   # HWND
    DialogTitle : UInt8*,   # LPCSTR optional
    DiskName : UInt8*,   # LPCSTR optional
    PathToSource : UInt8*,   # LPCSTR optional
    FileSought : UInt8*,   # LPCSTR
    TagFile : UInt8*,   # LPCSTR optional
    DiskPromptStyle : UInt32,   # DWORD
    PathBuffer : UInt8*,   # LPSTR optional, out
    PathBufferSize : UInt32,   # DWORD
    PathRequiredSize : UInt32*   # DWORD* optional, out
  ) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef SetupPromptForDiskANative = Uint32 Function(Pointer<Void>, Pointer<Utf8>, Pointer<Utf8>, Pointer<Utf8>, Pointer<Utf8>, Pointer<Utf8>, Uint32, Pointer<Utf8>, Uint32, Pointer<Uint32>);
typedef SetupPromptForDiskADart = int Function(Pointer<Void>, Pointer<Utf8>, Pointer<Utf8>, Pointer<Utf8>, Pointer<Utf8>, Pointer<Utf8>, int, Pointer<Utf8>, int, Pointer<Uint32>);
final SetupPromptForDiskA = DynamicLibrary.open('SETUPAPI.dll')
    .lookupFunction<SetupPromptForDiskANative, SetupPromptForDiskADart>('SetupPromptForDiskA');
// hwndParent : HWND -> Pointer<Void>
// DialogTitle : LPCSTR optional -> Pointer<Utf8>
// DiskName : LPCSTR optional -> Pointer<Utf8>
// PathToSource : LPCSTR optional -> Pointer<Utf8>
// FileSought : LPCSTR -> Pointer<Utf8>
// TagFile : LPCSTR optional -> Pointer<Utf8>
// DiskPromptStyle : DWORD -> Uint32
// PathBuffer : LPSTR optional, out -> Pointer<Utf8>
// PathBufferSize : DWORD -> Uint32
// PathRequiredSize : DWORD* optional, out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function SetupPromptForDiskA(
  hwndParent: THandle;   // HWND
  DialogTitle: PAnsiChar;   // LPCSTR optional
  DiskName: PAnsiChar;   // LPCSTR optional
  PathToSource: PAnsiChar;   // LPCSTR optional
  FileSought: PAnsiChar;   // LPCSTR
  TagFile: PAnsiChar;   // LPCSTR optional
  DiskPromptStyle: DWORD;   // DWORD
  PathBuffer: PAnsiChar;   // LPSTR optional, out
  PathBufferSize: DWORD;   // DWORD
  PathRequiredSize: Pointer   // DWORD* optional, out
): DWORD; stdcall;
  external 'SETUPAPI.dll' name 'SetupPromptForDiskA';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "SetupPromptForDiskA"
  c_SetupPromptForDiskA :: Ptr () -> CString -> CString -> CString -> CString -> CString -> Word32 -> CString -> Word32 -> Ptr Word32 -> IO Word32
-- hwndParent : HWND -> Ptr ()
-- DialogTitle : LPCSTR optional -> CString
-- DiskName : LPCSTR optional -> CString
-- PathToSource : LPCSTR optional -> CString
-- FileSought : LPCSTR -> CString
-- TagFile : LPCSTR optional -> CString
-- DiskPromptStyle : DWORD -> Word32
-- PathBuffer : LPSTR optional, out -> CString
-- PathBufferSize : DWORD -> Word32
-- PathRequiredSize : DWORD* optional, out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let setuppromptfordiska =
  foreign "SetupPromptForDiskA"
    ((ptr void) @-> string @-> string @-> string @-> string @-> string @-> uint32_t @-> string @-> uint32_t @-> (ptr uint32_t) @-> returning uint32_t)
(* hwndParent : HWND -> (ptr void) *)
(* DialogTitle : LPCSTR optional -> string *)
(* DiskName : LPCSTR optional -> string *)
(* PathToSource : LPCSTR optional -> string *)
(* FileSought : LPCSTR -> string *)
(* TagFile : LPCSTR optional -> string *)
(* DiskPromptStyle : DWORD -> uint32_t *)
(* PathBuffer : LPSTR optional, out -> string *)
(* PathBufferSize : DWORD -> uint32_t *)
(* PathRequiredSize : DWORD* optional, out -> (ptr uint32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library setupapi (t "SETUPAPI.dll"))
(cffi:use-foreign-library setupapi)

(cffi:defcfun ("SetupPromptForDiskA" setup-prompt-for-disk-a :convention :stdcall) :uint32
  (hwnd-parent :pointer)   ; HWND
  (dialog-title :string)   ; LPCSTR optional
  (disk-name :string)   ; LPCSTR optional
  (path-to-source :string)   ; LPCSTR optional
  (file-sought :string)   ; LPCSTR
  (tag-file :string)   ; LPCSTR optional
  (disk-prompt-style :uint32)   ; DWORD
  (path-buffer :pointer)   ; LPSTR optional, out
  (path-buffer-size :uint32)   ; DWORD
  (path-required-size :pointer))   ; DWORD* optional, out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $SetupPromptForDiskA = Win32::API::More->new('SETUPAPI',
    'DWORD SetupPromptForDiskA(HANDLE hwndParent, LPCSTR DialogTitle, LPCSTR DiskName, LPCSTR PathToSource, LPCSTR FileSought, LPCSTR TagFile, DWORD DiskPromptStyle, LPSTR PathBuffer, DWORD PathBufferSize, LPVOID PathRequiredSize)');
# my $ret = $SetupPromptForDiskA->Call($hwndParent, $DialogTitle, $DiskName, $PathToSource, $FileSought, $TagFile, $DiskPromptStyle, $PathBuffer, $PathBufferSize, $PathRequiredSize);
# hwndParent : HWND -> HANDLE
# DialogTitle : LPCSTR optional -> LPCSTR
# DiskName : LPCSTR optional -> LPCSTR
# PathToSource : LPCSTR optional -> LPCSTR
# FileSought : LPCSTR -> LPCSTR
# TagFile : LPCSTR optional -> LPCSTR
# DiskPromptStyle : DWORD -> DWORD
# PathBuffer : LPSTR optional, out -> LPSTR
# PathBufferSize : DWORD -> DWORD
# PathRequiredSize : DWORD* optional, out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

文字セット違い