MsiSourceListAddMediaDiskW
関数シグネチャ
// msi.dll (Unicode / -W)
#include <windows.h>
DWORD MsiSourceListAddMediaDiskW(
LPCWSTR szProductCodeOrPatchCode,
LPCWSTR szUserSid, // optional
MSIINSTALLCONTEXT dwContext,
DWORD dwOptions,
DWORD dwDiskId,
LPCWSTR szVolumeLabel, // optional
LPCWSTR szDiskPrompt // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| szProductCodeOrPatchCode | LPCWSTR | in | 製品またはパッチの ProductCode またはパッチ GUID。null 終端文字列を使用します。文字列が 39 文字を超える場合、関数は失敗し ERROR_INVALID_PARAMETER を返します。このパラメーターを NULL にすることはできません。 | ||||||||
| szUserSid | LPCWSTR | inoptional | このパラメーターには、製品またはパッチを保持するユーザーアカウントを指定する文字列形式の SID を指定できます。SID は検証も解決もされません。誤った SID を指定すると ERROR_UNKNOWN_PRODUCT または ERROR_UNKNOWN_PATCH が返される場合があります。
注意 特別な SID 文字列 s-1-5-18 (system) は、コンピューター単位 (per-machine) でインストールされた製品やパッチの列挙には使用できません。SID 値を s-1-5-18 に設定すると ERROR_INVALID_PARAMETER が返されます。dwContext を MSIINSTALLCONTEXT_MACHINE のみに設定する場合、szUserSid は NULL でなければなりません。
注意 特別な SID 文字列 s-1-1-0 (everyone) は使用しないでください。SID 値を s-1-1-0 に設定すると失敗し ERROR_INVALID_PARAM を返します。
| ||||||||
| dwContext | MSIINSTALLCONTEXT | in | このパラメーターは、製品またはパッチのインスタンスのコンテキストを指定します。このパラメーターには次のいずれかの値を指定できます。
| ||||||||
| dwOptions | DWORD | in | dwOptions 値は szProductCodeOrPatchCode の意味を指定します。
| ||||||||
| dwDiskId | DWORD | in | このパラメーターは、追加または更新するディスクの ID を指定します。 | ||||||||
| szVolumeLabel | LPCWSTR | inoptional | szVolumeLabel は、追加または更新するディスクのラベルを指定します。更新を行うと、レジストリ内の既存のボリュームラベルが上書きされます。ディスクプロンプトのみを変更するには、レジストリから既存のボリュームラベルを取得し、新しいディスクプロンプトとともにこの呼び出しで指定します。szVolumeLabel に NULL または空文字列を渡すと、ボリュームラベルとして空文字列 (長さ 0 バイト) が登録されます。 | ||||||||
| szDiskPrompt | LPCWSTR | inoptional | MsiSourceListAddMediaDisk への入力時、szDiskPrompt は追加または更新するディスクのディスクプロンプトを指定します。更新を行うと、登録済みのディスクプロンプトが上書きされます。 ボリュームラベルのみを変更するには、登録済みの既存のディスクプロンプトを取得し、新しいボリュームラベルとともに MsiSourceListAddMediaDisk を呼び出す際に指定します。NULL または空文字列を渡すと、ディスクプロンプトとして空文字列 (長さ 0 バイト) が登録されます。 |
戻り値の型: DWORD
公式ドキュメント
MsiSourceListAddMediaDisk 関数は、登録された製品またはパッチのメディアソースに対してディスクを追加または更新します。(Unicode)
戻り値
MsiSourceListAddMediaDisk 関数は次の値を返します。
| 値 | 意味 |
|---|---|
| ユーザーに、指定されたメディアソースまたは指定された製品もしくはパッチを読み取る権限がありません。これは、メディアソース、製品、またはパッチが見つかったかどうかを示すものではありません。 | |
| 構成データが破損しています。 | |
| Windows Installer サービスにアクセスできませんでした。 | |
| 無効なパラメーターが関数に渡されました。 | |
| 値が正常に並べ替えられました。 | |
| パッチが見つかりませんでした。 | |
| 製品が見つかりませんでした。 | |
| 予期しない内部エラーが発生しました。 |
解説(Remarks)
管理者は、コンピューターコンテキスト下、または自身のユーザー単位コンテキスト (管理対象または非管理対象) 下に存在する製品もしくはパッチのインスタンスのインストールを変更できます。また、任意のユーザーのユーザー単位の管理対象コンテキスト下に存在する製品もしくはパッチのインスタンスのインストールも変更できます。ただし、他のユーザーのユーザー単位の非管理対象コンテキスト下に存在する、そのユーザーによる製品もしくはパッチのインスタンスのインストールは変更できません。
管理者以外のユーザーは、他のユーザーのユーザー単位コンテキスト (管理対象または非管理対象) 下に存在する製品もしくはパッチのインスタンスのインストールを変更できません。自身のユーザー単位の非管理対象コンテキスト下に存在する製品もしくはパッチのインスタンスのインストールは変更できます。コンピューターコンテキスト下、または自身のユーザー単位の管理対象コンテキスト下にある製品もしくはパッチのインスタンスのインストールは、製品またはパッチのソースを参照する権限が付与されている場合に限り変更できます。ソースの参照を許可する権限は、ポリシーの設定によってユーザーに付与できます。詳細については、DisableBrowse、AllowLockdownBrowse、AllowLockDownMedia、AlwaysInstallElevated の各ポリシーを参照してください。
msi.h ヘッダーは、UNICODE プリプロセッサ定数の定義に基づいて、この関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして MsiSourceListAddMediaDisk を定義します。エンコーディング中立のエイリアスの使用を、エンコーディング中立でないコードと混在させると、不一致が生じてコンパイルエラーや実行時エラーの原因になることがあります。詳細については、関数プロトタイプの規約 を参照してください。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// msi.dll (Unicode / -W)
#include <windows.h>
DWORD MsiSourceListAddMediaDiskW(
LPCWSTR szProductCodeOrPatchCode,
LPCWSTR szUserSid, // optional
MSIINSTALLCONTEXT dwContext,
DWORD dwOptions,
DWORD dwDiskId,
LPCWSTR szVolumeLabel, // optional
LPCWSTR szDiskPrompt // optional
);[DllImport("msi.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern uint MsiSourceListAddMediaDiskW(
[MarshalAs(UnmanagedType.LPWStr)] string szProductCodeOrPatchCode, // LPCWSTR
[MarshalAs(UnmanagedType.LPWStr)] string szUserSid, // LPCWSTR optional
int dwContext, // MSIINSTALLCONTEXT
uint dwOptions, // DWORD
uint dwDiskId, // DWORD
[MarshalAs(UnmanagedType.LPWStr)] string szVolumeLabel, // LPCWSTR optional
[MarshalAs(UnmanagedType.LPWStr)] string szDiskPrompt // LPCWSTR optional
);<DllImport("msi.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function MsiSourceListAddMediaDiskW(
<MarshalAs(UnmanagedType.LPWStr)> szProductCodeOrPatchCode As String, ' LPCWSTR
<MarshalAs(UnmanagedType.LPWStr)> szUserSid As String, ' LPCWSTR optional
dwContext As Integer, ' MSIINSTALLCONTEXT
dwOptions As UInteger, ' DWORD
dwDiskId As UInteger, ' DWORD
<MarshalAs(UnmanagedType.LPWStr)> szVolumeLabel As String, ' LPCWSTR optional
<MarshalAs(UnmanagedType.LPWStr)> szDiskPrompt As String ' LPCWSTR optional
) As UInteger
End Function' szProductCodeOrPatchCode : LPCWSTR
' szUserSid : LPCWSTR optional
' dwContext : MSIINSTALLCONTEXT
' dwOptions : DWORD
' dwDiskId : DWORD
' szVolumeLabel : LPCWSTR optional
' szDiskPrompt : LPCWSTR optional
Declare PtrSafe Function MsiSourceListAddMediaDiskW Lib "msi" ( _
ByVal szProductCodeOrPatchCode As LongPtr, _
ByVal szUserSid As LongPtr, _
ByVal dwContext As Long, _
ByVal dwOptions As Long, _
ByVal dwDiskId As Long, _
ByVal szVolumeLabel As LongPtr, _
ByVal szDiskPrompt 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
MsiSourceListAddMediaDiskW = ctypes.windll.msi.MsiSourceListAddMediaDiskW
MsiSourceListAddMediaDiskW.restype = wintypes.DWORD
MsiSourceListAddMediaDiskW.argtypes = [
wintypes.LPCWSTR, # szProductCodeOrPatchCode : LPCWSTR
wintypes.LPCWSTR, # szUserSid : LPCWSTR optional
ctypes.c_int, # dwContext : MSIINSTALLCONTEXT
wintypes.DWORD, # dwOptions : DWORD
wintypes.DWORD, # dwDiskId : DWORD
wintypes.LPCWSTR, # szVolumeLabel : LPCWSTR optional
wintypes.LPCWSTR, # szDiskPrompt : LPCWSTR optional
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('msi.dll')
MsiSourceListAddMediaDiskW = Fiddle::Function.new(
lib['MsiSourceListAddMediaDiskW'],
[
Fiddle::TYPE_VOIDP, # szProductCodeOrPatchCode : LPCWSTR
Fiddle::TYPE_VOIDP, # szUserSid : LPCWSTR optional
Fiddle::TYPE_INT, # dwContext : MSIINSTALLCONTEXT
-Fiddle::TYPE_INT, # dwOptions : DWORD
-Fiddle::TYPE_INT, # dwDiskId : DWORD
Fiddle::TYPE_VOIDP, # szVolumeLabel : LPCWSTR optional
Fiddle::TYPE_VOIDP, # szDiskPrompt : LPCWSTR optional
],
-Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "msi")]
extern "system" {
fn MsiSourceListAddMediaDiskW(
szProductCodeOrPatchCode: *const u16, // LPCWSTR
szUserSid: *const u16, // LPCWSTR optional
dwContext: i32, // MSIINSTALLCONTEXT
dwOptions: u32, // DWORD
dwDiskId: u32, // DWORD
szVolumeLabel: *const u16, // LPCWSTR optional
szDiskPrompt: *const u16 // LPCWSTR optional
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("msi.dll", CharSet = CharSet.Unicode)]
public static extern uint MsiSourceListAddMediaDiskW([MarshalAs(UnmanagedType.LPWStr)] string szProductCodeOrPatchCode, [MarshalAs(UnmanagedType.LPWStr)] string szUserSid, int dwContext, uint dwOptions, uint dwDiskId, [MarshalAs(UnmanagedType.LPWStr)] string szVolumeLabel, [MarshalAs(UnmanagedType.LPWStr)] string szDiskPrompt);
"@
$api = Add-Type -MemberDefinition $sig -Name 'msi_MsiSourceListAddMediaDiskW' -Namespace Win32 -PassThru
# $api::MsiSourceListAddMediaDiskW(szProductCodeOrPatchCode, szUserSid, dwContext, dwOptions, dwDiskId, szVolumeLabel, szDiskPrompt)#uselib "msi.dll"
#func global MsiSourceListAddMediaDiskW "MsiSourceListAddMediaDiskW" wptr, wptr, wptr, wptr, wptr, wptr, wptr
; MsiSourceListAddMediaDiskW szProductCodeOrPatchCode, szUserSid, dwContext, dwOptions, dwDiskId, szVolumeLabel, szDiskPrompt ; 戻り値は stat
; szProductCodeOrPatchCode : LPCWSTR -> "wptr"
; szUserSid : LPCWSTR optional -> "wptr"
; dwContext : MSIINSTALLCONTEXT -> "wptr"
; dwOptions : DWORD -> "wptr"
; dwDiskId : DWORD -> "wptr"
; szVolumeLabel : LPCWSTR optional -> "wptr"
; szDiskPrompt : LPCWSTR optional -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "msi.dll"
#cfunc global MsiSourceListAddMediaDiskW "MsiSourceListAddMediaDiskW" wstr, wstr, int, int, int, wstr, wstr
; res = MsiSourceListAddMediaDiskW(szProductCodeOrPatchCode, szUserSid, dwContext, dwOptions, dwDiskId, szVolumeLabel, szDiskPrompt)
; szProductCodeOrPatchCode : LPCWSTR -> "wstr"
; szUserSid : LPCWSTR optional -> "wstr"
; dwContext : MSIINSTALLCONTEXT -> "int"
; dwOptions : DWORD -> "int"
; dwDiskId : DWORD -> "int"
; szVolumeLabel : LPCWSTR optional -> "wstr"
; szDiskPrompt : LPCWSTR optional -> "wstr"; DWORD MsiSourceListAddMediaDiskW(LPCWSTR szProductCodeOrPatchCode, LPCWSTR szUserSid, MSIINSTALLCONTEXT dwContext, DWORD dwOptions, DWORD dwDiskId, LPCWSTR szVolumeLabel, LPCWSTR szDiskPrompt)
#uselib "msi.dll"
#cfunc global MsiSourceListAddMediaDiskW "MsiSourceListAddMediaDiskW" wstr, wstr, int, int, int, wstr, wstr
; res = MsiSourceListAddMediaDiskW(szProductCodeOrPatchCode, szUserSid, dwContext, dwOptions, dwDiskId, szVolumeLabel, szDiskPrompt)
; szProductCodeOrPatchCode : LPCWSTR -> "wstr"
; szUserSid : LPCWSTR optional -> "wstr"
; dwContext : MSIINSTALLCONTEXT -> "int"
; dwOptions : DWORD -> "int"
; dwDiskId : DWORD -> "int"
; szVolumeLabel : LPCWSTR optional -> "wstr"
; szDiskPrompt : LPCWSTR optional -> "wstr"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
msi = windows.NewLazySystemDLL("msi.dll")
procMsiSourceListAddMediaDiskW = msi.NewProc("MsiSourceListAddMediaDiskW")
)
// szProductCodeOrPatchCode (LPCWSTR), szUserSid (LPCWSTR optional), dwContext (MSIINSTALLCONTEXT), dwOptions (DWORD), dwDiskId (DWORD), szVolumeLabel (LPCWSTR optional), szDiskPrompt (LPCWSTR optional)
r1, _, err := procMsiSourceListAddMediaDiskW.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(szProductCodeOrPatchCode))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(szUserSid))),
uintptr(dwContext),
uintptr(dwOptions),
uintptr(dwDiskId),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(szVolumeLabel))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(szDiskPrompt))),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction MsiSourceListAddMediaDiskW(
szProductCodeOrPatchCode: PWideChar; // LPCWSTR
szUserSid: PWideChar; // LPCWSTR optional
dwContext: Integer; // MSIINSTALLCONTEXT
dwOptions: DWORD; // DWORD
dwDiskId: DWORD; // DWORD
szVolumeLabel: PWideChar; // LPCWSTR optional
szDiskPrompt: PWideChar // LPCWSTR optional
): DWORD; stdcall;
external 'msi.dll' name 'MsiSourceListAddMediaDiskW';result := DllCall("msi\MsiSourceListAddMediaDiskW"
, "WStr", szProductCodeOrPatchCode ; LPCWSTR
, "WStr", szUserSid ; LPCWSTR optional
, "Int", dwContext ; MSIINSTALLCONTEXT
, "UInt", dwOptions ; DWORD
, "UInt", dwDiskId ; DWORD
, "WStr", szVolumeLabel ; LPCWSTR optional
, "WStr", szDiskPrompt ; LPCWSTR optional
, "UInt") ; return: DWORD●MsiSourceListAddMediaDiskW(szProductCodeOrPatchCode, szUserSid, dwContext, dwOptions, dwDiskId, szVolumeLabel, szDiskPrompt) = DLL("msi.dll", "dword MsiSourceListAddMediaDiskW(char*, char*, int, dword, dword, char*, char*)")
# 呼び出し: MsiSourceListAddMediaDiskW(szProductCodeOrPatchCode, szUserSid, dwContext, dwOptions, dwDiskId, szVolumeLabel, szDiskPrompt)
# szProductCodeOrPatchCode : LPCWSTR -> "char*"
# szUserSid : LPCWSTR optional -> "char*"
# dwContext : MSIINSTALLCONTEXT -> "int"
# dwOptions : DWORD -> "dword"
# dwDiskId : DWORD -> "dword"
# szVolumeLabel : LPCWSTR optional -> "char*"
# szDiskPrompt : LPCWSTR optional -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。const std = @import("std");
extern "msi" fn MsiSourceListAddMediaDiskW(
szProductCodeOrPatchCode: [*c]const u16, // LPCWSTR
szUserSid: [*c]const u16, // LPCWSTR optional
dwContext: i32, // MSIINSTALLCONTEXT
dwOptions: u32, // DWORD
dwDiskId: u32, // DWORD
szVolumeLabel: [*c]const u16, // LPCWSTR optional
szDiskPrompt: [*c]const u16 // LPCWSTR optional
) callconv(std.os.windows.WINAPI) u32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。proc MsiSourceListAddMediaDiskW(
szProductCodeOrPatchCode: WideCString, # LPCWSTR
szUserSid: WideCString, # LPCWSTR optional
dwContext: int32, # MSIINSTALLCONTEXT
dwOptions: uint32, # DWORD
dwDiskId: uint32, # DWORD
szVolumeLabel: WideCString, # LPCWSTR optional
szDiskPrompt: WideCString # LPCWSTR optional
): uint32 {.importc: "MsiSourceListAddMediaDiskW", stdcall, dynlib: "msi.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。pragma(lib, "msi");
extern(Windows)
uint MsiSourceListAddMediaDiskW(
const(wchar)* szProductCodeOrPatchCode, // LPCWSTR
const(wchar)* szUserSid, // LPCWSTR optional
int dwContext, // MSIINSTALLCONTEXT
uint dwOptions, // DWORD
uint dwDiskId, // DWORD
const(wchar)* szVolumeLabel, // LPCWSTR optional
const(wchar)* szDiskPrompt // LPCWSTR optional
);ccall((:MsiSourceListAddMediaDiskW, "msi.dll"), stdcall, UInt32,
(Cwstring, Cwstring, Int32, UInt32, UInt32, Cwstring, Cwstring),
szProductCodeOrPatchCode, szUserSid, dwContext, dwOptions, dwDiskId, szVolumeLabel, szDiskPrompt)
# szProductCodeOrPatchCode : LPCWSTR -> Cwstring
# szUserSid : LPCWSTR optional -> Cwstring
# dwContext : MSIINSTALLCONTEXT -> Int32
# dwOptions : DWORD -> UInt32
# dwDiskId : DWORD -> UInt32
# szVolumeLabel : LPCWSTR optional -> Cwstring
# szDiskPrompt : LPCWSTR optional -> Cwstring
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。local ffi = require("ffi")
ffi.cdef[[
uint32_t MsiSourceListAddMediaDiskW(
const uint16_t* szProductCodeOrPatchCode,
const uint16_t* szUserSid,
int32_t dwContext,
uint32_t dwOptions,
uint32_t dwDiskId,
const uint16_t* szVolumeLabel,
const uint16_t* szDiskPrompt);
]]
local msi = ffi.load("msi")
-- msi.MsiSourceListAddMediaDiskW(szProductCodeOrPatchCode, szUserSid, dwContext, dwOptions, dwDiskId, szVolumeLabel, szDiskPrompt)
-- szProductCodeOrPatchCode : LPCWSTR
-- szUserSid : LPCWSTR optional
-- dwContext : MSIINSTALLCONTEXT
-- dwOptions : DWORD
-- dwDiskId : DWORD
-- szVolumeLabel : LPCWSTR optional
-- szDiskPrompt : LPCWSTR optional
-- 構造体/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 MsiSourceListAddMediaDiskW = lib.func('__stdcall', 'MsiSourceListAddMediaDiskW', 'uint32_t', ['str16', 'str16', 'int32_t', 'uint32_t', 'uint32_t', 'str16', 'str16']);
// MsiSourceListAddMediaDiskW(szProductCodeOrPatchCode, szUserSid, dwContext, dwOptions, dwDiskId, szVolumeLabel, szDiskPrompt)
// szProductCodeOrPatchCode : LPCWSTR -> 'str16'
// szUserSid : LPCWSTR optional -> 'str16'
// dwContext : MSIINSTALLCONTEXT -> 'int32_t'
// dwOptions : DWORD -> 'uint32_t'
// dwDiskId : DWORD -> 'uint32_t'
// szVolumeLabel : LPCWSTR optional -> 'str16'
// szDiskPrompt : LPCWSTR optional -> 'str16'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("msi.dll", {
MsiSourceListAddMediaDiskW: { parameters: ["buffer", "buffer", "i32", "u32", "u32", "buffer", "buffer"], result: "u32" },
});
// lib.symbols.MsiSourceListAddMediaDiskW(szProductCodeOrPatchCode, szUserSid, dwContext, dwOptions, dwDiskId, szVolumeLabel, szDiskPrompt)
// szProductCodeOrPatchCode : LPCWSTR -> "buffer"
// szUserSid : LPCWSTR optional -> "buffer"
// dwContext : MSIINSTALLCONTEXT -> "i32"
// dwOptions : DWORD -> "u32"
// dwDiskId : DWORD -> "u32"
// szVolumeLabel : LPCWSTR optional -> "buffer"
// szDiskPrompt : LPCWSTR optional -> "buffer"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t MsiSourceListAddMediaDiskW(
const uint16_t* szProductCodeOrPatchCode,
const uint16_t* szUserSid,
int32_t dwContext,
uint32_t dwOptions,
uint32_t dwDiskId,
const uint16_t* szVolumeLabel,
const uint16_t* szDiskPrompt);
C, "msi.dll");
// $ffi->MsiSourceListAddMediaDiskW(szProductCodeOrPatchCode, szUserSid, dwContext, dwOptions, dwDiskId, szVolumeLabel, szDiskPrompt);
// szProductCodeOrPatchCode : LPCWSTR
// szUserSid : LPCWSTR optional
// dwContext : MSIINSTALLCONTEXT
// dwOptions : DWORD
// dwDiskId : DWORD
// szVolumeLabel : LPCWSTR optional
// szDiskPrompt : LPCWSTR 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.UNICODE_OPTIONS);
int MsiSourceListAddMediaDiskW(
WString szProductCodeOrPatchCode, // LPCWSTR
WString szUserSid, // LPCWSTR optional
int dwContext, // MSIINSTALLCONTEXT
int dwOptions, // DWORD
int dwDiskId, // DWORD
WString szVolumeLabel, // LPCWSTR optional
WString szDiskPrompt // LPCWSTR optional
);
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。@[Link("msi")]
lib Libmsi
fun MsiSourceListAddMediaDiskW = MsiSourceListAddMediaDiskW(
szProductCodeOrPatchCode : UInt16*, # LPCWSTR
szUserSid : UInt16*, # LPCWSTR optional
dwContext : Int32, # MSIINSTALLCONTEXT
dwOptions : UInt32, # DWORD
dwDiskId : UInt32, # DWORD
szVolumeLabel : UInt16*, # LPCWSTR optional
szDiskPrompt : UInt16* # LPCWSTR optional
) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef MsiSourceListAddMediaDiskWNative = Uint32 Function(Pointer<Utf16>, Pointer<Utf16>, Int32, Uint32, Uint32, Pointer<Utf16>, Pointer<Utf16>);
typedef MsiSourceListAddMediaDiskWDart = int Function(Pointer<Utf16>, Pointer<Utf16>, int, int, int, Pointer<Utf16>, Pointer<Utf16>);
final MsiSourceListAddMediaDiskW = DynamicLibrary.open('msi.dll')
.lookupFunction<MsiSourceListAddMediaDiskWNative, MsiSourceListAddMediaDiskWDart>('MsiSourceListAddMediaDiskW');
// szProductCodeOrPatchCode : LPCWSTR -> Pointer<Utf16>
// szUserSid : LPCWSTR optional -> Pointer<Utf16>
// dwContext : MSIINSTALLCONTEXT -> Int32
// dwOptions : DWORD -> Uint32
// dwDiskId : DWORD -> Uint32
// szVolumeLabel : LPCWSTR optional -> Pointer<Utf16>
// szDiskPrompt : LPCWSTR optional -> Pointer<Utf16>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function MsiSourceListAddMediaDiskW(
szProductCodeOrPatchCode: PWideChar; // LPCWSTR
szUserSid: PWideChar; // LPCWSTR optional
dwContext: Integer; // MSIINSTALLCONTEXT
dwOptions: DWORD; // DWORD
dwDiskId: DWORD; // DWORD
szVolumeLabel: PWideChar; // LPCWSTR optional
szDiskPrompt: PWideChar // LPCWSTR optional
): DWORD; stdcall;
external 'msi.dll' name 'MsiSourceListAddMediaDiskW';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "MsiSourceListAddMediaDiskW"
c_MsiSourceListAddMediaDiskW :: CWString -> CWString -> Int32 -> Word32 -> Word32 -> CWString -> CWString -> IO Word32
-- szProductCodeOrPatchCode : LPCWSTR -> CWString
-- szUserSid : LPCWSTR optional -> CWString
-- dwContext : MSIINSTALLCONTEXT -> Int32
-- dwOptions : DWORD -> Word32
-- dwDiskId : DWORD -> Word32
-- szVolumeLabel : LPCWSTR optional -> CWString
-- szDiskPrompt : LPCWSTR optional -> CWString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let msisourcelistaddmediadiskw =
foreign "MsiSourceListAddMediaDiskW"
((ptr uint16_t) @-> (ptr uint16_t) @-> int32_t @-> uint32_t @-> uint32_t @-> (ptr uint16_t) @-> (ptr uint16_t) @-> returning uint32_t)
(* szProductCodeOrPatchCode : LPCWSTR -> (ptr uint16_t) *)
(* szUserSid : LPCWSTR optional -> (ptr uint16_t) *)
(* dwContext : MSIINSTALLCONTEXT -> int32_t *)
(* dwOptions : DWORD -> uint32_t *)
(* dwDiskId : DWORD -> uint32_t *)
(* szVolumeLabel : LPCWSTR optional -> (ptr uint16_t) *)
(* szDiskPrompt : LPCWSTR optional -> (ptr uint16_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library msi (t "msi.dll"))
(cffi:use-foreign-library msi)
(cffi:defcfun ("MsiSourceListAddMediaDiskW" msi-source-list-add-media-disk-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-disk-id :uint32) ; DWORD
(sz-volume-label (:string :encoding :utf-16le)) ; LPCWSTR optional
(sz-disk-prompt (:string :encoding :utf-16le))) ; LPCWSTR optional
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $MsiSourceListAddMediaDiskW = Win32::API::More->new('msi',
'DWORD MsiSourceListAddMediaDiskW(LPCWSTR szProductCodeOrPatchCode, LPCWSTR szUserSid, int dwContext, DWORD dwOptions, DWORD dwDiskId, LPCWSTR szVolumeLabel, LPCWSTR szDiskPrompt)');
# my $ret = $MsiSourceListAddMediaDiskW->Call($szProductCodeOrPatchCode, $szUserSid, $dwContext, $dwOptions, $dwDiskId, $szVolumeLabel, $szDiskPrompt);
# szProductCodeOrPatchCode : LPCWSTR -> LPCWSTR
# szUserSid : LPCWSTR optional -> LPCWSTR
# dwContext : MSIINSTALLCONTEXT -> int
# dwOptions : DWORD -> DWORD
# dwDiskId : DWORD -> DWORD
# szVolumeLabel : LPCWSTR optional -> LPCWSTR
# szDiskPrompt : LPCWSTR optional -> LPCWSTR
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。関連項目
- f MsiSourceListAddMediaDiskA (ANSI版) — ソースリストにメディアディスクのラベルとプロンプトを登録する。