MsiEnumPatchesExW
関数シグネチャ
// msi.dll (Unicode / -W)
#include <windows.h>
DWORD MsiEnumPatchesExW(
LPCWSTR szProductCode, // optional
LPCWSTR szUserSid, // optional
DWORD dwContext,
DWORD dwFilter,
DWORD dwIndex,
LPWSTR szPatchCode, // optional
LPWSTR szTargetProductCode, // optional
MSIINSTALLCONTEXT* pdwTargetProductContext, // optional
LPWSTR szTargetUserSid, // optional
DWORD* pcchTargetUserSid // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| szProductCode | LPCWSTR | inoptional | パッチを列挙する製品の ProductCode GUID を指定する null 終端文字列です。NULL 以外の場合、パッチの列挙は szUserSid および dwContext で指定されたユーザーおよびコンテキスト下にあるこの製品のインスタンスに限定されます。NULL の場合、指定されたコンテキスト下にあるすべての製品のパッチが列挙されます。 | ||||||||||||
| szUserSid | LPCWSTR | inoptional | 列挙のコンテキストを制限するセキュリティ識別子 (SID) を指定する null 終端文字列です。特別な SID 文字列 "S-1-1-0" (Everyone) は、システム内の全ユーザーにわたる列挙を指定します。"S-1-1-0" 以外の SID 値はユーザー SID と見なされ、列挙をそのユーザーに限定します。現在のユーザー以外のユーザーを列挙する場合、Windows Installer バージョン 3.0 未満のバージョンを使用して per-user-unmanaged コンテキストで適用されたパッチは列挙されません。このパラメーターを NULL に設定すると、現在のユーザーを指定できます。
注意 特別な SID 文字列 "S-1-5-18" (System) は、per-machine としてインストールされた製品やパッチの列挙には使用できません。SID 値を "S-1-5-18" に設定すると ERROR_INVALID_PARAMETER が返されます。dwContext が MSIINSTALLCONTEXT_MACHINE のみに設定されている場合、szUserSid は NULL でなければなりません。
| ||||||||||||
| dwContext | DWORD | in | 列挙を 1 つまたは複数のコンテキストの組み合わせに制限します。このパラメーターには、次の値のいずれか 1 つまたはその組み合わせを指定できます。
| ||||||||||||
| dwFilter | DWORD | in | 列挙のフィルターです。このパラメーターには、次のパラメーターのいずれか 1 つまたはその組み合わせを指定できます。
| ||||||||||||
| dwIndex | DWORD | in | 取得するパッチのインデックスです。このパラメーターは、MsiEnumPatchesEx 関数の最初の呼び出しではゼロでなければならず、以降の呼び出しでは増分する必要があります。dwIndex パラメーターは、直前の呼び出しが ERROR_SUCCESS を返した場合にのみ増分してください。 | ||||||||||||
| szPatchCode | LPWSTR | outoptional | 列挙されるパッチの GUID を格納する出力バッファーです。バッファーは GUID を保持できる十分な大きさが必要です。このパラメーターは NULL にできます。 | ||||||||||||
| szTargetProductCode | LPWSTR | outoptional | このパッチを受け取る製品の ProductCode GUID を格納する出力バッファーです。バッファーは GUID を保持できる十分な大きさが必要です。このパラメーターは NULL にできます。 | ||||||||||||
| pdwTargetProductContext | MSIINSTALLCONTEXT* | outoptional | 列挙されるパッチのコンテキストを返します。出力値は MSIINSTALLCONTEXT_USERMANAGED、MSIINSTALLCONTEXT_USERUNMANAGED、または MSIINSTALLCONTEXT_MACHINE のいずれかになります。このパラメーターは NULL にできます。 | ||||||||||||
| szTargetUserSid | LPWSTR | outoptional | このパッチインスタンスが存在するアカウントの文字列 SID を受け取る出力バッファーです。per-machine コンテキストの場合、このバッファーには空文字列が返されます。 このバッファーは SID を格納できる十分な大きさが必要です。バッファーが小さすぎる場合、関数は ERROR_MORE_DATA を返し、*pcchTargetUserSid に終端の NULL 文字を含まない値の TCHAR 数を設定します。 szTargetUserSid が NULL に設定され、pcchTargetUserSid が有効なポインターに設定されている場合、関数は ERROR_SUCCESS を返し、pcchTargetUserSid に終端の NULL 文字を含まない値の TCHAR 数を設定します。その後、pcchTargetUserSid + 1 文字を格納できる十分な大きさの szTargetUserSid バッファーを指定して、関数を再度呼び出して値を取得できます。 szTargetUserSid と pcchTargetUserSid の両方が NULL に設定されている場合、関数は値を取得せずに、値が存在すれば ERROR_SUCCESS を返します。 | ||||||||||||
| pcchTargetUserSid | DWORD* | inoutoptional | szTargetUserSid バッファー内の TCHAR 数を指定する変数へのポインターです。関数が返るとき、このパラメーターには、関数が指定されたバッファーに値をコピーしたかどうかに関わらず、要求された値のサイズが設定されます。サイズは、終端の null 文字を含まない、要求された値の TCHAR 数として返されます。 このパラメーターを NULL に設定できるのは szTargetUserSid も NULL の場合のみです。そうでない場合、関数は ERROR_INVALID_PARAMETER を返します。 |
戻り値の型: DWORD
公式ドキュメント
特定のコンテキスト内、または全コンテキストにわたってすべてのパッチを列挙します。(Unicode)
戻り値
MsiEnumPatchesEx 関数は次の値のいずれかを返します。
| 戻り値 | 説明 |
|---|---|
| 権限が不足している状態でリソースにアクセスしようとして関数が失敗しました。 | |
| 構成データが破損しています。 | |
| 無効なパラメーターが関数に渡されました。 | |
| 列挙するパッチがこれ以上ありません。 | |
| パッチが正常に列挙されました。 | |
| szProduct が指定する製品が、指定されたコンテキストでコンピューターにインストールされていません。 | |
| pcchTargetUserSid が、SID をコピーするのに必要なサイズより小さいバッファーサイズを指している場合に返されます。この場合、ユーザーはバッファーを修正し、同じインデックス値で MsiEnumPatchesEx を再度呼び出すことができます。 |
解説(Remarks)
非管理者は、自身が参照可能な範囲内のパッチのみを列挙できます。管理者は、他のユーザーコンテキストのパッチを列挙できます。
msi.h ヘッダーは、MsiEnumPatchesEx を、UNICODE プリプロセッサ定数の定義に基づいてこの関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして定義します。エンコーディング中立のエイリアスの使用を、エンコーディング中立でないコードと混在させると、不一致が生じ、コンパイルエラーや実行時エラーを引き起こす可能性があります。詳細については、関数プロトタイプの規則 を参照してください。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// msi.dll (Unicode / -W)
#include <windows.h>
DWORD MsiEnumPatchesExW(
LPCWSTR szProductCode, // optional
LPCWSTR szUserSid, // optional
DWORD dwContext,
DWORD dwFilter,
DWORD dwIndex,
LPWSTR szPatchCode, // optional
LPWSTR szTargetProductCode, // optional
MSIINSTALLCONTEXT* pdwTargetProductContext, // optional
LPWSTR szTargetUserSid, // optional
DWORD* pcchTargetUserSid // optional
);[DllImport("msi.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern uint MsiEnumPatchesExW(
[MarshalAs(UnmanagedType.LPWStr)] string szProductCode, // LPCWSTR optional
[MarshalAs(UnmanagedType.LPWStr)] string szUserSid, // LPCWSTR optional
uint dwContext, // DWORD
uint dwFilter, // DWORD
uint dwIndex, // DWORD
[MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder szPatchCode, // LPWSTR optional, out
[MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder szTargetProductCode, // LPWSTR optional, out
IntPtr pdwTargetProductContext, // MSIINSTALLCONTEXT* optional, out
[MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder szTargetUserSid, // LPWSTR optional, out
IntPtr pcchTargetUserSid // DWORD* optional, in/out
);<DllImport("msi.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function MsiEnumPatchesExW(
<MarshalAs(UnmanagedType.LPWStr)> szProductCode As String, ' LPCWSTR optional
<MarshalAs(UnmanagedType.LPWStr)> szUserSid As String, ' LPCWSTR optional
dwContext As UInteger, ' DWORD
dwFilter As UInteger, ' DWORD
dwIndex As UInteger, ' DWORD
<MarshalAs(UnmanagedType.LPWStr)> szPatchCode As System.Text.StringBuilder, ' LPWSTR optional, out
<MarshalAs(UnmanagedType.LPWStr)> szTargetProductCode As System.Text.StringBuilder, ' LPWSTR optional, out
pdwTargetProductContext As IntPtr, ' MSIINSTALLCONTEXT* optional, out
<MarshalAs(UnmanagedType.LPWStr)> szTargetUserSid As System.Text.StringBuilder, ' LPWSTR optional, out
pcchTargetUserSid As IntPtr ' DWORD* optional, in/out
) As UInteger
End Function' szProductCode : LPCWSTR optional
' szUserSid : LPCWSTR optional
' dwContext : DWORD
' dwFilter : DWORD
' dwIndex : DWORD
' szPatchCode : LPWSTR optional, out
' szTargetProductCode : LPWSTR optional, out
' pdwTargetProductContext : MSIINSTALLCONTEXT* optional, out
' szTargetUserSid : LPWSTR optional, out
' pcchTargetUserSid : DWORD* optional, in/out
Declare PtrSafe Function MsiEnumPatchesExW Lib "msi" ( _
ByVal szProductCode As LongPtr, _
ByVal szUserSid As LongPtr, _
ByVal dwContext As Long, _
ByVal dwFilter As Long, _
ByVal dwIndex As Long, _
ByVal szPatchCode As LongPtr, _
ByVal szTargetProductCode As LongPtr, _
ByVal pdwTargetProductContext As LongPtr, _
ByVal szTargetUserSid As LongPtr, _
ByVal pcchTargetUserSid 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
MsiEnumPatchesExW = ctypes.windll.msi.MsiEnumPatchesExW
MsiEnumPatchesExW.restype = wintypes.DWORD
MsiEnumPatchesExW.argtypes = [
wintypes.LPCWSTR, # szProductCode : LPCWSTR optional
wintypes.LPCWSTR, # szUserSid : LPCWSTR optional
wintypes.DWORD, # dwContext : DWORD
wintypes.DWORD, # dwFilter : DWORD
wintypes.DWORD, # dwIndex : DWORD
wintypes.LPWSTR, # szPatchCode : LPWSTR optional, out
wintypes.LPWSTR, # szTargetProductCode : LPWSTR optional, out
ctypes.c_void_p, # pdwTargetProductContext : MSIINSTALLCONTEXT* optional, out
wintypes.LPWSTR, # szTargetUserSid : LPWSTR optional, out
ctypes.POINTER(wintypes.DWORD), # pcchTargetUserSid : DWORD* optional, in/out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('msi.dll')
MsiEnumPatchesExW = Fiddle::Function.new(
lib['MsiEnumPatchesExW'],
[
Fiddle::TYPE_VOIDP, # szProductCode : LPCWSTR optional
Fiddle::TYPE_VOIDP, # szUserSid : LPCWSTR optional
-Fiddle::TYPE_INT, # dwContext : DWORD
-Fiddle::TYPE_INT, # dwFilter : DWORD
-Fiddle::TYPE_INT, # dwIndex : DWORD
Fiddle::TYPE_VOIDP, # szPatchCode : LPWSTR optional, out
Fiddle::TYPE_VOIDP, # szTargetProductCode : LPWSTR optional, out
Fiddle::TYPE_VOIDP, # pdwTargetProductContext : MSIINSTALLCONTEXT* optional, out
Fiddle::TYPE_VOIDP, # szTargetUserSid : LPWSTR optional, out
Fiddle::TYPE_VOIDP, # pcchTargetUserSid : DWORD* optional, in/out
],
-Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "msi")]
extern "system" {
fn MsiEnumPatchesExW(
szProductCode: *const u16, // LPCWSTR optional
szUserSid: *const u16, // LPCWSTR optional
dwContext: u32, // DWORD
dwFilter: u32, // DWORD
dwIndex: u32, // DWORD
szPatchCode: *mut u16, // LPWSTR optional, out
szTargetProductCode: *mut u16, // LPWSTR optional, out
pdwTargetProductContext: *mut i32, // MSIINSTALLCONTEXT* optional, out
szTargetUserSid: *mut u16, // LPWSTR optional, out
pcchTargetUserSid: *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 MsiEnumPatchesExW([MarshalAs(UnmanagedType.LPWStr)] string szProductCode, [MarshalAs(UnmanagedType.LPWStr)] string szUserSid, uint dwContext, uint dwFilter, uint dwIndex, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder szPatchCode, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder szTargetProductCode, IntPtr pdwTargetProductContext, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder szTargetUserSid, IntPtr pcchTargetUserSid);
"@
$api = Add-Type -MemberDefinition $sig -Name 'msi_MsiEnumPatchesExW' -Namespace Win32 -PassThru
# $api::MsiEnumPatchesExW(szProductCode, szUserSid, dwContext, dwFilter, dwIndex, szPatchCode, szTargetProductCode, pdwTargetProductContext, szTargetUserSid, pcchTargetUserSid)#uselib "msi.dll"
#func global MsiEnumPatchesExW "MsiEnumPatchesExW" wptr, wptr, wptr, wptr, wptr, wptr, wptr, wptr, wptr, wptr
; MsiEnumPatchesExW szProductCode, szUserSid, dwContext, dwFilter, dwIndex, varptr(szPatchCode), varptr(szTargetProductCode), varptr(pdwTargetProductContext), varptr(szTargetUserSid), varptr(pcchTargetUserSid) ; 戻り値は stat
; szProductCode : LPCWSTR optional -> "wptr"
; szUserSid : LPCWSTR optional -> "wptr"
; dwContext : DWORD -> "wptr"
; dwFilter : DWORD -> "wptr"
; dwIndex : DWORD -> "wptr"
; szPatchCode : LPWSTR optional, out -> "wptr"
; szTargetProductCode : LPWSTR optional, out -> "wptr"
; pdwTargetProductContext : MSIINSTALLCONTEXT* optional, out -> "wptr"
; szTargetUserSid : LPWSTR optional, out -> "wptr"
; pcchTargetUserSid : DWORD* optional, in/out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "msi.dll" #cfunc global MsiEnumPatchesExW "MsiEnumPatchesExW" wstr, wstr, int, int, int, var, var, var, var, var ; res = MsiEnumPatchesExW(szProductCode, szUserSid, dwContext, dwFilter, dwIndex, szPatchCode, szTargetProductCode, pdwTargetProductContext, szTargetUserSid, pcchTargetUserSid) ; szProductCode : LPCWSTR optional -> "wstr" ; szUserSid : LPCWSTR optional -> "wstr" ; dwContext : DWORD -> "int" ; dwFilter : DWORD -> "int" ; dwIndex : DWORD -> "int" ; szPatchCode : LPWSTR optional, out -> "var" ; szTargetProductCode : LPWSTR optional, out -> "var" ; pdwTargetProductContext : MSIINSTALLCONTEXT* optional, out -> "var" ; szTargetUserSid : LPWSTR optional, out -> "var" ; pcchTargetUserSid : DWORD* optional, in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "msi.dll" #cfunc global MsiEnumPatchesExW "MsiEnumPatchesExW" wstr, wstr, int, int, int, sptr, sptr, sptr, sptr, sptr ; res = MsiEnumPatchesExW(szProductCode, szUserSid, dwContext, dwFilter, dwIndex, varptr(szPatchCode), varptr(szTargetProductCode), varptr(pdwTargetProductContext), varptr(szTargetUserSid), varptr(pcchTargetUserSid)) ; szProductCode : LPCWSTR optional -> "wstr" ; szUserSid : LPCWSTR optional -> "wstr" ; dwContext : DWORD -> "int" ; dwFilter : DWORD -> "int" ; dwIndex : DWORD -> "int" ; szPatchCode : LPWSTR optional, out -> "sptr" ; szTargetProductCode : LPWSTR optional, out -> "sptr" ; pdwTargetProductContext : MSIINSTALLCONTEXT* optional, out -> "sptr" ; szTargetUserSid : LPWSTR optional, out -> "sptr" ; pcchTargetUserSid : DWORD* optional, in/out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
; DWORD MsiEnumPatchesExW(LPCWSTR szProductCode, LPCWSTR szUserSid, DWORD dwContext, DWORD dwFilter, DWORD dwIndex, LPWSTR szPatchCode, LPWSTR szTargetProductCode, MSIINSTALLCONTEXT* pdwTargetProductContext, LPWSTR szTargetUserSid, DWORD* pcchTargetUserSid) #uselib "msi.dll" #cfunc global MsiEnumPatchesExW "MsiEnumPatchesExW" wstr, wstr, int, int, int, var, var, var, var, var ; res = MsiEnumPatchesExW(szProductCode, szUserSid, dwContext, dwFilter, dwIndex, szPatchCode, szTargetProductCode, pdwTargetProductContext, szTargetUserSid, pcchTargetUserSid) ; szProductCode : LPCWSTR optional -> "wstr" ; szUserSid : LPCWSTR optional -> "wstr" ; dwContext : DWORD -> "int" ; dwFilter : DWORD -> "int" ; dwIndex : DWORD -> "int" ; szPatchCode : LPWSTR optional, out -> "var" ; szTargetProductCode : LPWSTR optional, out -> "var" ; pdwTargetProductContext : MSIINSTALLCONTEXT* optional, out -> "var" ; szTargetUserSid : LPWSTR optional, out -> "var" ; pcchTargetUserSid : DWORD* optional, in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; DWORD MsiEnumPatchesExW(LPCWSTR szProductCode, LPCWSTR szUserSid, DWORD dwContext, DWORD dwFilter, DWORD dwIndex, LPWSTR szPatchCode, LPWSTR szTargetProductCode, MSIINSTALLCONTEXT* pdwTargetProductContext, LPWSTR szTargetUserSid, DWORD* pcchTargetUserSid) #uselib "msi.dll" #cfunc global MsiEnumPatchesExW "MsiEnumPatchesExW" wstr, wstr, int, int, int, intptr, intptr, intptr, intptr, intptr ; res = MsiEnumPatchesExW(szProductCode, szUserSid, dwContext, dwFilter, dwIndex, varptr(szPatchCode), varptr(szTargetProductCode), varptr(pdwTargetProductContext), varptr(szTargetUserSid), varptr(pcchTargetUserSid)) ; szProductCode : LPCWSTR optional -> "wstr" ; szUserSid : LPCWSTR optional -> "wstr" ; dwContext : DWORD -> "int" ; dwFilter : DWORD -> "int" ; dwIndex : DWORD -> "int" ; szPatchCode : LPWSTR optional, out -> "intptr" ; szTargetProductCode : LPWSTR optional, out -> "intptr" ; pdwTargetProductContext : MSIINSTALLCONTEXT* optional, out -> "intptr" ; szTargetUserSid : LPWSTR optional, out -> "intptr" ; pcchTargetUserSid : DWORD* optional, in/out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
msi = windows.NewLazySystemDLL("msi.dll")
procMsiEnumPatchesExW = msi.NewProc("MsiEnumPatchesExW")
)
// szProductCode (LPCWSTR optional), szUserSid (LPCWSTR optional), dwContext (DWORD), dwFilter (DWORD), dwIndex (DWORD), szPatchCode (LPWSTR optional, out), szTargetProductCode (LPWSTR optional, out), pdwTargetProductContext (MSIINSTALLCONTEXT* optional, out), szTargetUserSid (LPWSTR optional, out), pcchTargetUserSid (DWORD* optional, in/out)
r1, _, err := procMsiEnumPatchesExW.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(szProductCode))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(szUserSid))),
uintptr(dwContext),
uintptr(dwFilter),
uintptr(dwIndex),
uintptr(szPatchCode),
uintptr(szTargetProductCode),
uintptr(pdwTargetProductContext),
uintptr(szTargetUserSid),
uintptr(pcchTargetUserSid),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction MsiEnumPatchesExW(
szProductCode: PWideChar; // LPCWSTR optional
szUserSid: PWideChar; // LPCWSTR optional
dwContext: DWORD; // DWORD
dwFilter: DWORD; // DWORD
dwIndex: DWORD; // DWORD
szPatchCode: PWideChar; // LPWSTR optional, out
szTargetProductCode: PWideChar; // LPWSTR optional, out
pdwTargetProductContext: Pointer; // MSIINSTALLCONTEXT* optional, out
szTargetUserSid: PWideChar; // LPWSTR optional, out
pcchTargetUserSid: Pointer // DWORD* optional, in/out
): DWORD; stdcall;
external 'msi.dll' name 'MsiEnumPatchesExW';result := DllCall("msi\MsiEnumPatchesExW"
, "WStr", szProductCode ; LPCWSTR optional
, "WStr", szUserSid ; LPCWSTR optional
, "UInt", dwContext ; DWORD
, "UInt", dwFilter ; DWORD
, "UInt", dwIndex ; DWORD
, "Ptr", szPatchCode ; LPWSTR optional, out
, "Ptr", szTargetProductCode ; LPWSTR optional, out
, "Ptr", pdwTargetProductContext ; MSIINSTALLCONTEXT* optional, out
, "Ptr", szTargetUserSid ; LPWSTR optional, out
, "Ptr", pcchTargetUserSid ; DWORD* optional, in/out
, "UInt") ; return: DWORD●MsiEnumPatchesExW(szProductCode, szUserSid, dwContext, dwFilter, dwIndex, szPatchCode, szTargetProductCode, pdwTargetProductContext, szTargetUserSid, pcchTargetUserSid) = DLL("msi.dll", "dword MsiEnumPatchesExW(char*, char*, dword, dword, dword, char*, char*, void*, char*, void*)")
# 呼び出し: MsiEnumPatchesExW(szProductCode, szUserSid, dwContext, dwFilter, dwIndex, szPatchCode, szTargetProductCode, pdwTargetProductContext, szTargetUserSid, pcchTargetUserSid)
# szProductCode : LPCWSTR optional -> "char*"
# szUserSid : LPCWSTR optional -> "char*"
# dwContext : DWORD -> "dword"
# dwFilter : DWORD -> "dword"
# dwIndex : DWORD -> "dword"
# szPatchCode : LPWSTR optional, out -> "char*"
# szTargetProductCode : LPWSTR optional, out -> "char*"
# pdwTargetProductContext : MSIINSTALLCONTEXT* optional, out -> "void*"
# szTargetUserSid : LPWSTR optional, out -> "char*"
# pcchTargetUserSid : 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 MsiEnumPatchesExW(
szProductCode: [*c]const u16, // LPCWSTR optional
szUserSid: [*c]const u16, // LPCWSTR optional
dwContext: u32, // DWORD
dwFilter: u32, // DWORD
dwIndex: u32, // DWORD
szPatchCode: [*c]u16, // LPWSTR optional, out
szTargetProductCode: [*c]u16, // LPWSTR optional, out
pdwTargetProductContext: [*c]i32, // MSIINSTALLCONTEXT* optional, out
szTargetUserSid: [*c]u16, // LPWSTR optional, out
pcchTargetUserSid: [*c]u32 // DWORD* optional, in/out
) callconv(std.os.windows.WINAPI) u32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。proc MsiEnumPatchesExW(
szProductCode: WideCString, # LPCWSTR optional
szUserSid: WideCString, # LPCWSTR optional
dwContext: uint32, # DWORD
dwFilter: uint32, # DWORD
dwIndex: uint32, # DWORD
szPatchCode: ptr uint16, # LPWSTR optional, out
szTargetProductCode: ptr uint16, # LPWSTR optional, out
pdwTargetProductContext: ptr int32, # MSIINSTALLCONTEXT* optional, out
szTargetUserSid: ptr uint16, # LPWSTR optional, out
pcchTargetUserSid: ptr uint32 # DWORD* optional, in/out
): uint32 {.importc: "MsiEnumPatchesExW", stdcall, dynlib: "msi.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。pragma(lib, "msi");
extern(Windows)
uint MsiEnumPatchesExW(
const(wchar)* szProductCode, // LPCWSTR optional
const(wchar)* szUserSid, // LPCWSTR optional
uint dwContext, // DWORD
uint dwFilter, // DWORD
uint dwIndex, // DWORD
wchar* szPatchCode, // LPWSTR optional, out
wchar* szTargetProductCode, // LPWSTR optional, out
int* pdwTargetProductContext, // MSIINSTALLCONTEXT* optional, out
wchar* szTargetUserSid, // LPWSTR optional, out
uint* pcchTargetUserSid // DWORD* optional, in/out
);ccall((:MsiEnumPatchesExW, "msi.dll"), stdcall, UInt32,
(Cwstring, Cwstring, UInt32, UInt32, UInt32, Ptr{UInt16}, Ptr{UInt16}, Ptr{Int32}, Ptr{UInt16}, Ptr{UInt32}),
szProductCode, szUserSid, dwContext, dwFilter, dwIndex, szPatchCode, szTargetProductCode, pdwTargetProductContext, szTargetUserSid, pcchTargetUserSid)
# szProductCode : LPCWSTR optional -> Cwstring
# szUserSid : LPCWSTR optional -> Cwstring
# dwContext : DWORD -> UInt32
# dwFilter : DWORD -> UInt32
# dwIndex : DWORD -> UInt32
# szPatchCode : LPWSTR optional, out -> Ptr{UInt16}
# szTargetProductCode : LPWSTR optional, out -> Ptr{UInt16}
# pdwTargetProductContext : MSIINSTALLCONTEXT* optional, out -> Ptr{Int32}
# szTargetUserSid : LPWSTR optional, out -> Ptr{UInt16}
# pcchTargetUserSid : DWORD* optional, in/out -> Ptr{UInt32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。local ffi = require("ffi")
ffi.cdef[[
uint32_t MsiEnumPatchesExW(
const uint16_t* szProductCode,
const uint16_t* szUserSid,
uint32_t dwContext,
uint32_t dwFilter,
uint32_t dwIndex,
uint16_t* szPatchCode,
uint16_t* szTargetProductCode,
int32_t* pdwTargetProductContext,
uint16_t* szTargetUserSid,
uint32_t* pcchTargetUserSid);
]]
local msi = ffi.load("msi")
-- msi.MsiEnumPatchesExW(szProductCode, szUserSid, dwContext, dwFilter, dwIndex, szPatchCode, szTargetProductCode, pdwTargetProductContext, szTargetUserSid, pcchTargetUserSid)
-- szProductCode : LPCWSTR optional
-- szUserSid : LPCWSTR optional
-- dwContext : DWORD
-- dwFilter : DWORD
-- dwIndex : DWORD
-- szPatchCode : LPWSTR optional, out
-- szTargetProductCode : LPWSTR optional, out
-- pdwTargetProductContext : MSIINSTALLCONTEXT* optional, out
-- szTargetUserSid : LPWSTR optional, out
-- pcchTargetUserSid : 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 MsiEnumPatchesExW = lib.func('__stdcall', 'MsiEnumPatchesExW', 'uint32_t', ['str16', 'str16', 'uint32_t', 'uint32_t', 'uint32_t', 'uint16_t *', 'uint16_t *', 'int32_t *', 'uint16_t *', 'uint32_t *']);
// MsiEnumPatchesExW(szProductCode, szUserSid, dwContext, dwFilter, dwIndex, szPatchCode, szTargetProductCode, pdwTargetProductContext, szTargetUserSid, pcchTargetUserSid)
// szProductCode : LPCWSTR optional -> 'str16'
// szUserSid : LPCWSTR optional -> 'str16'
// dwContext : DWORD -> 'uint32_t'
// dwFilter : DWORD -> 'uint32_t'
// dwIndex : DWORD -> 'uint32_t'
// szPatchCode : LPWSTR optional, out -> 'uint16_t *'
// szTargetProductCode : LPWSTR optional, out -> 'uint16_t *'
// pdwTargetProductContext : MSIINSTALLCONTEXT* optional, out -> 'int32_t *'
// szTargetUserSid : LPWSTR optional, out -> 'uint16_t *'
// pcchTargetUserSid : DWORD* optional, in/out -> 'uint32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("msi.dll", {
MsiEnumPatchesExW: { parameters: ["buffer", "buffer", "u32", "u32", "u32", "buffer", "buffer", "pointer", "buffer", "pointer"], result: "u32" },
});
// lib.symbols.MsiEnumPatchesExW(szProductCode, szUserSid, dwContext, dwFilter, dwIndex, szPatchCode, szTargetProductCode, pdwTargetProductContext, szTargetUserSid, pcchTargetUserSid)
// szProductCode : LPCWSTR optional -> "buffer"
// szUserSid : LPCWSTR optional -> "buffer"
// dwContext : DWORD -> "u32"
// dwFilter : DWORD -> "u32"
// dwIndex : DWORD -> "u32"
// szPatchCode : LPWSTR optional, out -> "buffer"
// szTargetProductCode : LPWSTR optional, out -> "buffer"
// pdwTargetProductContext : MSIINSTALLCONTEXT* optional, out -> "pointer"
// szTargetUserSid : LPWSTR optional, out -> "buffer"
// pcchTargetUserSid : 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 MsiEnumPatchesExW(
const uint16_t* szProductCode,
const uint16_t* szUserSid,
uint32_t dwContext,
uint32_t dwFilter,
uint32_t dwIndex,
uint16_t* szPatchCode,
uint16_t* szTargetProductCode,
int32_t* pdwTargetProductContext,
uint16_t* szTargetUserSid,
uint32_t* pcchTargetUserSid);
C, "msi.dll");
// $ffi->MsiEnumPatchesExW(szProductCode, szUserSid, dwContext, dwFilter, dwIndex, szPatchCode, szTargetProductCode, pdwTargetProductContext, szTargetUserSid, pcchTargetUserSid);
// szProductCode : LPCWSTR optional
// szUserSid : LPCWSTR optional
// dwContext : DWORD
// dwFilter : DWORD
// dwIndex : DWORD
// szPatchCode : LPWSTR optional, out
// szTargetProductCode : LPWSTR optional, out
// pdwTargetProductContext : MSIINSTALLCONTEXT* optional, out
// szTargetUserSid : LPWSTR optional, out
// pcchTargetUserSid : 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 MsiEnumPatchesExW(
WString szProductCode, // LPCWSTR optional
WString szUserSid, // LPCWSTR optional
int dwContext, // DWORD
int dwFilter, // DWORD
int dwIndex, // DWORD
char[] szPatchCode, // LPWSTR optional, out
char[] szTargetProductCode, // LPWSTR optional, out
IntByReference pdwTargetProductContext, // MSIINSTALLCONTEXT* optional, out
char[] szTargetUserSid, // LPWSTR optional, out
IntByReference pcchTargetUserSid // DWORD* optional, in/out
);
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。@[Link("msi")]
lib Libmsi
fun MsiEnumPatchesExW = MsiEnumPatchesExW(
szProductCode : UInt16*, # LPCWSTR optional
szUserSid : UInt16*, # LPCWSTR optional
dwContext : UInt32, # DWORD
dwFilter : UInt32, # DWORD
dwIndex : UInt32, # DWORD
szPatchCode : UInt16*, # LPWSTR optional, out
szTargetProductCode : UInt16*, # LPWSTR optional, out
pdwTargetProductContext : Int32*, # MSIINSTALLCONTEXT* optional, out
szTargetUserSid : UInt16*, # LPWSTR optional, out
pcchTargetUserSid : 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 MsiEnumPatchesExWNative = Uint32 Function(Pointer<Utf16>, Pointer<Utf16>, Uint32, Uint32, Uint32, Pointer<Utf16>, Pointer<Utf16>, Pointer<Int32>, Pointer<Utf16>, Pointer<Uint32>);
typedef MsiEnumPatchesExWDart = int Function(Pointer<Utf16>, Pointer<Utf16>, int, int, int, Pointer<Utf16>, Pointer<Utf16>, Pointer<Int32>, Pointer<Utf16>, Pointer<Uint32>);
final MsiEnumPatchesExW = DynamicLibrary.open('msi.dll')
.lookupFunction<MsiEnumPatchesExWNative, MsiEnumPatchesExWDart>('MsiEnumPatchesExW');
// szProductCode : LPCWSTR optional -> Pointer<Utf16>
// szUserSid : LPCWSTR optional -> Pointer<Utf16>
// dwContext : DWORD -> Uint32
// dwFilter : DWORD -> Uint32
// dwIndex : DWORD -> Uint32
// szPatchCode : LPWSTR optional, out -> Pointer<Utf16>
// szTargetProductCode : LPWSTR optional, out -> Pointer<Utf16>
// pdwTargetProductContext : MSIINSTALLCONTEXT* optional, out -> Pointer<Int32>
// szTargetUserSid : LPWSTR optional, out -> Pointer<Utf16>
// pcchTargetUserSid : DWORD* optional, in/out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function MsiEnumPatchesExW(
szProductCode: PWideChar; // LPCWSTR optional
szUserSid: PWideChar; // LPCWSTR optional
dwContext: DWORD; // DWORD
dwFilter: DWORD; // DWORD
dwIndex: DWORD; // DWORD
szPatchCode: PWideChar; // LPWSTR optional, out
szTargetProductCode: PWideChar; // LPWSTR optional, out
pdwTargetProductContext: Pointer; // MSIINSTALLCONTEXT* optional, out
szTargetUserSid: PWideChar; // LPWSTR optional, out
pcchTargetUserSid: Pointer // DWORD* optional, in/out
): DWORD; stdcall;
external 'msi.dll' name 'MsiEnumPatchesExW';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "MsiEnumPatchesExW"
c_MsiEnumPatchesExW :: CWString -> CWString -> Word32 -> Word32 -> Word32 -> CWString -> CWString -> Ptr Int32 -> CWString -> Ptr Word32 -> IO Word32
-- szProductCode : LPCWSTR optional -> CWString
-- szUserSid : LPCWSTR optional -> CWString
-- dwContext : DWORD -> Word32
-- dwFilter : DWORD -> Word32
-- dwIndex : DWORD -> Word32
-- szPatchCode : LPWSTR optional, out -> CWString
-- szTargetProductCode : LPWSTR optional, out -> CWString
-- pdwTargetProductContext : MSIINSTALLCONTEXT* optional, out -> Ptr Int32
-- szTargetUserSid : LPWSTR optional, out -> CWString
-- pcchTargetUserSid : DWORD* optional, in/out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let msienumpatchesexw =
foreign "MsiEnumPatchesExW"
((ptr uint16_t) @-> (ptr uint16_t) @-> uint32_t @-> uint32_t @-> uint32_t @-> (ptr uint16_t) @-> (ptr uint16_t) @-> (ptr int32_t) @-> (ptr uint16_t) @-> (ptr uint32_t) @-> returning uint32_t)
(* szProductCode : LPCWSTR optional -> (ptr uint16_t) *)
(* szUserSid : LPCWSTR optional -> (ptr uint16_t) *)
(* dwContext : DWORD -> uint32_t *)
(* dwFilter : DWORD -> uint32_t *)
(* dwIndex : DWORD -> uint32_t *)
(* szPatchCode : LPWSTR optional, out -> (ptr uint16_t) *)
(* szTargetProductCode : LPWSTR optional, out -> (ptr uint16_t) *)
(* pdwTargetProductContext : MSIINSTALLCONTEXT* optional, out -> (ptr int32_t) *)
(* szTargetUserSid : LPWSTR optional, out -> (ptr uint16_t) *)
(* pcchTargetUserSid : 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 ("MsiEnumPatchesExW" msi-enum-patches-ex-w :convention :stdcall) :uint32
(sz-product-code (:string :encoding :utf-16le)) ; LPCWSTR optional
(sz-user-sid (:string :encoding :utf-16le)) ; LPCWSTR optional
(dw-context :uint32) ; DWORD
(dw-filter :uint32) ; DWORD
(dw-index :uint32) ; DWORD
(sz-patch-code :pointer) ; LPWSTR optional, out
(sz-target-product-code :pointer) ; LPWSTR optional, out
(pdw-target-product-context :pointer) ; MSIINSTALLCONTEXT* optional, out
(sz-target-user-sid :pointer) ; LPWSTR optional, out
(pcch-target-user-sid :pointer)) ; DWORD* optional, in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $MsiEnumPatchesExW = Win32::API::More->new('msi',
'DWORD MsiEnumPatchesExW(LPCWSTR szProductCode, LPCWSTR szUserSid, DWORD dwContext, DWORD dwFilter, DWORD dwIndex, LPWSTR szPatchCode, LPWSTR szTargetProductCode, LPVOID pdwTargetProductContext, LPWSTR szTargetUserSid, LPVOID pcchTargetUserSid)');
# my $ret = $MsiEnumPatchesExW->Call($szProductCode, $szUserSid, $dwContext, $dwFilter, $dwIndex, $szPatchCode, $szTargetProductCode, $pdwTargetProductContext, $szTargetUserSid, $pcchTargetUserSid);
# szProductCode : LPCWSTR optional -> LPCWSTR
# szUserSid : LPCWSTR optional -> LPCWSTR
# dwContext : DWORD -> DWORD
# dwFilter : DWORD -> DWORD
# dwIndex : DWORD -> DWORD
# szPatchCode : LPWSTR optional, out -> LPWSTR
# szTargetProductCode : LPWSTR optional, out -> LPWSTR
# pdwTargetProductContext : MSIINSTALLCONTEXT* optional, out -> LPVOID
# szTargetUserSid : LPWSTR optional, out -> LPWSTR
# pcchTargetUserSid : DWORD* optional, in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。関連項目
- f MsiEnumPatchesExA (ANSI版) — コンテキストやフィルタを指定してパッチを列挙する(ANSI版)。
- f MsiEnumPatchesW — 製品に適用されたパッチを列挙する(Unicode版)。
- f MsiSourceListAddSourceExW — コンテキストや種別を指定して製品やパッチのソースを追加する。