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

MsiSourceListEnumMediaDisksW

関数
ソースリストに登録されたメディアディスクを列挙する。
DLLmsi.dll文字セットUnicode (-W)呼出規約winapi対応OSwindows8.0

シグネチャ

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

DWORD MsiSourceListEnumMediaDisksW(
    LPCWSTR szProductCodeOrPatchCode,
    LPCWSTR szUserSid,   // optional
    MSIINSTALLCONTEXT dwContext,
    DWORD dwOptions,
    DWORD dwIndex,
    DWORD* pdwDiskId,   // optional
    LPWSTR szVolumeLabel,   // optional
    DWORD* pcchVolumeLabel,   // optional
    LPWSTR szDiskPrompt,   // optional
    DWORD* pcchDiskPrompt   // optional
);

パラメーター

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

製品またはパッチを含むユーザーアカウントを指定する文字列形式の 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) は、per-machine としてインストールされた製品またはパッチの列挙には使用できません。SID 値を s-1-5-18 に設定すると ERROR_INVALID_PARAMETER が返されます。
dwContextMSIINSTALLCONTEXTin

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

コンテキストの種類 意味
MSIINSTALLCONTEXT_USERMANAGED
製品またはパッチインスタンスは、per-user-managed コンテキストに存在します。
MSIINSTALLCONTEXT_USERUNMANAGED
製品またはパッチインスタンスは、per-user-unmanaged コンテキストに存在します。
MSIINSTALLCONTEXT_MACHINE
製品またはパッチインスタンスは、per-machine コンテキストに存在します。
dwOptionsDWORDin

szProductCodeOrPatchCode の意味を指定する dwOptions 値です。

フラグ 意味
MSICODE_PRODUCT
szProductCodeOrPatchCode は製品コード GUID です。
MSICODE_PATCH
szProductCodeOrPatchCode はパッチコード GUID です。
dwIndexDWORDin取得するソースのインデックス。このパラメーターは、MsiSourceListEnumMediaDisks 関数の最初の呼び出しでは 0 (ゼロ) でなければならず、その後は関数が ERROR_NO_MORE_ITEMS を返すまで、後続の呼び出しごとにインクリメントします。
pdwDiskIdDWORD*outoptionalMsiSourceListEnumMediaDisks への入力時、このパラメーターは、列挙対象のディスクの ID を受け取る DWORD へのポインターを指定します。このパラメーターは省略可能です。
szVolumeLabelLPWSTRoutoptional

列挙対象のディスクのボリュームラベルを受け取る出力バッファー。このバッファーは情報を格納できるだけの十分な大きさが必要です。バッファーが小さすぎる場合、関数は ERROR_MORE_DATA を返し、終端の NULL 文字を含まない値の TCHAR 数を *pcchVolumeLabel に設定します。

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

pcchVolumeLabelDWORD*inoutoptional

szVolumeLabel バッファー内の TCHAR 数を指定する変数へのポインター。関数が返るとき、このパラメーターは終端の null 文字を含まない、受け取った値の TCHAR 数になります。

このパラメーターを NULL に設定できるのは szVolumeLabelNULL の場合のみです。そうでない場合、関数は ERROR_INVALID_PARAMETER を返します。

szDiskPromptLPWSTRoutoptional

列挙対象のディスクのディスクプロンプトを受け取る出力バッファー。このバッファーは情報を格納できるだけの十分な大きさが必要です。バッファーが小さすぎる場合、関数は ERROR_MORE_DATA を返し、終端の NULL 文字を含まない値の TCHAR 数を *pcchDiskPrompt に設定します。

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

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

pcchDiskPromptDWORD*inoutoptional

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

このパラメーターを NULL に設定できるのは szDiskPromptNULL の場合のみです。そうでない場合、関数は ERROR_INVALID_PARAMETER を返します。

戻り値の型: DWORD

公式ドキュメント

MsiSourceListEnumMediaDisks 関数は、パッチまたは製品のメディアソースに登録されているディスクの一覧を列挙します。(Unicode)

戻り値

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

意味
ERROR_ACCESS_DENIED
ユーザーに、指定されたメディアソース、または指定された製品もしくはパッチを読み取る権限がありません。これは、メディアソース、製品、またはパッチが見つかったかどうかを示すものではありません。
ERROR_BAD_CONFIGURATION
構成データが破損しています。
ERROR_INVALID_PARAMETER
無効なパラメーターが関数に渡されました。
ERROR_NO_MORE_ITEMS
この製品またはパッチに登録されているディスクはもうありません。
ERROR_SUCCESS
値が正常に列挙されました。
ERROR_UNKNOWN_PATCH
パッチが見つかりません。
ERROR_UNKNOWN_PRODUCT
製品が見つかりません。
ERROR_MORE_DATA
提供されたバッファーが小さすぎて、要求された情報を格納できません。
ERROR_FUNCTION_FAILED
予期しない内部エラーが発生しました。

解説(Remarks)

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

管理者は、自分自身の per-user unmanaged および managed のインストール、per-machine のインストール、および任意のユーザーの per-user managed のインストールを列挙できます。管理者は、他のユーザーの per-user unmanaged のインストールを列挙することはできません。非管理者は、自分自身の per-user unmanaged および managed のインストールと per-machine のインストールのみを列挙できます。

メモ

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

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

各言語での呼び出し定義

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

DWORD MsiSourceListEnumMediaDisksW(
    LPCWSTR szProductCodeOrPatchCode,
    LPCWSTR szUserSid,   // optional
    MSIINSTALLCONTEXT dwContext,
    DWORD dwOptions,
    DWORD dwIndex,
    DWORD* pdwDiskId,   // optional
    LPWSTR szVolumeLabel,   // optional
    DWORD* pcchVolumeLabel,   // optional
    LPWSTR szDiskPrompt,   // optional
    DWORD* pcchDiskPrompt   // optional
);
[DllImport("msi.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern uint MsiSourceListEnumMediaDisksW(
    [MarshalAs(UnmanagedType.LPWStr)] string szProductCodeOrPatchCode,   // LPCWSTR
    [MarshalAs(UnmanagedType.LPWStr)] string szUserSid,   // LPCWSTR optional
    int dwContext,   // MSIINSTALLCONTEXT
    uint dwOptions,   // DWORD
    uint dwIndex,   // DWORD
    IntPtr pdwDiskId,   // DWORD* optional, out
    [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder szVolumeLabel,   // LPWSTR optional, out
    IntPtr pcchVolumeLabel,   // DWORD* optional, in/out
    [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder szDiskPrompt,   // LPWSTR optional, out
    IntPtr pcchDiskPrompt   // DWORD* optional, in/out
);
<DllImport("msi.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function MsiSourceListEnumMediaDisksW(
    <MarshalAs(UnmanagedType.LPWStr)> szProductCodeOrPatchCode As String,   ' LPCWSTR
    <MarshalAs(UnmanagedType.LPWStr)> szUserSid As String,   ' LPCWSTR optional
    dwContext As Integer,   ' MSIINSTALLCONTEXT
    dwOptions As UInteger,   ' DWORD
    dwIndex As UInteger,   ' DWORD
    pdwDiskId As IntPtr,   ' DWORD* optional, out
    <MarshalAs(UnmanagedType.LPWStr)> szVolumeLabel As System.Text.StringBuilder,   ' LPWSTR optional, out
    pcchVolumeLabel As IntPtr,   ' DWORD* optional, in/out
    <MarshalAs(UnmanagedType.LPWStr)> szDiskPrompt As System.Text.StringBuilder,   ' LPWSTR optional, out
    pcchDiskPrompt As IntPtr   ' DWORD* optional, in/out
) As UInteger
End Function
' szProductCodeOrPatchCode : LPCWSTR
' szUserSid : LPCWSTR optional
' dwContext : MSIINSTALLCONTEXT
' dwOptions : DWORD
' dwIndex : DWORD
' pdwDiskId : DWORD* optional, out
' szVolumeLabel : LPWSTR optional, out
' pcchVolumeLabel : DWORD* optional, in/out
' szDiskPrompt : LPWSTR optional, out
' pcchDiskPrompt : DWORD* optional, in/out
Declare PtrSafe Function MsiSourceListEnumMediaDisksW Lib "msi" ( _
    ByVal szProductCodeOrPatchCode As LongPtr, _
    ByVal szUserSid As LongPtr, _
    ByVal dwContext As Long, _
    ByVal dwOptions As Long, _
    ByVal dwIndex As Long, _
    ByVal pdwDiskId As LongPtr, _
    ByVal szVolumeLabel As LongPtr, _
    ByVal pcchVolumeLabel As LongPtr, _
    ByVal szDiskPrompt As LongPtr, _
    ByVal pcchDiskPrompt 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

MsiSourceListEnumMediaDisksW = ctypes.windll.msi.MsiSourceListEnumMediaDisksW
MsiSourceListEnumMediaDisksW.restype = wintypes.DWORD
MsiSourceListEnumMediaDisksW.argtypes = [
    wintypes.LPCWSTR,  # szProductCodeOrPatchCode : LPCWSTR
    wintypes.LPCWSTR,  # szUserSid : LPCWSTR optional
    ctypes.c_int,  # dwContext : MSIINSTALLCONTEXT
    wintypes.DWORD,  # dwOptions : DWORD
    wintypes.DWORD,  # dwIndex : DWORD
    ctypes.POINTER(wintypes.DWORD),  # pdwDiskId : DWORD* optional, out
    wintypes.LPWSTR,  # szVolumeLabel : LPWSTR optional, out
    ctypes.POINTER(wintypes.DWORD),  # pcchVolumeLabel : DWORD* optional, in/out
    wintypes.LPWSTR,  # szDiskPrompt : LPWSTR optional, out
    ctypes.POINTER(wintypes.DWORD),  # pcchDiskPrompt : DWORD* optional, in/out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('msi.dll')
MsiSourceListEnumMediaDisksW = Fiddle::Function.new(
  lib['MsiSourceListEnumMediaDisksW'],
  [
    Fiddle::TYPE_VOIDP,  # szProductCodeOrPatchCode : LPCWSTR
    Fiddle::TYPE_VOIDP,  # szUserSid : LPCWSTR optional
    Fiddle::TYPE_INT,  # dwContext : MSIINSTALLCONTEXT
    -Fiddle::TYPE_INT,  # dwOptions : DWORD
    -Fiddle::TYPE_INT,  # dwIndex : DWORD
    Fiddle::TYPE_VOIDP,  # pdwDiskId : DWORD* optional, out
    Fiddle::TYPE_VOIDP,  # szVolumeLabel : LPWSTR optional, out
    Fiddle::TYPE_VOIDP,  # pcchVolumeLabel : DWORD* optional, in/out
    Fiddle::TYPE_VOIDP,  # szDiskPrompt : LPWSTR optional, out
    Fiddle::TYPE_VOIDP,  # pcchDiskPrompt : DWORD* optional, in/out
  ],
  -Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "msi")]
extern "system" {
    fn MsiSourceListEnumMediaDisksW(
        szProductCodeOrPatchCode: *const u16,  // LPCWSTR
        szUserSid: *const u16,  // LPCWSTR optional
        dwContext: i32,  // MSIINSTALLCONTEXT
        dwOptions: u32,  // DWORD
        dwIndex: u32,  // DWORD
        pdwDiskId: *mut u32,  // DWORD* optional, out
        szVolumeLabel: *mut u16,  // LPWSTR optional, out
        pcchVolumeLabel: *mut u32,  // DWORD* optional, in/out
        szDiskPrompt: *mut u16,  // LPWSTR optional, out
        pcchDiskPrompt: *mut u32  // DWORD* optional, in/out
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("msi.dll", CharSet = CharSet.Unicode)]
public static extern uint MsiSourceListEnumMediaDisksW([MarshalAs(UnmanagedType.LPWStr)] string szProductCodeOrPatchCode, [MarshalAs(UnmanagedType.LPWStr)] string szUserSid, int dwContext, uint dwOptions, uint dwIndex, IntPtr pdwDiskId, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder szVolumeLabel, IntPtr pcchVolumeLabel, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder szDiskPrompt, IntPtr pcchDiskPrompt);
"@
$api = Add-Type -MemberDefinition $sig -Name 'msi_MsiSourceListEnumMediaDisksW' -Namespace Win32 -PassThru
# $api::MsiSourceListEnumMediaDisksW(szProductCodeOrPatchCode, szUserSid, dwContext, dwOptions, dwIndex, pdwDiskId, szVolumeLabel, pcchVolumeLabel, szDiskPrompt, pcchDiskPrompt)
#uselib "msi.dll"
#func global MsiSourceListEnumMediaDisksW "MsiSourceListEnumMediaDisksW" wptr, wptr, wptr, wptr, wptr, wptr, wptr, wptr, wptr, wptr
; MsiSourceListEnumMediaDisksW szProductCodeOrPatchCode, szUserSid, dwContext, dwOptions, dwIndex, varptr(pdwDiskId), varptr(szVolumeLabel), varptr(pcchVolumeLabel), varptr(szDiskPrompt), varptr(pcchDiskPrompt)   ; 戻り値は stat
; szProductCodeOrPatchCode : LPCWSTR -> "wptr"
; szUserSid : LPCWSTR optional -> "wptr"
; dwContext : MSIINSTALLCONTEXT -> "wptr"
; dwOptions : DWORD -> "wptr"
; dwIndex : DWORD -> "wptr"
; pdwDiskId : DWORD* optional, out -> "wptr"
; szVolumeLabel : LPWSTR optional, out -> "wptr"
; pcchVolumeLabel : DWORD* optional, in/out -> "wptr"
; szDiskPrompt : LPWSTR optional, out -> "wptr"
; pcchDiskPrompt : DWORD* optional, in/out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "msi.dll"
#cfunc global MsiSourceListEnumMediaDisksW "MsiSourceListEnumMediaDisksW" wstr, wstr, int, int, int, var, var, var, var, var
; res = MsiSourceListEnumMediaDisksW(szProductCodeOrPatchCode, szUserSid, dwContext, dwOptions, dwIndex, pdwDiskId, szVolumeLabel, pcchVolumeLabel, szDiskPrompt, pcchDiskPrompt)
; szProductCodeOrPatchCode : LPCWSTR -> "wstr"
; szUserSid : LPCWSTR optional -> "wstr"
; dwContext : MSIINSTALLCONTEXT -> "int"
; dwOptions : DWORD -> "int"
; dwIndex : DWORD -> "int"
; pdwDiskId : DWORD* optional, out -> "var"
; szVolumeLabel : LPWSTR optional, out -> "var"
; pcchVolumeLabel : DWORD* optional, in/out -> "var"
; szDiskPrompt : LPWSTR optional, out -> "var"
; pcchDiskPrompt : DWORD* optional, in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; DWORD MsiSourceListEnumMediaDisksW(LPCWSTR szProductCodeOrPatchCode, LPCWSTR szUserSid, MSIINSTALLCONTEXT dwContext, DWORD dwOptions, DWORD dwIndex, DWORD* pdwDiskId, LPWSTR szVolumeLabel, DWORD* pcchVolumeLabel, LPWSTR szDiskPrompt, DWORD* pcchDiskPrompt)
#uselib "msi.dll"
#cfunc global MsiSourceListEnumMediaDisksW "MsiSourceListEnumMediaDisksW" wstr, wstr, int, int, int, var, var, var, var, var
; res = MsiSourceListEnumMediaDisksW(szProductCodeOrPatchCode, szUserSid, dwContext, dwOptions, dwIndex, pdwDiskId, szVolumeLabel, pcchVolumeLabel, szDiskPrompt, pcchDiskPrompt)
; szProductCodeOrPatchCode : LPCWSTR -> "wstr"
; szUserSid : LPCWSTR optional -> "wstr"
; dwContext : MSIINSTALLCONTEXT -> "int"
; dwOptions : DWORD -> "int"
; dwIndex : DWORD -> "int"
; pdwDiskId : DWORD* optional, out -> "var"
; szVolumeLabel : LPWSTR optional, out -> "var"
; pcchVolumeLabel : DWORD* optional, in/out -> "var"
; szDiskPrompt : LPWSTR optional, out -> "var"
; pcchDiskPrompt : DWORD* optional, in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	msi = windows.NewLazySystemDLL("msi.dll")
	procMsiSourceListEnumMediaDisksW = msi.NewProc("MsiSourceListEnumMediaDisksW")
)

// szProductCodeOrPatchCode (LPCWSTR), szUserSid (LPCWSTR optional), dwContext (MSIINSTALLCONTEXT), dwOptions (DWORD), dwIndex (DWORD), pdwDiskId (DWORD* optional, out), szVolumeLabel (LPWSTR optional, out), pcchVolumeLabel (DWORD* optional, in/out), szDiskPrompt (LPWSTR optional, out), pcchDiskPrompt (DWORD* optional, in/out)
r1, _, err := procMsiSourceListEnumMediaDisksW.Call(
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(szProductCodeOrPatchCode))),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(szUserSid))),
	uintptr(dwContext),
	uintptr(dwOptions),
	uintptr(dwIndex),
	uintptr(pdwDiskId),
	uintptr(szVolumeLabel),
	uintptr(pcchVolumeLabel),
	uintptr(szDiskPrompt),
	uintptr(pcchDiskPrompt),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function MsiSourceListEnumMediaDisksW(
  szProductCodeOrPatchCode: PWideChar;   // LPCWSTR
  szUserSid: PWideChar;   // LPCWSTR optional
  dwContext: Integer;   // MSIINSTALLCONTEXT
  dwOptions: DWORD;   // DWORD
  dwIndex: DWORD;   // DWORD
  pdwDiskId: Pointer;   // DWORD* optional, out
  szVolumeLabel: PWideChar;   // LPWSTR optional, out
  pcchVolumeLabel: Pointer;   // DWORD* optional, in/out
  szDiskPrompt: PWideChar;   // LPWSTR optional, out
  pcchDiskPrompt: Pointer   // DWORD* optional, in/out
): DWORD; stdcall;
  external 'msi.dll' name 'MsiSourceListEnumMediaDisksW';
result := DllCall("msi\MsiSourceListEnumMediaDisksW"
    , "WStr", szProductCodeOrPatchCode   ; LPCWSTR
    , "WStr", szUserSid   ; LPCWSTR optional
    , "Int", dwContext   ; MSIINSTALLCONTEXT
    , "UInt", dwOptions   ; DWORD
    , "UInt", dwIndex   ; DWORD
    , "Ptr", pdwDiskId   ; DWORD* optional, out
    , "Ptr", szVolumeLabel   ; LPWSTR optional, out
    , "Ptr", pcchVolumeLabel   ; DWORD* optional, in/out
    , "Ptr", szDiskPrompt   ; LPWSTR optional, out
    , "Ptr", pcchDiskPrompt   ; DWORD* optional, in/out
    , "UInt")   ; return: DWORD
●MsiSourceListEnumMediaDisksW(szProductCodeOrPatchCode, szUserSid, dwContext, dwOptions, dwIndex, pdwDiskId, szVolumeLabel, pcchVolumeLabel, szDiskPrompt, pcchDiskPrompt) = DLL("msi.dll", "dword MsiSourceListEnumMediaDisksW(char*, char*, int, dword, dword, void*, char*, void*, char*, void*)")
# 呼び出し: MsiSourceListEnumMediaDisksW(szProductCodeOrPatchCode, szUserSid, dwContext, dwOptions, dwIndex, pdwDiskId, szVolumeLabel, pcchVolumeLabel, szDiskPrompt, pcchDiskPrompt)
# szProductCodeOrPatchCode : LPCWSTR -> "char*"
# szUserSid : LPCWSTR optional -> "char*"
# dwContext : MSIINSTALLCONTEXT -> "int"
# dwOptions : DWORD -> "dword"
# dwIndex : DWORD -> "dword"
# pdwDiskId : DWORD* optional, out -> "void*"
# szVolumeLabel : LPWSTR optional, out -> "char*"
# pcchVolumeLabel : DWORD* optional, in/out -> "void*"
# szDiskPrompt : LPWSTR optional, out -> "char*"
# pcchDiskPrompt : DWORD* optional, in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。
const std = @import("std");

extern "msi" fn MsiSourceListEnumMediaDisksW(
    szProductCodeOrPatchCode: [*c]const u16, // LPCWSTR
    szUserSid: [*c]const u16, // LPCWSTR optional
    dwContext: i32, // MSIINSTALLCONTEXT
    dwOptions: u32, // DWORD
    dwIndex: u32, // DWORD
    pdwDiskId: [*c]u32, // DWORD* optional, out
    szVolumeLabel: [*c]u16, // LPWSTR optional, out
    pcchVolumeLabel: [*c]u32, // DWORD* optional, in/out
    szDiskPrompt: [*c]u16, // LPWSTR optional, out
    pcchDiskPrompt: [*c]u32 // DWORD* optional, in/out
) callconv(std.os.windows.WINAPI) u32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。
proc MsiSourceListEnumMediaDisksW(
    szProductCodeOrPatchCode: WideCString,  # LPCWSTR
    szUserSid: WideCString,  # LPCWSTR optional
    dwContext: int32,  # MSIINSTALLCONTEXT
    dwOptions: uint32,  # DWORD
    dwIndex: uint32,  # DWORD
    pdwDiskId: ptr uint32,  # DWORD* optional, out
    szVolumeLabel: ptr uint16,  # LPWSTR optional, out
    pcchVolumeLabel: ptr uint32,  # DWORD* optional, in/out
    szDiskPrompt: ptr uint16,  # LPWSTR optional, out
    pcchDiskPrompt: ptr uint32  # DWORD* optional, in/out
): uint32 {.importc: "MsiSourceListEnumMediaDisksW", stdcall, dynlib: "msi.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。
pragma(lib, "msi");
extern(Windows)
uint MsiSourceListEnumMediaDisksW(
    const(wchar)* szProductCodeOrPatchCode,   // LPCWSTR
    const(wchar)* szUserSid,   // LPCWSTR optional
    int dwContext,   // MSIINSTALLCONTEXT
    uint dwOptions,   // DWORD
    uint dwIndex,   // DWORD
    uint* pdwDiskId,   // DWORD* optional, out
    wchar* szVolumeLabel,   // LPWSTR optional, out
    uint* pcchVolumeLabel,   // DWORD* optional, in/out
    wchar* szDiskPrompt,   // LPWSTR optional, out
    uint* pcchDiskPrompt   // DWORD* optional, in/out
);
ccall((:MsiSourceListEnumMediaDisksW, "msi.dll"), stdcall, UInt32,
      (Cwstring, Cwstring, Int32, UInt32, UInt32, Ptr{UInt32}, Ptr{UInt16}, Ptr{UInt32}, Ptr{UInt16}, Ptr{UInt32}),
      szProductCodeOrPatchCode, szUserSid, dwContext, dwOptions, dwIndex, pdwDiskId, szVolumeLabel, pcchVolumeLabel, szDiskPrompt, pcchDiskPrompt)
# szProductCodeOrPatchCode : LPCWSTR -> Cwstring
# szUserSid : LPCWSTR optional -> Cwstring
# dwContext : MSIINSTALLCONTEXT -> Int32
# dwOptions : DWORD -> UInt32
# dwIndex : DWORD -> UInt32
# pdwDiskId : DWORD* optional, out -> Ptr{UInt32}
# szVolumeLabel : LPWSTR optional, out -> Ptr{UInt16}
# pcchVolumeLabel : DWORD* optional, in/out -> Ptr{UInt32}
# szDiskPrompt : LPWSTR optional, out -> Ptr{UInt16}
# pcchDiskPrompt : DWORD* optional, in/out -> Ptr{UInt32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。
local ffi = require("ffi")
ffi.cdef[[
uint32_t MsiSourceListEnumMediaDisksW(
    const uint16_t* szProductCodeOrPatchCode,
    const uint16_t* szUserSid,
    int32_t dwContext,
    uint32_t dwOptions,
    uint32_t dwIndex,
    uint32_t* pdwDiskId,
    uint16_t* szVolumeLabel,
    uint32_t* pcchVolumeLabel,
    uint16_t* szDiskPrompt,
    uint32_t* pcchDiskPrompt);
]]
local msi = ffi.load("msi")
-- msi.MsiSourceListEnumMediaDisksW(szProductCodeOrPatchCode, szUserSid, dwContext, dwOptions, dwIndex, pdwDiskId, szVolumeLabel, pcchVolumeLabel, szDiskPrompt, pcchDiskPrompt)
-- szProductCodeOrPatchCode : LPCWSTR
-- szUserSid : LPCWSTR optional
-- dwContext : MSIINSTALLCONTEXT
-- dwOptions : DWORD
-- dwIndex : DWORD
-- pdwDiskId : DWORD* optional, out
-- szVolumeLabel : LPWSTR optional, out
-- pcchVolumeLabel : DWORD* optional, in/out
-- szDiskPrompt : LPWSTR optional, out
-- pcchDiskPrompt : DWORD* optional, in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
-- Unicode(-W): uint16_t* には UTF-16LE のバッファ(ffi.new("uint16_t[?]", ...))を渡す。
const koffi = require('koffi');
const lib = koffi.load('msi.dll');
const MsiSourceListEnumMediaDisksW = lib.func('__stdcall', 'MsiSourceListEnumMediaDisksW', 'uint32_t', ['str16', 'str16', 'int32_t', 'uint32_t', 'uint32_t', 'uint32_t *', 'uint16_t *', 'uint32_t *', 'uint16_t *', 'uint32_t *']);
// MsiSourceListEnumMediaDisksW(szProductCodeOrPatchCode, szUserSid, dwContext, dwOptions, dwIndex, pdwDiskId, szVolumeLabel, pcchVolumeLabel, szDiskPrompt, pcchDiskPrompt)
// szProductCodeOrPatchCode : LPCWSTR -> 'str16'
// szUserSid : LPCWSTR optional -> 'str16'
// dwContext : MSIINSTALLCONTEXT -> 'int32_t'
// dwOptions : DWORD -> 'uint32_t'
// dwIndex : DWORD -> 'uint32_t'
// pdwDiskId : DWORD* optional, out -> 'uint32_t *'
// szVolumeLabel : LPWSTR optional, out -> 'uint16_t *'
// pcchVolumeLabel : DWORD* optional, in/out -> 'uint32_t *'
// szDiskPrompt : LPWSTR optional, out -> 'uint16_t *'
// pcchDiskPrompt : DWORD* optional, in/out -> 'uint32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("msi.dll", {
  MsiSourceListEnumMediaDisksW: { parameters: ["buffer", "buffer", "i32", "u32", "u32", "pointer", "buffer", "pointer", "buffer", "pointer"], result: "u32" },
});
// lib.symbols.MsiSourceListEnumMediaDisksW(szProductCodeOrPatchCode, szUserSid, dwContext, dwOptions, dwIndex, pdwDiskId, szVolumeLabel, pcchVolumeLabel, szDiskPrompt, pcchDiskPrompt)
// szProductCodeOrPatchCode : LPCWSTR -> "buffer"
// szUserSid : LPCWSTR optional -> "buffer"
// dwContext : MSIINSTALLCONTEXT -> "i32"
// dwOptions : DWORD -> "u32"
// dwIndex : DWORD -> "u32"
// pdwDiskId : DWORD* optional, out -> "pointer"
// szVolumeLabel : LPWSTR optional, out -> "buffer"
// pcchVolumeLabel : DWORD* optional, in/out -> "pointer"
// szDiskPrompt : LPWSTR optional, out -> "buffer"
// pcchDiskPrompt : DWORD* optional, in/out -> "pointer"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
uint32_t MsiSourceListEnumMediaDisksW(
    const uint16_t* szProductCodeOrPatchCode,
    const uint16_t* szUserSid,
    int32_t dwContext,
    uint32_t dwOptions,
    uint32_t dwIndex,
    uint32_t* pdwDiskId,
    uint16_t* szVolumeLabel,
    uint32_t* pcchVolumeLabel,
    uint16_t* szDiskPrompt,
    uint32_t* pcchDiskPrompt);
C, "msi.dll");
// $ffi->MsiSourceListEnumMediaDisksW(szProductCodeOrPatchCode, szUserSid, dwContext, dwOptions, dwIndex, pdwDiskId, szVolumeLabel, pcchVolumeLabel, szDiskPrompt, pcchDiskPrompt);
// szProductCodeOrPatchCode : LPCWSTR
// szUserSid : LPCWSTR optional
// dwContext : MSIINSTALLCONTEXT
// dwOptions : DWORD
// dwIndex : DWORD
// pdwDiskId : DWORD* optional, out
// szVolumeLabel : LPWSTR optional, out
// pcchVolumeLabel : DWORD* optional, in/out
// szDiskPrompt : LPWSTR optional, out
// pcchDiskPrompt : 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.UNICODE_OPTIONS);
    int MsiSourceListEnumMediaDisksW(
        WString szProductCodeOrPatchCode,   // LPCWSTR
        WString szUserSid,   // LPCWSTR optional
        int dwContext,   // MSIINSTALLCONTEXT
        int dwOptions,   // DWORD
        int dwIndex,   // DWORD
        IntByReference pdwDiskId,   // DWORD* optional, out
        char[] szVolumeLabel,   // LPWSTR optional, out
        IntByReference pcchVolumeLabel,   // DWORD* optional, in/out
        char[] szDiskPrompt,   // LPWSTR optional, out
        IntByReference pcchDiskPrompt   // DWORD* optional, in/out
    );
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。
@[Link("msi")]
lib Libmsi
  fun MsiSourceListEnumMediaDisksW = MsiSourceListEnumMediaDisksW(
    szProductCodeOrPatchCode : UInt16*,   # LPCWSTR
    szUserSid : UInt16*,   # LPCWSTR optional
    dwContext : Int32,   # MSIINSTALLCONTEXT
    dwOptions : UInt32,   # DWORD
    dwIndex : UInt32,   # DWORD
    pdwDiskId : UInt32*,   # DWORD* optional, out
    szVolumeLabel : UInt16*,   # LPWSTR optional, out
    pcchVolumeLabel : UInt32*,   # DWORD* optional, in/out
    szDiskPrompt : UInt16*,   # LPWSTR optional, out
    pcchDiskPrompt : 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 MsiSourceListEnumMediaDisksWNative = Uint32 Function(Pointer<Utf16>, Pointer<Utf16>, Int32, Uint32, Uint32, Pointer<Uint32>, Pointer<Utf16>, Pointer<Uint32>, Pointer<Utf16>, Pointer<Uint32>);
typedef MsiSourceListEnumMediaDisksWDart = int Function(Pointer<Utf16>, Pointer<Utf16>, int, int, int, Pointer<Uint32>, Pointer<Utf16>, Pointer<Uint32>, Pointer<Utf16>, Pointer<Uint32>);
final MsiSourceListEnumMediaDisksW = DynamicLibrary.open('msi.dll')
    .lookupFunction<MsiSourceListEnumMediaDisksWNative, MsiSourceListEnumMediaDisksWDart>('MsiSourceListEnumMediaDisksW');
// szProductCodeOrPatchCode : LPCWSTR -> Pointer<Utf16>
// szUserSid : LPCWSTR optional -> Pointer<Utf16>
// dwContext : MSIINSTALLCONTEXT -> Int32
// dwOptions : DWORD -> Uint32
// dwIndex : DWORD -> Uint32
// pdwDiskId : DWORD* optional, out -> Pointer<Uint32>
// szVolumeLabel : LPWSTR optional, out -> Pointer<Utf16>
// pcchVolumeLabel : DWORD* optional, in/out -> Pointer<Uint32>
// szDiskPrompt : LPWSTR optional, out -> Pointer<Utf16>
// pcchDiskPrompt : DWORD* optional, in/out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function MsiSourceListEnumMediaDisksW(
  szProductCodeOrPatchCode: PWideChar;   // LPCWSTR
  szUserSid: PWideChar;   // LPCWSTR optional
  dwContext: Integer;   // MSIINSTALLCONTEXT
  dwOptions: DWORD;   // DWORD
  dwIndex: DWORD;   // DWORD
  pdwDiskId: Pointer;   // DWORD* optional, out
  szVolumeLabel: PWideChar;   // LPWSTR optional, out
  pcchVolumeLabel: Pointer;   // DWORD* optional, in/out
  szDiskPrompt: PWideChar;   // LPWSTR optional, out
  pcchDiskPrompt: Pointer   // DWORD* optional, in/out
): DWORD; stdcall;
  external 'msi.dll' name 'MsiSourceListEnumMediaDisksW';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "MsiSourceListEnumMediaDisksW"
  c_MsiSourceListEnumMediaDisksW :: CWString -> CWString -> Int32 -> Word32 -> Word32 -> Ptr Word32 -> CWString -> Ptr Word32 -> CWString -> Ptr Word32 -> IO Word32
-- szProductCodeOrPatchCode : LPCWSTR -> CWString
-- szUserSid : LPCWSTR optional -> CWString
-- dwContext : MSIINSTALLCONTEXT -> Int32
-- dwOptions : DWORD -> Word32
-- dwIndex : DWORD -> Word32
-- pdwDiskId : DWORD* optional, out -> Ptr Word32
-- szVolumeLabel : LPWSTR optional, out -> CWString
-- pcchVolumeLabel : DWORD* optional, in/out -> Ptr Word32
-- szDiskPrompt : LPWSTR optional, out -> CWString
-- pcchDiskPrompt : DWORD* optional, in/out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let msisourcelistenummediadisksw =
  foreign "MsiSourceListEnumMediaDisksW"
    ((ptr uint16_t) @-> (ptr uint16_t) @-> int32_t @-> uint32_t @-> uint32_t @-> (ptr uint32_t) @-> (ptr uint16_t) @-> (ptr uint32_t) @-> (ptr uint16_t) @-> (ptr uint32_t) @-> returning uint32_t)
(* szProductCodeOrPatchCode : LPCWSTR -> (ptr uint16_t) *)
(* szUserSid : LPCWSTR optional -> (ptr uint16_t) *)
(* dwContext : MSIINSTALLCONTEXT -> int32_t *)
(* dwOptions : DWORD -> uint32_t *)
(* dwIndex : DWORD -> uint32_t *)
(* pdwDiskId : DWORD* optional, out -> (ptr uint32_t) *)
(* szVolumeLabel : LPWSTR optional, out -> (ptr uint16_t) *)
(* pcchVolumeLabel : DWORD* optional, in/out -> (ptr uint32_t) *)
(* szDiskPrompt : LPWSTR optional, out -> (ptr uint16_t) *)
(* pcchDiskPrompt : 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 ("MsiSourceListEnumMediaDisksW" msi-source-list-enum-media-disks-w :convention :stdcall) :uint32
  (sz-product-code-or-patch-code (:string :encoding :utf-16le))   ; LPCWSTR
  (sz-user-sid (:string :encoding :utf-16le))   ; LPCWSTR optional
  (dw-context :int32)   ; MSIINSTALLCONTEXT
  (dw-options :uint32)   ; DWORD
  (dw-index :uint32)   ; DWORD
  (pdw-disk-id :pointer)   ; DWORD* optional, out
  (sz-volume-label :pointer)   ; LPWSTR optional, out
  (pcch-volume-label :pointer)   ; DWORD* optional, in/out
  (sz-disk-prompt :pointer)   ; LPWSTR optional, out
  (pcch-disk-prompt :pointer))   ; DWORD* optional, in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $MsiSourceListEnumMediaDisksW = Win32::API::More->new('msi',
    'DWORD MsiSourceListEnumMediaDisksW(LPCWSTR szProductCodeOrPatchCode, LPCWSTR szUserSid, int dwContext, DWORD dwOptions, DWORD dwIndex, LPVOID pdwDiskId, LPWSTR szVolumeLabel, LPVOID pcchVolumeLabel, LPWSTR szDiskPrompt, LPVOID pcchDiskPrompt)');
# my $ret = $MsiSourceListEnumMediaDisksW->Call($szProductCodeOrPatchCode, $szUserSid, $dwContext, $dwOptions, $dwIndex, $pdwDiskId, $szVolumeLabel, $pcchVolumeLabel, $szDiskPrompt, $pcchDiskPrompt);
# szProductCodeOrPatchCode : LPCWSTR -> LPCWSTR
# szUserSid : LPCWSTR optional -> LPCWSTR
# dwContext : MSIINSTALLCONTEXT -> int
# dwOptions : DWORD -> DWORD
# dwIndex : DWORD -> DWORD
# pdwDiskId : DWORD* optional, out -> LPVOID
# szVolumeLabel : LPWSTR optional, out -> LPWSTR
# pcchVolumeLabel : DWORD* optional, in/out -> LPVOID
# szDiskPrompt : LPWSTR optional, out -> LPWSTR
# pcchDiskPrompt : DWORD* optional, in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。

関連項目

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