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

MsiSourceListAddMediaDiskA

関数
ソースリストにメディアディスクのラベルとプロンプトを登録する。
DLLmsi.dll文字セットANSI (-A)呼出規約winapi対応OSwindows8.0

シグネチャ

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

DWORD MsiSourceListAddMediaDiskA(
    LPCSTR szProductCodeOrPatchCode,
    LPCSTR szUserSid,   // optional
    MSIINSTALLCONTEXT dwContext,
    DWORD dwOptions,
    DWORD dwDiskId,
    LPCSTR szVolumeLabel,   // optional
    LPCSTR szDiskPrompt   // optional
);

パラメーター

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

このパラメーターには、製品またはパッチを保持するユーザーアカウントを指定する文字列 SID を指定できます。SID は検証も解決もされません。誤った SID を指定すると ERROR_UNKNOWN_PRODUCT または ERROR_UNKNOWN_PATCH が返される場合があります。

Type of SID Meaning
NULL
NULL は現在ログオンしているユーザーを表します。現在のユーザーアカウントを参照する場合、szUserSIDNULL にし、dwContextMSIINSTALLCONTEXT_USERMANAGED または MSIINSTALLCONTEXT_USERUNMANAGED にできます。
User SID
システム内の特定のユーザーに対する列挙を指定します。ユーザー SID の例として "S-1-3-64-2415071341-1358098788-3127455600-2561" があります。
Note 特殊 SID 文字列 s-1-5-18 (system) は、コンピューター単位 (per-machine) でインストールされた製品やパッチの列挙には使用できません。SID 値を s-1-5-18 に設定すると ERROR_INVALID_PARAMETER が返されます。dwContextMSIINSTALLCONTEXT_MACHINE のみに設定されている場合、szUserSidNULL でなければなりません。
Note 特殊 SID 文字列 s-1-1-0 (everyone) は使用しないでください。SID 値を s-1-1-0 に設定すると失敗し、ERROR_INVALID_PARAM が返されます。
dwContextMSIINSTALLCONTEXTin

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

Type of context Meaning
MSIINSTALLCONTEXT_USERMANAGED
製品またはパッチのインスタンスがユーザー単位の管理対象 (per-user-managed) コンテキストに存在します。
MSIINSTALLCONTEXT_USERUNMANAGED
製品またはパッチのインスタンスがユーザー単位の非管理対象 (per-user-unmanaged) コンテキストに存在します。
MSIINSTALLCONTEXT_MACHINE
製品またはパッチのインスタンスがコンピューター単位 (per-machine) コンテキストに存在します。
dwOptionsDWORDin

dwOptions の値は、szProductCodeOrPatchCode の意味を指定します。

Flag Meaning
MSICODE_PRODUCT
szProductCodeOrPatchCode は製品コード GUID です。
MSICODE_PATCH
szProductCodeOrPatchCode はパッチコード GUID です。
dwDiskIdDWORDinこのパラメーターは、追加または更新するディスクの ID を指定します。
szVolumeLabelLPCSTRinoptionalszVolumeLabel は、追加または更新するディスクのラベルを指定します。更新を行うと、レジストリ内の既存のボリュームラベルが上書きされます。ディスクプロンプトのみを変更する場合は、レジストリから既存のボリュームラベルを取得し、新しいディスクプロンプトと共にこの呼び出しに指定します。szVolumeLabelNULL または空文字列を渡すと、空文字列 (長さ 0 バイト) がボリュームラベルとして登録されます。
szDiskPromptLPCSTRinoptionalMsiSourceListAddMediaDisk の呼び出し時、szDiskPrompt は追加または更新するディスクのディスクプロンプトを指定します。更新を行うと、登録済みのディスクプロンプトが上書きされます。 ボリュームラベルのみを変更する場合は、登録済みの既存のディスクプロンプトを取得し、新しいボリュームラベルと共に MsiSourceListAddMediaDisk を呼び出す際に指定します。NULL または空文字列を渡すと、空文字列 (長さ 0 バイト) がディスクプロンプトとして登録されます。

戻り値の型: DWORD

公式ドキュメント

MsiSourceListAddMediaDisk 関数は、登録済みの製品またはパッチのメディアソースに対してディスクを追加または更新します。(ANSI)

戻り値

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

Value Meaning
ERROR_ACCESS_DENIED
ユーザーに、指定されたメディアソースまたは指定された製品やパッチを読み取る権限がありません。これは、メディアソース、製品、またはパッチが見つかったかどうかを示すものではありません。
ERROR_BAD_CONFIGURATION
構成データが破損しています。
ERROR_INSTALL_SERVICE_FAILURE
Windows Installer サービスにアクセスできませんでした。
ERROR_INVALID_PARAMETER
関数に無効なパラメーターが渡されました。
ERROR_SUCCESS
値が正常に並べ替えられました。
ERROR_UNKNOWN_PATCH
パッチが見つかりませんでした。
ERROR_UNKNOWN_PRODUCT
製品が見つかりませんでした。
ERROR_FUNCTION_FAILED
予期しない内部エラーが発生しました。

解説(Remarks)

管理者は、コンピューターコンテキスト下に存在する製品やパッチのインスタンス、または自身のユーザー単位コンテキスト (管理対象または非管理対象) 下に存在する製品やパッチのインスタンスのインストールを変更できます。また、任意のユーザーのユーザー単位の管理対象 (per-user-managed) コンテキスト下に存在する製品やパッチのインスタンスのインストールを変更できます。管理者は、他のユーザーのユーザー単位の非管理対象 (per-user-unmanaged) コンテキスト下に存在する、その他のユーザーによる製品やパッチのインスタンスのインストールは変更できません。

管理者以外のユーザーは、他のユーザーのユーザー単位コンテキスト (管理対象または非管理対象) 下に存在する製品やパッチのインスタンスのインストールを変更できません。自身のユーザー単位の非管理対象 (per-user-unmanaged) コンテキスト下に存在する製品やパッチのインスタンスのインストールは変更できます。コンピューターコンテキストまたは自身のユーザー単位の管理対象 (per-user-managed) コンテキスト下の製品やパッチのインスタンスのインストールは、製品やパッチのソースを参照する権限が有効になっている場合に限り変更できます。ユーザーがソースを参照できるようにするには、ポリシーを設定します。詳細については、DisableBrowseAllowLockdownBrowseAllowLockDownMedia、および AlwaysInstallElevated の各ポリシーを参照してください。

メモ

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

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

MsiSourceListAddMediaDiskA = ctypes.windll.msi.MsiSourceListAddMediaDiskA
MsiSourceListAddMediaDiskA.restype = wintypes.DWORD
MsiSourceListAddMediaDiskA.argtypes = [
    wintypes.LPCSTR,  # szProductCodeOrPatchCode : LPCSTR
    wintypes.LPCSTR,  # szUserSid : LPCSTR optional
    ctypes.c_int,  # dwContext : MSIINSTALLCONTEXT
    wintypes.DWORD,  # dwOptions : DWORD
    wintypes.DWORD,  # dwDiskId : DWORD
    wintypes.LPCSTR,  # szVolumeLabel : LPCSTR optional
    wintypes.LPCSTR,  # szDiskPrompt : LPCSTR optional
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('msi.dll')
MsiSourceListAddMediaDiskA = Fiddle::Function.new(
  lib['MsiSourceListAddMediaDiskA'],
  [
    Fiddle::TYPE_VOIDP,  # szProductCodeOrPatchCode : LPCSTR
    Fiddle::TYPE_VOIDP,  # szUserSid : LPCSTR optional
    Fiddle::TYPE_INT,  # dwContext : MSIINSTALLCONTEXT
    -Fiddle::TYPE_INT,  # dwOptions : DWORD
    -Fiddle::TYPE_INT,  # dwDiskId : DWORD
    Fiddle::TYPE_VOIDP,  # szVolumeLabel : LPCSTR optional
    Fiddle::TYPE_VOIDP,  # szDiskPrompt : LPCSTR optional
  ],
  -Fiddle::TYPE_INT)
#[link(name = "msi")]
extern "system" {
    fn MsiSourceListAddMediaDiskA(
        szProductCodeOrPatchCode: *const u8,  // LPCSTR
        szUserSid: *const u8,  // LPCSTR optional
        dwContext: i32,  // MSIINSTALLCONTEXT
        dwOptions: u32,  // DWORD
        dwDiskId: u32,  // DWORD
        szVolumeLabel: *const u8,  // LPCSTR optional
        szDiskPrompt: *const u8  // LPCSTR optional
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("msi.dll", CharSet = CharSet.Ansi)]
public static extern uint MsiSourceListAddMediaDiskA([MarshalAs(UnmanagedType.LPStr)] string szProductCodeOrPatchCode, [MarshalAs(UnmanagedType.LPStr)] string szUserSid, int dwContext, uint dwOptions, uint dwDiskId, [MarshalAs(UnmanagedType.LPStr)] string szVolumeLabel, [MarshalAs(UnmanagedType.LPStr)] string szDiskPrompt);
"@
$api = Add-Type -MemberDefinition $sig -Name 'msi_MsiSourceListAddMediaDiskA' -Namespace Win32 -PassThru
# $api::MsiSourceListAddMediaDiskA(szProductCodeOrPatchCode, szUserSid, dwContext, dwOptions, dwDiskId, szVolumeLabel, szDiskPrompt)
#uselib "msi.dll"
#func global MsiSourceListAddMediaDiskA "MsiSourceListAddMediaDiskA" sptr, sptr, sptr, sptr, sptr, sptr, sptr
; MsiSourceListAddMediaDiskA szProductCodeOrPatchCode, szUserSid, dwContext, dwOptions, dwDiskId, szVolumeLabel, szDiskPrompt   ; 戻り値は stat
; szProductCodeOrPatchCode : LPCSTR -> "sptr"
; szUserSid : LPCSTR optional -> "sptr"
; dwContext : MSIINSTALLCONTEXT -> "sptr"
; dwOptions : DWORD -> "sptr"
; dwDiskId : DWORD -> "sptr"
; szVolumeLabel : LPCSTR optional -> "sptr"
; szDiskPrompt : LPCSTR optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "msi.dll"
#cfunc global MsiSourceListAddMediaDiskA "MsiSourceListAddMediaDiskA" str, str, int, int, int, str, str
; res = MsiSourceListAddMediaDiskA(szProductCodeOrPatchCode, szUserSid, dwContext, dwOptions, dwDiskId, szVolumeLabel, szDiskPrompt)
; szProductCodeOrPatchCode : LPCSTR -> "str"
; szUserSid : LPCSTR optional -> "str"
; dwContext : MSIINSTALLCONTEXT -> "int"
; dwOptions : DWORD -> "int"
; dwDiskId : DWORD -> "int"
; szVolumeLabel : LPCSTR optional -> "str"
; szDiskPrompt : LPCSTR optional -> "str"
; DWORD MsiSourceListAddMediaDiskA(LPCSTR szProductCodeOrPatchCode, LPCSTR szUserSid, MSIINSTALLCONTEXT dwContext, DWORD dwOptions, DWORD dwDiskId, LPCSTR szVolumeLabel, LPCSTR szDiskPrompt)
#uselib "msi.dll"
#cfunc global MsiSourceListAddMediaDiskA "MsiSourceListAddMediaDiskA" str, str, int, int, int, str, str
; res = MsiSourceListAddMediaDiskA(szProductCodeOrPatchCode, szUserSid, dwContext, dwOptions, dwDiskId, szVolumeLabel, szDiskPrompt)
; szProductCodeOrPatchCode : LPCSTR -> "str"
; szUserSid : LPCSTR optional -> "str"
; dwContext : MSIINSTALLCONTEXT -> "int"
; dwOptions : DWORD -> "int"
; dwDiskId : DWORD -> "int"
; szVolumeLabel : LPCSTR optional -> "str"
; szDiskPrompt : LPCSTR optional -> "str"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	msi = windows.NewLazySystemDLL("msi.dll")
	procMsiSourceListAddMediaDiskA = msi.NewProc("MsiSourceListAddMediaDiskA")
)

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

extern "msi" fn MsiSourceListAddMediaDiskA(
    szProductCodeOrPatchCode: [*c]const u8, // LPCSTR
    szUserSid: [*c]const u8, // LPCSTR optional
    dwContext: i32, // MSIINSTALLCONTEXT
    dwOptions: u32, // DWORD
    dwDiskId: u32, // DWORD
    szVolumeLabel: [*c]const u8, // LPCSTR optional
    szDiskPrompt: [*c]const u8 // LPCSTR optional
) callconv(std.os.windows.WINAPI) u32;
proc MsiSourceListAddMediaDiskA(
    szProductCodeOrPatchCode: cstring,  # LPCSTR
    szUserSid: cstring,  # LPCSTR optional
    dwContext: int32,  # MSIINSTALLCONTEXT
    dwOptions: uint32,  # DWORD
    dwDiskId: uint32,  # DWORD
    szVolumeLabel: cstring,  # LPCSTR optional
    szDiskPrompt: cstring  # LPCSTR optional
): uint32 {.importc: "MsiSourceListAddMediaDiskA", stdcall, dynlib: "msi.dll".}
pragma(lib, "msi");
extern(Windows)
uint MsiSourceListAddMediaDiskA(
    const(char)* szProductCodeOrPatchCode,   // LPCSTR
    const(char)* szUserSid,   // LPCSTR optional
    int dwContext,   // MSIINSTALLCONTEXT
    uint dwOptions,   // DWORD
    uint dwDiskId,   // DWORD
    const(char)* szVolumeLabel,   // LPCSTR optional
    const(char)* szDiskPrompt   // LPCSTR optional
);
ccall((:MsiSourceListAddMediaDiskA, "msi.dll"), stdcall, UInt32,
      (Cstring, Cstring, Int32, UInt32, UInt32, Cstring, Cstring),
      szProductCodeOrPatchCode, szUserSid, dwContext, dwOptions, dwDiskId, szVolumeLabel, szDiskPrompt)
# szProductCodeOrPatchCode : LPCSTR -> Cstring
# szUserSid : LPCSTR optional -> Cstring
# dwContext : MSIINSTALLCONTEXT -> Int32
# dwOptions : DWORD -> UInt32
# dwDiskId : DWORD -> UInt32
# szVolumeLabel : LPCSTR optional -> Cstring
# szDiskPrompt : LPCSTR optional -> Cstring
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
uint32_t MsiSourceListAddMediaDiskA(
    const char* szProductCodeOrPatchCode,
    const char* szUserSid,
    int32_t dwContext,
    uint32_t dwOptions,
    uint32_t dwDiskId,
    const char* szVolumeLabel,
    const char* szDiskPrompt);
]]
local msi = ffi.load("msi")
-- msi.MsiSourceListAddMediaDiskA(szProductCodeOrPatchCode, szUserSid, dwContext, dwOptions, dwDiskId, szVolumeLabel, szDiskPrompt)
-- szProductCodeOrPatchCode : LPCSTR
-- szUserSid : LPCSTR optional
-- dwContext : MSIINSTALLCONTEXT
-- dwOptions : DWORD
-- dwDiskId : DWORD
-- szVolumeLabel : LPCSTR optional
-- szDiskPrompt : LPCSTR optional
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('msi.dll');
const MsiSourceListAddMediaDiskA = lib.func('__stdcall', 'MsiSourceListAddMediaDiskA', 'uint32_t', ['str', 'str', 'int32_t', 'uint32_t', 'uint32_t', 'str', 'str']);
// MsiSourceListAddMediaDiskA(szProductCodeOrPatchCode, szUserSid, dwContext, dwOptions, dwDiskId, szVolumeLabel, szDiskPrompt)
// szProductCodeOrPatchCode : LPCSTR -> 'str'
// szUserSid : LPCSTR optional -> 'str'
// dwContext : MSIINSTALLCONTEXT -> 'int32_t'
// dwOptions : DWORD -> 'uint32_t'
// dwDiskId : DWORD -> 'uint32_t'
// szVolumeLabel : LPCSTR optional -> 'str'
// szDiskPrompt : LPCSTR optional -> 'str'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("msi.dll", {
  MsiSourceListAddMediaDiskA: { parameters: ["buffer", "buffer", "i32", "u32", "u32", "buffer", "buffer"], result: "u32" },
});
// lib.symbols.MsiSourceListAddMediaDiskA(szProductCodeOrPatchCode, szUserSid, dwContext, dwOptions, dwDiskId, szVolumeLabel, szDiskPrompt)
// szProductCodeOrPatchCode : LPCSTR -> "buffer"
// szUserSid : LPCSTR optional -> "buffer"
// dwContext : MSIINSTALLCONTEXT -> "i32"
// dwOptions : DWORD -> "u32"
// dwDiskId : DWORD -> "u32"
// szVolumeLabel : LPCSTR optional -> "buffer"
// szDiskPrompt : LPCSTR optional -> "buffer"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
uint32_t MsiSourceListAddMediaDiskA(
    const char* szProductCodeOrPatchCode,
    const char* szUserSid,
    int32_t dwContext,
    uint32_t dwOptions,
    uint32_t dwDiskId,
    const char* szVolumeLabel,
    const char* szDiskPrompt);
C, "msi.dll");
// $ffi->MsiSourceListAddMediaDiskA(szProductCodeOrPatchCode, szUserSid, dwContext, dwOptions, dwDiskId, szVolumeLabel, szDiskPrompt);
// szProductCodeOrPatchCode : LPCSTR
// szUserSid : LPCSTR optional
// dwContext : MSIINSTALLCONTEXT
// dwOptions : DWORD
// dwDiskId : DWORD
// szVolumeLabel : LPCSTR optional
// szDiskPrompt : LPCSTR optional
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。
import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;

public interface Msi extends StdCallLibrary {
    Msi INSTANCE = Native.load("msi", Msi.class, W32APIOptions.ASCII_OPTIONS);
    int MsiSourceListAddMediaDiskA(
        String szProductCodeOrPatchCode,   // LPCSTR
        String szUserSid,   // LPCSTR optional
        int dwContext,   // MSIINSTALLCONTEXT
        int dwOptions,   // DWORD
        int dwDiskId,   // DWORD
        String szVolumeLabel,   // LPCSTR optional
        String szDiskPrompt   // LPCSTR optional
    );
}
@[Link("msi")]
lib Libmsi
  fun MsiSourceListAddMediaDiskA = MsiSourceListAddMediaDiskA(
    szProductCodeOrPatchCode : UInt8*,   # LPCSTR
    szUserSid : UInt8*,   # LPCSTR optional
    dwContext : Int32,   # MSIINSTALLCONTEXT
    dwOptions : UInt32,   # DWORD
    dwDiskId : UInt32,   # DWORD
    szVolumeLabel : UInt8*,   # LPCSTR optional
    szDiskPrompt : UInt8*   # LPCSTR optional
  ) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

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

foreign import stdcall safe "MsiSourceListAddMediaDiskA"
  c_MsiSourceListAddMediaDiskA :: CString -> CString -> Int32 -> Word32 -> Word32 -> CString -> CString -> IO Word32
-- szProductCodeOrPatchCode : LPCSTR -> CString
-- szUserSid : LPCSTR optional -> CString
-- dwContext : MSIINSTALLCONTEXT -> Int32
-- dwOptions : DWORD -> Word32
-- dwDiskId : DWORD -> Word32
-- szVolumeLabel : LPCSTR optional -> CString
-- szDiskPrompt : LPCSTR optional -> CString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let msisourcelistaddmediadiska =
  foreign "MsiSourceListAddMediaDiskA"
    (string @-> string @-> int32_t @-> uint32_t @-> uint32_t @-> string @-> string @-> returning uint32_t)
(* szProductCodeOrPatchCode : LPCSTR -> string *)
(* szUserSid : LPCSTR optional -> string *)
(* dwContext : MSIINSTALLCONTEXT -> int32_t *)
(* dwOptions : DWORD -> uint32_t *)
(* dwDiskId : DWORD -> uint32_t *)
(* szVolumeLabel : LPCSTR optional -> string *)
(* szDiskPrompt : LPCSTR optional -> string *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library msi (t "msi.dll"))
(cffi:use-foreign-library msi)

(cffi:defcfun ("MsiSourceListAddMediaDiskA" msi-source-list-add-media-disk-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-disk-id :uint32)   ; DWORD
  (sz-volume-label :string)   ; LPCSTR optional
  (sz-disk-prompt :string))   ; LPCSTR optional
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $MsiSourceListAddMediaDiskA = Win32::API::More->new('msi',
    'DWORD MsiSourceListAddMediaDiskA(LPCSTR szProductCodeOrPatchCode, LPCSTR szUserSid, int dwContext, DWORD dwOptions, DWORD dwDiskId, LPCSTR szVolumeLabel, LPCSTR szDiskPrompt)');
# my $ret = $MsiSourceListAddMediaDiskA->Call($szProductCodeOrPatchCode, $szUserSid, $dwContext, $dwOptions, $dwDiskId, $szVolumeLabel, $szDiskPrompt);
# szProductCodeOrPatchCode : LPCSTR -> LPCSTR
# szUserSid : LPCSTR optional -> LPCSTR
# dwContext : MSIINSTALLCONTEXT -> int
# dwOptions : DWORD -> DWORD
# dwDiskId : DWORD -> DWORD
# szVolumeLabel : LPCSTR optional -> LPCSTR
# szDiskPrompt : LPCSTR optional -> LPCSTR
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

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