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

MsiSourceListEnumSourcesA

関数
製品やパッチのソースリスト内のソースを列挙する。
DLLmsi.dll文字セットANSI (-A)呼出規約winapi対応OSwindows8.0

シグネチャ

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

DWORD MsiSourceListEnumSourcesA(
    LPCSTR szProductCodeOrPatchCode,
    LPCSTR szUserSid,   // optional
    MSIINSTALLCONTEXT dwContext,
    DWORD dwOptions,
    DWORD dwIndex,
    LPSTR szSource,   // optional
    DWORD* pcchSource   // optional
);

パラメーター

名前方向説明
szProductCodeOrPatchCodeLPCSTRin製品またはパッチの ProductCode またはパッチ GUID です。NULL で終わる文字列を使用します。文字列が 39 文字を超える場合、関数は失敗し ERROR_INVALID_PARAMETER を返します。このパラメーターを NULL にすることはできません。
szUserSidLPCSTRinoptional

製品またはパッチを保持するユーザー アカウントを指定する文字列形式の SID です。この SID は検証も解決もされません。誤った SID を指定すると ERROR_UNKNOWN_PRODUCT または ERROR_UNKNOWN_PATCH が返される場合があります。マシン コンテキストを参照する場合、szUserSIDNULL でなければならず、dwContextMSIINSTALLCONTEXT_MACHINE でなければなりません。

SID の種類 意味
NULL
NULL は現在ログオンしているユーザーを示します。現在のユーザー アカウントを参照する場合、szUserSIDNULL にし、dwContextMSIINSTALLCONTEXT_USERMANAGED または MSIINSTALLCONTEXT_USERUNMANAGED にできます。
User SID
システム内の特定のユーザーを列挙対象とします。ユーザー SID の例としては "S-1-3-64-2415071341-1358098788-3127455600-2561" があります。
s-1-1-0
特殊な SID 文字列 s-1-1-0 (everyone) は、システム内のすべてのユーザーを対象とした列挙を指定します。
注意 特殊な SID 文字列 s-1-5-18 (system) を使用して、マシン単位でインストールされた製品やパッチを列挙することはできません。SID の値を s-1-5-18 に設定すると ERROR_INVALID_PARAMETER が返されます。
dwContextMSIINSTALLCONTEXTin

製品またはパッチのインスタンスのコンテキストです。このパラメーターには次の値のいずれか 1 つを指定できます。

コンテキストの種類 意味
MSIINSTALLCONTEXT_USERMANAGED
製品またはパッチのインスタンスがユーザー単位の管理対象 (per-user-managed) コンテキストに存在します。
MSIINSTALLCONTEXT_USERUNMANAGED
製品またはパッチのインスタンスがユーザー単位の非管理対象 (per-user-unmanaged) コンテキストに存在します。
MSIINSTALLCONTEXT_MACHINE
製品またはパッチのインスタンスがマシン単位 (per-machine) コンテキストに存在します。
dwOptionsDWORDin

dwOptions の値によって、szProductCodeOrPatchCode の値の解釈と、対象とするソースの種類が決まります。このパラメーターは、次の MSISOURCETYPE_* 定数のいずれか 1 つと、次の MSICODE_* 定数のいずれか 1 つを組み合わせたものでなければなりません。

フラグ 意味
MSISOURCETYPE_NETWORK
ソースはネットワーク型です。
MSISOURCETYPE_URL
ソースは URL 型です。
MSICODE_PRODUCT
szProductCodeOrPatchCode は製品コードです。
MSICODE_PATCH
szProductCodeOrPatchCode はパッチ コードです。
dwIndexDWORDin取得するソースのインデックスです。このパラメーターは、MsiSourceListEnumSources 関数の最初の呼び出しでは 0 (ゼロ) でなければならず、その後は関数が ERROR_NO_MORE_ITEMS を返すまで、呼び出しごとに増分します。インデックスを増分するのは、直前の呼び出しが ERROR_SUCCESS を返した場合のみにしてください。
szSourceLPSTRoutoptional

列挙対象のソースへのパスを受け取るバッファーへのポインターです。このバッファーは、受け取る値を格納できる十分な大きさが必要です。バッファーが小さすぎる場合、関数は ERROR_MORE_DATA を返し、*pcchSource に、終端の NULL 文字を含まない値の TCHAR 数を設定します。

szSourceNULL に設定し、pcchSource を有効なポインターに設定した場合、関数は ERROR_SUCCESS を返し、pcchSource に、終端の NULL 文字を含まない値の TCHAR 数を設定します。その後、pcchSource + 1 文字を格納できる十分な大きさの szSource バッファーを指定して関数を再度呼び出し、値を取得できます。

szSourcepcchSource の両方を NULL に設定した場合、値が存在すれば関数は値を取得せずに ERROR_SUCCESS を返します。

pcchSourceDWORD*inoutoptional

szSource バッファー内の TCHAR 数を指定する変数へのポインターです。関数が値を指定バッファーにコピーするかどうかにかかわらず、関数が戻るとき、このパラメーターには要求された値のサイズが設定されます。サイズは、終端の NULL 文字を含まない要求された値の TCHAR 数として返されます。

このパラメーターを NULL に設定できるのは、szSourceNULL である場合のみです。それ以外の場合、関数は ERROR_INVALID_PARAMETER を返します。

戻り値の型: DWORD

公式ドキュメント

MsiSourceListEnumSources 関数は、指定されたパッチまたは製品のソース リストに含まれるソースを列挙します。(ANSI)

戻り値

MsiSourceListEnumSources 関数は次の値を返します。

意味
ERROR_ACCESS_DENIED
ユーザーに、指定されたソース リストを読み取る権限がありません。これは、製品やパッチが見つかったかどうかを示すものではありません。
ERROR_BAD_CONFIGURATION
構成データが破損しています。
ERROR_INVALID_PARAMETER
無効なパラメーターが関数に渡されました。
ERROR_MORE_DATA
指定されたバッファーが、要求されたデータを格納するのに十分ではありません。
ERROR_NO_MORE_ITEMS
指定されたリスト内に、列挙すべきソースがこれ以上ありません。
ERROR_SUCCESS
ソースが正常に列挙されました。
ERROR_UNKNOWN_PATCH
指定されたパッチが、指定されたコンテキストでコンピューターにインストールされていません。
ERROR_UNKNOWN_PRODUCT
指定された製品が、指定されたコンテキストでコンピューターにインストールされていません。
ERROR_FUNCTION_FAILED
予期しない内部エラーが発生しました。

解説(Remarks)

MsiSourceListEnumSources を複数回呼び出して単一の製品インスタンスのすべてのソースを列挙する場合、各呼び出しは同じスレッドから行う必要があります。

管理者は、自分自身のユーザー単位の非管理対象および管理対象のインストール、マシン単位のインストール、および任意のユーザーのユーザー単位の管理対象のインストールを列挙できます。管理者は、他のユーザーのユーザー単位の非管理対象のインストールを列挙することはできません。管理者以外のユーザーは、自分自身のユーザー単位の非管理対象および管理対象のインストールと、マシン単位のインストールのみを列挙できます。

メモ

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

出典・ライセンス: 上記「公式ドキュメント」の内容は 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 MsiSourceListEnumSourcesA(
    LPCSTR szProductCodeOrPatchCode,
    LPCSTR szUserSid,   // optional
    MSIINSTALLCONTEXT dwContext,
    DWORD dwOptions,
    DWORD dwIndex,
    LPSTR szSource,   // optional
    DWORD* pcchSource   // optional
);
[DllImport("msi.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern uint MsiSourceListEnumSourcesA(
    [MarshalAs(UnmanagedType.LPStr)] string szProductCodeOrPatchCode,   // LPCSTR
    [MarshalAs(UnmanagedType.LPStr)] string szUserSid,   // LPCSTR optional
    int dwContext,   // MSIINSTALLCONTEXT
    uint dwOptions,   // DWORD
    uint dwIndex,   // DWORD
    [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder szSource,   // LPSTR optional, out
    IntPtr pcchSource   // DWORD* optional, in/out
);
<DllImport("msi.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function MsiSourceListEnumSourcesA(
    <MarshalAs(UnmanagedType.LPStr)> szProductCodeOrPatchCode As String,   ' LPCSTR
    <MarshalAs(UnmanagedType.LPStr)> szUserSid As String,   ' LPCSTR optional
    dwContext As Integer,   ' MSIINSTALLCONTEXT
    dwOptions As UInteger,   ' DWORD
    dwIndex As UInteger,   ' DWORD
    <MarshalAs(UnmanagedType.LPStr)> szSource As System.Text.StringBuilder,   ' LPSTR optional, out
    pcchSource As IntPtr   ' DWORD* optional, in/out
) As UInteger
End Function
' szProductCodeOrPatchCode : LPCSTR
' szUserSid : LPCSTR optional
' dwContext : MSIINSTALLCONTEXT
' dwOptions : DWORD
' dwIndex : DWORD
' szSource : LPSTR optional, out
' pcchSource : DWORD* optional, in/out
Declare PtrSafe Function MsiSourceListEnumSourcesA Lib "msi" ( _
    ByVal szProductCodeOrPatchCode As String, _
    ByVal szUserSid As String, _
    ByVal dwContext As Long, _
    ByVal dwOptions As Long, _
    ByVal dwIndex As Long, _
    ByVal szSource As String, _
    ByVal pcchSource As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

MsiSourceListEnumSourcesA = ctypes.windll.msi.MsiSourceListEnumSourcesA
MsiSourceListEnumSourcesA.restype = wintypes.DWORD
MsiSourceListEnumSourcesA.argtypes = [
    wintypes.LPCSTR,  # szProductCodeOrPatchCode : LPCSTR
    wintypes.LPCSTR,  # szUserSid : LPCSTR optional
    ctypes.c_int,  # dwContext : MSIINSTALLCONTEXT
    wintypes.DWORD,  # dwOptions : DWORD
    wintypes.DWORD,  # dwIndex : DWORD
    wintypes.LPSTR,  # szSource : LPSTR optional, out
    ctypes.POINTER(wintypes.DWORD),  # pcchSource : DWORD* optional, in/out
]
require 'fiddle'
require 'fiddle/import'

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

var (
	msi = windows.NewLazySystemDLL("msi.dll")
	procMsiSourceListEnumSourcesA = msi.NewProc("MsiSourceListEnumSourcesA")
)

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

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

typedef MsiSourceListEnumSourcesANative = Uint32 Function(Pointer<Utf8>, Pointer<Utf8>, Int32, Uint32, Uint32, Pointer<Utf8>, Pointer<Uint32>);
typedef MsiSourceListEnumSourcesADart = int Function(Pointer<Utf8>, Pointer<Utf8>, int, int, int, Pointer<Utf8>, Pointer<Uint32>);
final MsiSourceListEnumSourcesA = DynamicLibrary.open('msi.dll')
    .lookupFunction<MsiSourceListEnumSourcesANative, MsiSourceListEnumSourcesADart>('MsiSourceListEnumSourcesA');
// szProductCodeOrPatchCode : LPCSTR -> Pointer<Utf8>
// szUserSid : LPCSTR optional -> Pointer<Utf8>
// dwContext : MSIINSTALLCONTEXT -> Int32
// dwOptions : DWORD -> Uint32
// dwIndex : DWORD -> Uint32
// szSource : LPSTR optional, out -> Pointer<Utf8>
// pcchSource : DWORD* optional, in/out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function MsiSourceListEnumSourcesA(
  szProductCodeOrPatchCode: PAnsiChar;   // LPCSTR
  szUserSid: PAnsiChar;   // LPCSTR optional
  dwContext: Integer;   // MSIINSTALLCONTEXT
  dwOptions: DWORD;   // DWORD
  dwIndex: DWORD;   // DWORD
  szSource: PAnsiChar;   // LPSTR optional, out
  pcchSource: Pointer   // DWORD* optional, in/out
): DWORD; stdcall;
  external 'msi.dll' name 'MsiSourceListEnumSourcesA';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "MsiSourceListEnumSourcesA"
  c_MsiSourceListEnumSourcesA :: CString -> CString -> Int32 -> Word32 -> Word32 -> CString -> Ptr Word32 -> IO Word32
-- szProductCodeOrPatchCode : LPCSTR -> CString
-- szUserSid : LPCSTR optional -> CString
-- dwContext : MSIINSTALLCONTEXT -> Int32
-- dwOptions : DWORD -> Word32
-- dwIndex : DWORD -> Word32
-- szSource : LPSTR optional, out -> CString
-- pcchSource : DWORD* optional, in/out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let msisourcelistenumsourcesa =
  foreign "MsiSourceListEnumSourcesA"
    (string @-> string @-> int32_t @-> uint32_t @-> uint32_t @-> string @-> (ptr uint32_t) @-> returning uint32_t)
(* szProductCodeOrPatchCode : LPCSTR -> string *)
(* szUserSid : LPCSTR optional -> string *)
(* dwContext : MSIINSTALLCONTEXT -> int32_t *)
(* dwOptions : DWORD -> uint32_t *)
(* dwIndex : DWORD -> uint32_t *)
(* szSource : LPSTR optional, out -> string *)
(* pcchSource : DWORD* optional, in/out -> (ptr uint32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library msi (t "msi.dll"))
(cffi:use-foreign-library msi)

(cffi:defcfun ("MsiSourceListEnumSourcesA" msi-source-list-enum-sources-a :convention :stdcall) :uint32
  (sz-product-code-or-patch-code :string)   ; LPCSTR
  (sz-user-sid :string)   ; LPCSTR optional
  (dw-context :int32)   ; MSIINSTALLCONTEXT
  (dw-options :uint32)   ; DWORD
  (dw-index :uint32)   ; DWORD
  (sz-source :pointer)   ; LPSTR optional, out
  (pcch-source :pointer))   ; DWORD* optional, in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $MsiSourceListEnumSourcesA = Win32::API::More->new('msi',
    'DWORD MsiSourceListEnumSourcesA(LPCSTR szProductCodeOrPatchCode, LPCSTR szUserSid, int dwContext, DWORD dwOptions, DWORD dwIndex, LPSTR szSource, LPVOID pcchSource)');
# my $ret = $MsiSourceListEnumSourcesA->Call($szProductCodeOrPatchCode, $szUserSid, $dwContext, $dwOptions, $dwIndex, $szSource, $pcchSource);
# szProductCodeOrPatchCode : LPCSTR -> LPCSTR
# szUserSid : LPCSTR optional -> LPCSTR
# dwContext : MSIINSTALLCONTEXT -> int
# dwOptions : DWORD -> DWORD
# dwIndex : DWORD -> DWORD
# szSource : LPSTR optional, out -> LPSTR
# pcchSource : DWORD* optional, in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

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