Win32 API 日本語リファレンス
ホームSystem.ApplicationInstallationAndServicing › MsiEnumComponentCostsA

MsiEnumComponentCostsA

関数
コンポーネントのドライブ別ディスクコストを列挙する(ANSI版)。
DLLmsi.dll文字セットANSI (-A)呼出規約winapi対応OSwindows8.0

シグネチャ

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

DWORD MsiEnumComponentCostsA(
    MSIHANDLE hInstall,
    LPCSTR szComponent,
    DWORD dwIndex,
    INSTALLSTATE iState,
    LPSTR szDriveBuf,
    DWORD* pcchDriveBuf,
    INT* piCost,
    INT* piTempCost
);

パラメーター

名前方向説明
hInstallMSIHANDLEinDLL カスタムアクションに提供された、または MsiOpenPackageMsiOpenPackageExMsiOpenProduct を通じて取得したインストールへのハンドル。
szComponentLPCSTRinComponent テーブルの Component 列に記載されているコンポーネント名を指定する null 終端文字列。このパラメーターは null にできます。szComponent が null または空文字列の場合、 MsiEnumComponentCosts はインストール中に使用されるドライブごとの合計ディスク容量を列挙します。この場合、iState は無視されます。インストーラーのコストには、データベースをセキュアフォルダーにキャッシュするためのコストや、インストールスクリプトを作成するためのコストが含まれます。なお、インストール中に使用される合計ディスク容量は、コンポーネントのインストール後に使用される容量よりも大きくなる場合があります。
dwIndexDWORDinドライブの 0 から始まるインデックス。このパラメーターは、 MsiEnumComponentCosts 関数の最初の呼び出しでは 0 とし、それ以降の呼び出しでは増分する必要があります。
iStateINSTALLSTATEin列挙するコンポーネントの要求状態。szComponent に Null または空文字列が渡された場合、インストーラーは iState パラメーターを無視します。
szDriveBufLPSTRoutnull 終端文字を含むドライブ名を格納するバッファー。エラーが発生した場合は空文字列になります。
pcchDriveBufDWORD*inoutlpDriveBuf パラメーターが指すバッファーのサイズを TCHAR 単位で指定する変数へのポインター。このサイズには終端の null 文字を含める必要があります。指定したバッファーが小さすぎる場合、pcchDriveBuf が指す変数には、null 終端文字を含まない文字数が格納されます。
piCostINT*out512 バイトの倍数で表される、ドライブごとのコンポーネントのコスト。エラーが発生した場合、この値は 0 になります。piCost で返される値は、インストール後にコンポーネントが使用する最終的なディスク容量です。szComponent に Null または空文字列が渡された場合、インストーラーは piCost の値を 0 に設定します。
piTempCostINT*outインストール期間中のドライブごとのコンポーネントのコスト。エラーが発生した場合は 0 になります。*piTempCost の値は、インストール期間中に必要となる一時的な容量を表します。この一時的な容量要件は、インストール期間中のみ必要となる容量です。これは最終的なディスク容量要件には影響しません。

戻り値の型: DWORD

公式ドキュメント

MsiEnumComponentCosts 関数は、コンポーネントのインストールに必要なドライブごとのディスク容量を列挙します。(ANSI)

戻り値

戻り値 意味
ERROR_INVALID_HANDLE_STATE
構成データが破損しています。
ERROR_INVALID_PARAMETER
無効なパラメーターが関数に渡されました。
ERROR_NO_MORE_ITEMS
返すドライブがこれ以上ありません。
ERROR_SUCCESS
値が列挙されました。
ERROR_UNKNOWN_COMPONENT
コンポーネントが見つかりません。
ERROR_FUNCTION_NOT_CALLED
コスト計算が完了していません。
ERROR_MORE_DATA
ドライブ名に対してバッファーが十分な大きさではありません。
ERROR_INVALID_HANDLE
指定されたハンドルが無効または非アクティブです。

解説(Remarks)

ドライブごとのディスク容量コストを列挙する推奨方法は次のとおりです。dwIndex を 0 に設定して開始し、各呼び出しの後に 1 ずつ増分します。 MsiEnumComponentCostsERROR_SUCCESS を返す限り、列挙を続けます。

MsiEnumComponentCosts はカスタムアクションから呼び出すことができます。

インストールの最終的な合計ディスクコストは、すべてのコンポーネントのコストの合計に、Windows インストーラーのコスト(szComponent = null)を加えたものです。

メモ

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

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

各言語での呼び出し定義

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

DWORD MsiEnumComponentCostsA(
    MSIHANDLE hInstall,
    LPCSTR szComponent,
    DWORD dwIndex,
    INSTALLSTATE iState,
    LPSTR szDriveBuf,
    DWORD* pcchDriveBuf,
    INT* piCost,
    INT* piTempCost
);
[DllImport("msi.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern uint MsiEnumComponentCostsA(
    uint hInstall,   // MSIHANDLE
    [MarshalAs(UnmanagedType.LPStr)] string szComponent,   // LPCSTR
    uint dwIndex,   // DWORD
    int iState,   // INSTALLSTATE
    [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder szDriveBuf,   // LPSTR out
    ref uint pcchDriveBuf,   // DWORD* in/out
    out int piCost,   // INT* out
    out int piTempCost   // INT* out
);
<DllImport("msi.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function MsiEnumComponentCostsA(
    hInstall As UInteger,   ' MSIHANDLE
    <MarshalAs(UnmanagedType.LPStr)> szComponent As String,   ' LPCSTR
    dwIndex As UInteger,   ' DWORD
    iState As Integer,   ' INSTALLSTATE
    <MarshalAs(UnmanagedType.LPStr)> szDriveBuf As System.Text.StringBuilder,   ' LPSTR out
    ByRef pcchDriveBuf As UInteger,   ' DWORD* in/out
    <Out> ByRef piCost As Integer,   ' INT* out
    <Out> ByRef piTempCost As Integer   ' INT* out
) As UInteger
End Function
' hInstall : MSIHANDLE
' szComponent : LPCSTR
' dwIndex : DWORD
' iState : INSTALLSTATE
' szDriveBuf : LPSTR out
' pcchDriveBuf : DWORD* in/out
' piCost : INT* out
' piTempCost : INT* out
Declare PtrSafe Function MsiEnumComponentCostsA Lib "msi" ( _
    ByVal hInstall As Long, _
    ByVal szComponent As String, _
    ByVal dwIndex As Long, _
    ByVal iState As Long, _
    ByVal szDriveBuf As String, _
    ByRef pcchDriveBuf As Long, _
    ByRef piCost As Long, _
    ByRef piTempCost As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

MsiEnumComponentCostsA = ctypes.windll.msi.MsiEnumComponentCostsA
MsiEnumComponentCostsA.restype = wintypes.DWORD
MsiEnumComponentCostsA.argtypes = [
    wintypes.DWORD,  # hInstall : MSIHANDLE
    wintypes.LPCSTR,  # szComponent : LPCSTR
    wintypes.DWORD,  # dwIndex : DWORD
    ctypes.c_int,  # iState : INSTALLSTATE
    wintypes.LPSTR,  # szDriveBuf : LPSTR out
    ctypes.POINTER(wintypes.DWORD),  # pcchDriveBuf : DWORD* in/out
    ctypes.POINTER(ctypes.c_int),  # piCost : INT* out
    ctypes.POINTER(ctypes.c_int),  # piTempCost : INT* out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('msi.dll')
MsiEnumComponentCostsA = Fiddle::Function.new(
  lib['MsiEnumComponentCostsA'],
  [
    -Fiddle::TYPE_INT,  # hInstall : MSIHANDLE
    Fiddle::TYPE_VOIDP,  # szComponent : LPCSTR
    -Fiddle::TYPE_INT,  # dwIndex : DWORD
    Fiddle::TYPE_INT,  # iState : INSTALLSTATE
    Fiddle::TYPE_VOIDP,  # szDriveBuf : LPSTR out
    Fiddle::TYPE_VOIDP,  # pcchDriveBuf : DWORD* in/out
    Fiddle::TYPE_VOIDP,  # piCost : INT* out
    Fiddle::TYPE_VOIDP,  # piTempCost : INT* out
  ],
  -Fiddle::TYPE_INT)
#[link(name = "msi")]
extern "system" {
    fn MsiEnumComponentCostsA(
        hInstall: u32,  // MSIHANDLE
        szComponent: *const u8,  // LPCSTR
        dwIndex: u32,  // DWORD
        iState: i32,  // INSTALLSTATE
        szDriveBuf: *mut u8,  // LPSTR out
        pcchDriveBuf: *mut u32,  // DWORD* in/out
        piCost: *mut i32,  // INT* out
        piTempCost: *mut i32  // INT* out
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("msi.dll", CharSet = CharSet.Ansi)]
public static extern uint MsiEnumComponentCostsA(uint hInstall, [MarshalAs(UnmanagedType.LPStr)] string szComponent, uint dwIndex, int iState, [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder szDriveBuf, ref uint pcchDriveBuf, out int piCost, out int piTempCost);
"@
$api = Add-Type -MemberDefinition $sig -Name 'msi_MsiEnumComponentCostsA' -Namespace Win32 -PassThru
# $api::MsiEnumComponentCostsA(hInstall, szComponent, dwIndex, iState, szDriveBuf, pcchDriveBuf, piCost, piTempCost)
#uselib "msi.dll"
#func global MsiEnumComponentCostsA "MsiEnumComponentCostsA" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; MsiEnumComponentCostsA hInstall, szComponent, dwIndex, iState, varptr(szDriveBuf), varptr(pcchDriveBuf), varptr(piCost), varptr(piTempCost)   ; 戻り値は stat
; hInstall : MSIHANDLE -> "sptr"
; szComponent : LPCSTR -> "sptr"
; dwIndex : DWORD -> "sptr"
; iState : INSTALLSTATE -> "sptr"
; szDriveBuf : LPSTR out -> "sptr"
; pcchDriveBuf : DWORD* in/out -> "sptr"
; piCost : INT* out -> "sptr"
; piTempCost : INT* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "msi.dll"
#cfunc global MsiEnumComponentCostsA "MsiEnumComponentCostsA" int, str, int, int, var, var, var, var
; res = MsiEnumComponentCostsA(hInstall, szComponent, dwIndex, iState, szDriveBuf, pcchDriveBuf, piCost, piTempCost)
; hInstall : MSIHANDLE -> "int"
; szComponent : LPCSTR -> "str"
; dwIndex : DWORD -> "int"
; iState : INSTALLSTATE -> "int"
; szDriveBuf : LPSTR out -> "var"
; pcchDriveBuf : DWORD* in/out -> "var"
; piCost : INT* out -> "var"
; piTempCost : INT* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; DWORD MsiEnumComponentCostsA(MSIHANDLE hInstall, LPCSTR szComponent, DWORD dwIndex, INSTALLSTATE iState, LPSTR szDriveBuf, DWORD* pcchDriveBuf, INT* piCost, INT* piTempCost)
#uselib "msi.dll"
#cfunc global MsiEnumComponentCostsA "MsiEnumComponentCostsA" int, str, int, int, var, var, var, var
; res = MsiEnumComponentCostsA(hInstall, szComponent, dwIndex, iState, szDriveBuf, pcchDriveBuf, piCost, piTempCost)
; hInstall : MSIHANDLE -> "int"
; szComponent : LPCSTR -> "str"
; dwIndex : DWORD -> "int"
; iState : INSTALLSTATE -> "int"
; szDriveBuf : LPSTR out -> "var"
; pcchDriveBuf : DWORD* in/out -> "var"
; piCost : INT* out -> "var"
; piTempCost : INT* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	msi = windows.NewLazySystemDLL("msi.dll")
	procMsiEnumComponentCostsA = msi.NewProc("MsiEnumComponentCostsA")
)

// hInstall (MSIHANDLE), szComponent (LPCSTR), dwIndex (DWORD), iState (INSTALLSTATE), szDriveBuf (LPSTR out), pcchDriveBuf (DWORD* in/out), piCost (INT* out), piTempCost (INT* out)
r1, _, err := procMsiEnumComponentCostsA.Call(
	uintptr(hInstall),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(szComponent))),
	uintptr(dwIndex),
	uintptr(iState),
	uintptr(szDriveBuf),
	uintptr(pcchDriveBuf),
	uintptr(piCost),
	uintptr(piTempCost),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function MsiEnumComponentCostsA(
  hInstall: DWORD;   // MSIHANDLE
  szComponent: PAnsiChar;   // LPCSTR
  dwIndex: DWORD;   // DWORD
  iState: Integer;   // INSTALLSTATE
  szDriveBuf: PAnsiChar;   // LPSTR out
  pcchDriveBuf: Pointer;   // DWORD* in/out
  piCost: Pointer;   // INT* out
  piTempCost: Pointer   // INT* out
): DWORD; stdcall;
  external 'msi.dll' name 'MsiEnumComponentCostsA';
result := DllCall("msi\MsiEnumComponentCostsA"
    , "UInt", hInstall   ; MSIHANDLE
    , "AStr", szComponent   ; LPCSTR
    , "UInt", dwIndex   ; DWORD
    , "Int", iState   ; INSTALLSTATE
    , "Ptr", szDriveBuf   ; LPSTR out
    , "Ptr", pcchDriveBuf   ; DWORD* in/out
    , "Ptr", piCost   ; INT* out
    , "Ptr", piTempCost   ; INT* out
    , "UInt")   ; return: DWORD
●MsiEnumComponentCostsA(hInstall, szComponent, dwIndex, iState, szDriveBuf, pcchDriveBuf, piCost, piTempCost) = DLL("msi.dll", "dword MsiEnumComponentCostsA(dword, char*, dword, int, char*, void*, void*, void*)")
# 呼び出し: MsiEnumComponentCostsA(hInstall, szComponent, dwIndex, iState, szDriveBuf, pcchDriveBuf, piCost, piTempCost)
# hInstall : MSIHANDLE -> "dword"
# szComponent : LPCSTR -> "char*"
# dwIndex : DWORD -> "dword"
# iState : INSTALLSTATE -> "int"
# szDriveBuf : LPSTR out -> "char*"
# pcchDriveBuf : DWORD* in/out -> "void*"
# piCost : INT* out -> "void*"
# piTempCost : INT* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

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

typedef MsiEnumComponentCostsANative = Uint32 Function(Uint32, Pointer<Utf8>, Uint32, Int32, Pointer<Utf8>, Pointer<Uint32>, Pointer<Int32>, Pointer<Int32>);
typedef MsiEnumComponentCostsADart = int Function(int, Pointer<Utf8>, int, int, Pointer<Utf8>, Pointer<Uint32>, Pointer<Int32>, Pointer<Int32>);
final MsiEnumComponentCostsA = DynamicLibrary.open('msi.dll')
    .lookupFunction<MsiEnumComponentCostsANative, MsiEnumComponentCostsADart>('MsiEnumComponentCostsA');
// hInstall : MSIHANDLE -> Uint32
// szComponent : LPCSTR -> Pointer<Utf8>
// dwIndex : DWORD -> Uint32
// iState : INSTALLSTATE -> Int32
// szDriveBuf : LPSTR out -> Pointer<Utf8>
// pcchDriveBuf : DWORD* in/out -> Pointer<Uint32>
// piCost : INT* out -> Pointer<Int32>
// piTempCost : INT* out -> Pointer<Int32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function MsiEnumComponentCostsA(
  hInstall: DWORD;   // MSIHANDLE
  szComponent: PAnsiChar;   // LPCSTR
  dwIndex: DWORD;   // DWORD
  iState: Integer;   // INSTALLSTATE
  szDriveBuf: PAnsiChar;   // LPSTR out
  pcchDriveBuf: Pointer;   // DWORD* in/out
  piCost: Pointer;   // INT* out
  piTempCost: Pointer   // INT* out
): DWORD; stdcall;
  external 'msi.dll' name 'MsiEnumComponentCostsA';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "MsiEnumComponentCostsA"
  c_MsiEnumComponentCostsA :: Word32 -> CString -> Word32 -> Int32 -> CString -> Ptr Word32 -> Ptr Int32 -> Ptr Int32 -> IO Word32
-- hInstall : MSIHANDLE -> Word32
-- szComponent : LPCSTR -> CString
-- dwIndex : DWORD -> Word32
-- iState : INSTALLSTATE -> Int32
-- szDriveBuf : LPSTR out -> CString
-- pcchDriveBuf : DWORD* in/out -> Ptr Word32
-- piCost : INT* out -> Ptr Int32
-- piTempCost : INT* out -> Ptr Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let msienumcomponentcostsa =
  foreign "MsiEnumComponentCostsA"
    (uint32_t @-> string @-> uint32_t @-> int32_t @-> string @-> (ptr uint32_t) @-> (ptr int32_t) @-> (ptr int32_t) @-> returning uint32_t)
(* hInstall : MSIHANDLE -> uint32_t *)
(* szComponent : LPCSTR -> string *)
(* dwIndex : DWORD -> uint32_t *)
(* iState : INSTALLSTATE -> int32_t *)
(* szDriveBuf : LPSTR out -> string *)
(* pcchDriveBuf : DWORD* in/out -> (ptr uint32_t) *)
(* piCost : INT* out -> (ptr int32_t) *)
(* piTempCost : INT* out -> (ptr int32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library msi (t "msi.dll"))
(cffi:use-foreign-library msi)

(cffi:defcfun ("MsiEnumComponentCostsA" msi-enum-component-costs-a :convention :stdcall) :uint32
  (h-install :uint32)   ; MSIHANDLE
  (sz-component :string)   ; LPCSTR
  (dw-index :uint32)   ; DWORD
  (i-state :int32)   ; INSTALLSTATE
  (sz-drive-buf :pointer)   ; LPSTR out
  (pcch-drive-buf :pointer)   ; DWORD* in/out
  (pi-cost :pointer)   ; INT* out
  (pi-temp-cost :pointer))   ; INT* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $MsiEnumComponentCostsA = Win32::API::More->new('msi',
    'DWORD MsiEnumComponentCostsA(DWORD hInstall, LPCSTR szComponent, DWORD dwIndex, int iState, LPSTR szDriveBuf, LPVOID pcchDriveBuf, LPVOID piCost, LPVOID piTempCost)');
# my $ret = $MsiEnumComponentCostsA->Call($hInstall, $szComponent, $dwIndex, $iState, $szDriveBuf, $pcchDriveBuf, $piCost, $piTempCost);
# hInstall : MSIHANDLE -> DWORD
# szComponent : LPCSTR -> LPCSTR
# dwIndex : DWORD -> DWORD
# iState : INSTALLSTATE -> int
# szDriveBuf : LPSTR out -> LPSTR
# pcchDriveBuf : DWORD* in/out -> LPVOID
# piCost : INT* out -> LPVOID
# piTempCost : INT* out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

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