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

MsiGetPatchInfoExW

関数
コンテキスト指定でパッチの詳細情報を取得する(Unicode版)。
DLLmsi.dll文字セットUnicode (-W)呼出規約winapi対応OSwindows8.0

シグネチャ

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

DWORD MsiGetPatchInfoExW(
    LPCWSTR szPatchCode,
    LPCWSTR szProductCode,
    LPCWSTR szUserSid,   // optional
    MSIINSTALLCONTEXT dwContext,
    LPCWSTR szProperty,
    LPWSTR lpValue,   // optional
    DWORD* pcchValue   // optional
);

パラメーター

名前方向説明
szPatchCodeLPCWSTRinパッチの GUID を含む null 終端文字列です。このパラメーターを NULL にすることはできません。
szProductCodeLPCWSTRin製品インスタンスの ProductCode GUID を含む null 終端文字列です。このパラメーターを NULL にすることはできません。
szUserSidLPCWSTRinoptional

照会対象のパッチインスタンスが存在するセキュリティ識別子 (SID) を指定する null 終端文字列です。NULL を指定すると、現在のユーザーを指定したことになります。

SID 意味
NULL
ログオンしているユーザーを指定します。
User SID
システム内の特定のユーザー ID に対する列挙を指定します。次の例は、ユーザー SID の一例を示しています: "S-1-3-64-2415071341-1358098788-3127455600-2561"。
特殊な SID 文字列 "S-1-5-18" (システム) を使用して、コンピューター単位 (per-machine) でインストールされた製品を列挙することはできません。dwContextMSIINSTALLCONTEXT_MACHINE の場合、szUserSidNULL でなければなりません。
dwContextMSIINSTALLCONTEXTin

列挙を、ユーザー単位の非管理 (per-user-unmanaged)、ユーザー単位の管理 (per-user-managed)、またはコンピューター単位 (per-machine) のコンテキストに限定します。このパラメーターには、次のいずれかの値を指定できます。

コンテキスト 意味
MSIINSTALLCONTEXT_USERMANAGED
1
szUserSid で指定したユーザーについて、すべてのユーザー単位の管理 (per-user-managed) インストールに拡張される照会です。
MSIINSTALLCONTEXT_USERUNMANAGED
2
szUserSid で指定したユーザーについて、すべてのユーザー単位の非管理 (per-user-unmanaged) インストールに拡張される照会です。
MSIINSTALLCONTEXT_MACHINE
4
すべてのコンピューター単位 (per-machine) インストールに拡張される照会です。
szPropertyLPCWSTRin

取得するプロパティ値を指定する null 終端文字列です。szProperty パラメーターには、次のいずれかを指定できます。

名前 意味
INSTALLPROPERTY_LOCALPACKAGE
"LocalPackage"
製品が使用するキャッシュされたパッチファイルを取得します。
INSTALLPROPERTY_TRANSFORMS
"Transforms"
直近のパッチインストールが製品に適用したパッチ変換 (transform) のセットを取得します。ユーザーがログオンしていない場合、ユーザー単位の非管理アプリケーションではこの値が利用できないことがあります。
INSTALLPROPERTY_INSTALLDATE
"InstallDate"
この製品が最後に保守された日時を取得します。このプロパティの値は、製品にパッチが適用または削除されるたび、あるいは /v コマンドラインオプション を使用して製品が修復されるたびに置き換えられます。製品が修復もパッチ適用も受けていない場合、このプロパティには、この製品がこのコンピューターにインストールされた日時が格納されます。
INSTALLPROPERTY_UNINSTALLABLE
"Uninstallable"
パッチが製品からアンインストール可能としてマークされている場合に "1" を返します。この場合でも、このパッチが、アンインストールできない別のパッチによって必要とされているときは、インストーラーがアンインストールをブロックすることがあります。
INSTALLPROPERTY_PATCHSTATE
"State"
このパッチが現在製品に適用されている場合は "1" を返します。このパッチが別のパッチによって置き換えられている (superseded) 場合は "2" を返します。このパッチが廃止 (obsolete) されている場合は "4" を返します。これらの値は、MsiEnumPatchesExdwFilter パラメーターが使用する定数に対応しています。
INSTALLPROPERTY_DISPLAYNAME
"DisplayName"
パッチに登録されている表示名を取得します。MsiPatchMetadata テーブルに DisplayName プロパティを含まないパッチの場合、返される表示名は空の文字列 ("") になります。
INSTALLPROPERTY_MOREINFOURL
"MoreInfoURL"
パッチに登録されているサポート情報 URL を取得します。MsiPatchMetadata テーブルに MoreInfoURL プロパティを含まないパッチの場合、返されるサポート情報 URL は空の文字列 ("") になります。
lpValueLPWSTRoutoptional

このパラメーターは、プロパティ値を受け取るバッファーへのポインターです。このバッファーは、情報を格納するのに十分な大きさである必要があります。バッファーが小さすぎる場合、関数は ERROR_MORE_DATA を返し、*pcchValue に、終端の NULL 文字を含まないプロパティ値内の TCHAR 数を設定します。

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

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

pcchValueDWORD*inoutoptional

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

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

戻り値の型: DWORD

公式ドキュメント

指定した製品インスタンスへのパッチ適用に関する情報を照会します。(Unicode)

戻り値

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

リターンコード 説明
ERROR_ACCESS_DENIED
権限が不足した状態でリソースにアクセスしようとして、関数が失敗しました。
ERROR_BAD_CONFIGURATION
構成データが破損しています。
ERROR_FUNCTION_FAILED
関数が失敗し、そのエラーが他のエラーコードで識別されません。
ERROR_INVALID_PARAMETER
無効なパラメーターが関数に渡されました。
ERROR_MORE_DATA
値が指定されたバッファーに収まりません。
ERROR_SUCCESS
パッチが正常に列挙されました。
ERROR_UNKNOWN_PRODUCT
szProduct で指定された製品がコンピューターにインストールされていません。
ERROR_UNKNOWN_PROPERTY
プロパティが認識されません。
ERROR_UNKNOWN_PATCH
パッチが認識されません。

解説(Remarks)

Windows Installer 2.0: サポートされていません。この関数は Windows Installer バージョン 3.0 以降で利用できます。

ユーザーは、参照可能な任意の製品インスタンスについてパッチデータを照会できます。Administrators グループは、コンピューター上の任意の製品インスタンスおよび任意のユーザーについてパッチデータを照会できます。ユーザーがログオンしていない場合、ユーザー単位の非管理アプリケーションでは、すべての値が利用できることが保証されるわけではありません。

メモ

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

出典・ライセンス: 上記「公式ドキュメント」の内容は 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 MsiGetPatchInfoExW(
    LPCWSTR szPatchCode,
    LPCWSTR szProductCode,
    LPCWSTR szUserSid,   // optional
    MSIINSTALLCONTEXT dwContext,
    LPCWSTR szProperty,
    LPWSTR lpValue,   // optional
    DWORD* pcchValue   // optional
);
[DllImport("msi.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern uint MsiGetPatchInfoExW(
    [MarshalAs(UnmanagedType.LPWStr)] string szPatchCode,   // LPCWSTR
    [MarshalAs(UnmanagedType.LPWStr)] string szProductCode,   // LPCWSTR
    [MarshalAs(UnmanagedType.LPWStr)] string szUserSid,   // LPCWSTR optional
    int dwContext,   // MSIINSTALLCONTEXT
    [MarshalAs(UnmanagedType.LPWStr)] string szProperty,   // LPCWSTR
    [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder lpValue,   // LPWSTR optional, out
    IntPtr pcchValue   // DWORD* optional, in/out
);
<DllImport("msi.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function MsiGetPatchInfoExW(
    <MarshalAs(UnmanagedType.LPWStr)> szPatchCode As String,   ' LPCWSTR
    <MarshalAs(UnmanagedType.LPWStr)> szProductCode As String,   ' LPCWSTR
    <MarshalAs(UnmanagedType.LPWStr)> szUserSid As String,   ' LPCWSTR optional
    dwContext As Integer,   ' MSIINSTALLCONTEXT
    <MarshalAs(UnmanagedType.LPWStr)> szProperty As String,   ' LPCWSTR
    <MarshalAs(UnmanagedType.LPWStr)> lpValue As System.Text.StringBuilder,   ' LPWSTR optional, out
    pcchValue As IntPtr   ' DWORD* optional, in/out
) As UInteger
End Function
' szPatchCode : LPCWSTR
' szProductCode : LPCWSTR
' szUserSid : LPCWSTR optional
' dwContext : MSIINSTALLCONTEXT
' szProperty : LPCWSTR
' lpValue : LPWSTR optional, out
' pcchValue : DWORD* optional, in/out
Declare PtrSafe Function MsiGetPatchInfoExW Lib "msi" ( _
    ByVal szPatchCode As LongPtr, _
    ByVal szProductCode As LongPtr, _
    ByVal szUserSid As LongPtr, _
    ByVal dwContext As Long, _
    ByVal szProperty As LongPtr, _
    ByVal lpValue As LongPtr, _
    ByVal pcchValue 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

MsiGetPatchInfoExW = ctypes.windll.msi.MsiGetPatchInfoExW
MsiGetPatchInfoExW.restype = wintypes.DWORD
MsiGetPatchInfoExW.argtypes = [
    wintypes.LPCWSTR,  # szPatchCode : LPCWSTR
    wintypes.LPCWSTR,  # szProductCode : LPCWSTR
    wintypes.LPCWSTR,  # szUserSid : LPCWSTR optional
    ctypes.c_int,  # dwContext : MSIINSTALLCONTEXT
    wintypes.LPCWSTR,  # szProperty : LPCWSTR
    wintypes.LPWSTR,  # lpValue : LPWSTR optional, out
    ctypes.POINTER(wintypes.DWORD),  # pcchValue : DWORD* optional, in/out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('msi.dll')
MsiGetPatchInfoExW = Fiddle::Function.new(
  lib['MsiGetPatchInfoExW'],
  [
    Fiddle::TYPE_VOIDP,  # szPatchCode : LPCWSTR
    Fiddle::TYPE_VOIDP,  # szProductCode : LPCWSTR
    Fiddle::TYPE_VOIDP,  # szUserSid : LPCWSTR optional
    Fiddle::TYPE_INT,  # dwContext : MSIINSTALLCONTEXT
    Fiddle::TYPE_VOIDP,  # szProperty : LPCWSTR
    Fiddle::TYPE_VOIDP,  # lpValue : LPWSTR optional, out
    Fiddle::TYPE_VOIDP,  # pcchValue : DWORD* optional, in/out
  ],
  -Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "msi")]
extern "system" {
    fn MsiGetPatchInfoExW(
        szPatchCode: *const u16,  // LPCWSTR
        szProductCode: *const u16,  // LPCWSTR
        szUserSid: *const u16,  // LPCWSTR optional
        dwContext: i32,  // MSIINSTALLCONTEXT
        szProperty: *const u16,  // LPCWSTR
        lpValue: *mut u16,  // LPWSTR optional, out
        pcchValue: *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 MsiGetPatchInfoExW([MarshalAs(UnmanagedType.LPWStr)] string szPatchCode, [MarshalAs(UnmanagedType.LPWStr)] string szProductCode, [MarshalAs(UnmanagedType.LPWStr)] string szUserSid, int dwContext, [MarshalAs(UnmanagedType.LPWStr)] string szProperty, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder lpValue, IntPtr pcchValue);
"@
$api = Add-Type -MemberDefinition $sig -Name 'msi_MsiGetPatchInfoExW' -Namespace Win32 -PassThru
# $api::MsiGetPatchInfoExW(szPatchCode, szProductCode, szUserSid, dwContext, szProperty, lpValue, pcchValue)
#uselib "msi.dll"
#func global MsiGetPatchInfoExW "MsiGetPatchInfoExW" wptr, wptr, wptr, wptr, wptr, wptr, wptr
; MsiGetPatchInfoExW szPatchCode, szProductCode, szUserSid, dwContext, szProperty, varptr(lpValue), varptr(pcchValue)   ; 戻り値は stat
; szPatchCode : LPCWSTR -> "wptr"
; szProductCode : LPCWSTR -> "wptr"
; szUserSid : LPCWSTR optional -> "wptr"
; dwContext : MSIINSTALLCONTEXT -> "wptr"
; szProperty : LPCWSTR -> "wptr"
; lpValue : LPWSTR optional, out -> "wptr"
; pcchValue : DWORD* optional, in/out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "msi.dll"
#cfunc global MsiGetPatchInfoExW "MsiGetPatchInfoExW" wstr, wstr, wstr, int, wstr, var, var
; res = MsiGetPatchInfoExW(szPatchCode, szProductCode, szUserSid, dwContext, szProperty, lpValue, pcchValue)
; szPatchCode : LPCWSTR -> "wstr"
; szProductCode : LPCWSTR -> "wstr"
; szUserSid : LPCWSTR optional -> "wstr"
; dwContext : MSIINSTALLCONTEXT -> "int"
; szProperty : LPCWSTR -> "wstr"
; lpValue : LPWSTR optional, out -> "var"
; pcchValue : DWORD* optional, in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; DWORD MsiGetPatchInfoExW(LPCWSTR szPatchCode, LPCWSTR szProductCode, LPCWSTR szUserSid, MSIINSTALLCONTEXT dwContext, LPCWSTR szProperty, LPWSTR lpValue, DWORD* pcchValue)
#uselib "msi.dll"
#cfunc global MsiGetPatchInfoExW "MsiGetPatchInfoExW" wstr, wstr, wstr, int, wstr, var, var
; res = MsiGetPatchInfoExW(szPatchCode, szProductCode, szUserSid, dwContext, szProperty, lpValue, pcchValue)
; szPatchCode : LPCWSTR -> "wstr"
; szProductCode : LPCWSTR -> "wstr"
; szUserSid : LPCWSTR optional -> "wstr"
; dwContext : MSIINSTALLCONTEXT -> "int"
; szProperty : LPCWSTR -> "wstr"
; lpValue : LPWSTR optional, out -> "var"
; pcchValue : DWORD* optional, in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	msi = windows.NewLazySystemDLL("msi.dll")
	procMsiGetPatchInfoExW = msi.NewProc("MsiGetPatchInfoExW")
)

// szPatchCode (LPCWSTR), szProductCode (LPCWSTR), szUserSid (LPCWSTR optional), dwContext (MSIINSTALLCONTEXT), szProperty (LPCWSTR), lpValue (LPWSTR optional, out), pcchValue (DWORD* optional, in/out)
r1, _, err := procMsiGetPatchInfoExW.Call(
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(szPatchCode))),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(szProductCode))),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(szUserSid))),
	uintptr(dwContext),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(szProperty))),
	uintptr(lpValue),
	uintptr(pcchValue),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function MsiGetPatchInfoExW(
  szPatchCode: PWideChar;   // LPCWSTR
  szProductCode: PWideChar;   // LPCWSTR
  szUserSid: PWideChar;   // LPCWSTR optional
  dwContext: Integer;   // MSIINSTALLCONTEXT
  szProperty: PWideChar;   // LPCWSTR
  lpValue: PWideChar;   // LPWSTR optional, out
  pcchValue: Pointer   // DWORD* optional, in/out
): DWORD; stdcall;
  external 'msi.dll' name 'MsiGetPatchInfoExW';
result := DllCall("msi\MsiGetPatchInfoExW"
    , "WStr", szPatchCode   ; LPCWSTR
    , "WStr", szProductCode   ; LPCWSTR
    , "WStr", szUserSid   ; LPCWSTR optional
    , "Int", dwContext   ; MSIINSTALLCONTEXT
    , "WStr", szProperty   ; LPCWSTR
    , "Ptr", lpValue   ; LPWSTR optional, out
    , "Ptr", pcchValue   ; DWORD* optional, in/out
    , "UInt")   ; return: DWORD
●MsiGetPatchInfoExW(szPatchCode, szProductCode, szUserSid, dwContext, szProperty, lpValue, pcchValue) = DLL("msi.dll", "dword MsiGetPatchInfoExW(char*, char*, char*, int, char*, char*, void*)")
# 呼び出し: MsiGetPatchInfoExW(szPatchCode, szProductCode, szUserSid, dwContext, szProperty, lpValue, pcchValue)
# szPatchCode : LPCWSTR -> "char*"
# szProductCode : LPCWSTR -> "char*"
# szUserSid : LPCWSTR optional -> "char*"
# dwContext : MSIINSTALLCONTEXT -> "int"
# szProperty : LPCWSTR -> "char*"
# lpValue : LPWSTR optional, out -> "char*"
# pcchValue : 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 MsiGetPatchInfoExW(
    szPatchCode: [*c]const u16, // LPCWSTR
    szProductCode: [*c]const u16, // LPCWSTR
    szUserSid: [*c]const u16, // LPCWSTR optional
    dwContext: i32, // MSIINSTALLCONTEXT
    szProperty: [*c]const u16, // LPCWSTR
    lpValue: [*c]u16, // LPWSTR optional, out
    pcchValue: [*c]u32 // DWORD* optional, in/out
) callconv(std.os.windows.WINAPI) u32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。
proc MsiGetPatchInfoExW(
    szPatchCode: WideCString,  # LPCWSTR
    szProductCode: WideCString,  # LPCWSTR
    szUserSid: WideCString,  # LPCWSTR optional
    dwContext: int32,  # MSIINSTALLCONTEXT
    szProperty: WideCString,  # LPCWSTR
    lpValue: ptr uint16,  # LPWSTR optional, out
    pcchValue: ptr uint32  # DWORD* optional, in/out
): uint32 {.importc: "MsiGetPatchInfoExW", stdcall, dynlib: "msi.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。
pragma(lib, "msi");
extern(Windows)
uint MsiGetPatchInfoExW(
    const(wchar)* szPatchCode,   // LPCWSTR
    const(wchar)* szProductCode,   // LPCWSTR
    const(wchar)* szUserSid,   // LPCWSTR optional
    int dwContext,   // MSIINSTALLCONTEXT
    const(wchar)* szProperty,   // LPCWSTR
    wchar* lpValue,   // LPWSTR optional, out
    uint* pcchValue   // DWORD* optional, in/out
);
ccall((:MsiGetPatchInfoExW, "msi.dll"), stdcall, UInt32,
      (Cwstring, Cwstring, Cwstring, Int32, Cwstring, Ptr{UInt16}, Ptr{UInt32}),
      szPatchCode, szProductCode, szUserSid, dwContext, szProperty, lpValue, pcchValue)
# szPatchCode : LPCWSTR -> Cwstring
# szProductCode : LPCWSTR -> Cwstring
# szUserSid : LPCWSTR optional -> Cwstring
# dwContext : MSIINSTALLCONTEXT -> Int32
# szProperty : LPCWSTR -> Cwstring
# lpValue : LPWSTR optional, out -> Ptr{UInt16}
# pcchValue : DWORD* optional, in/out -> Ptr{UInt32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。
local ffi = require("ffi")
ffi.cdef[[
uint32_t MsiGetPatchInfoExW(
    const uint16_t* szPatchCode,
    const uint16_t* szProductCode,
    const uint16_t* szUserSid,
    int32_t dwContext,
    const uint16_t* szProperty,
    uint16_t* lpValue,
    uint32_t* pcchValue);
]]
local msi = ffi.load("msi")
-- msi.MsiGetPatchInfoExW(szPatchCode, szProductCode, szUserSid, dwContext, szProperty, lpValue, pcchValue)
-- szPatchCode : LPCWSTR
-- szProductCode : LPCWSTR
-- szUserSid : LPCWSTR optional
-- dwContext : MSIINSTALLCONTEXT
-- szProperty : LPCWSTR
-- lpValue : LPWSTR optional, out
-- pcchValue : 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 MsiGetPatchInfoExW = lib.func('__stdcall', 'MsiGetPatchInfoExW', 'uint32_t', ['str16', 'str16', 'str16', 'int32_t', 'str16', 'uint16_t *', 'uint32_t *']);
// MsiGetPatchInfoExW(szPatchCode, szProductCode, szUserSid, dwContext, szProperty, lpValue, pcchValue)
// szPatchCode : LPCWSTR -> 'str16'
// szProductCode : LPCWSTR -> 'str16'
// szUserSid : LPCWSTR optional -> 'str16'
// dwContext : MSIINSTALLCONTEXT -> 'int32_t'
// szProperty : LPCWSTR -> 'str16'
// lpValue : LPWSTR optional, out -> 'uint16_t *'
// pcchValue : DWORD* optional, in/out -> 'uint32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("msi.dll", {
  MsiGetPatchInfoExW: { parameters: ["buffer", "buffer", "buffer", "i32", "buffer", "buffer", "pointer"], result: "u32" },
});
// lib.symbols.MsiGetPatchInfoExW(szPatchCode, szProductCode, szUserSid, dwContext, szProperty, lpValue, pcchValue)
// szPatchCode : LPCWSTR -> "buffer"
// szProductCode : LPCWSTR -> "buffer"
// szUserSid : LPCWSTR optional -> "buffer"
// dwContext : MSIINSTALLCONTEXT -> "i32"
// szProperty : LPCWSTR -> "buffer"
// lpValue : LPWSTR optional, out -> "buffer"
// pcchValue : 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 MsiGetPatchInfoExW(
    const uint16_t* szPatchCode,
    const uint16_t* szProductCode,
    const uint16_t* szUserSid,
    int32_t dwContext,
    const uint16_t* szProperty,
    uint16_t* lpValue,
    uint32_t* pcchValue);
C, "msi.dll");
// $ffi->MsiGetPatchInfoExW(szPatchCode, szProductCode, szUserSid, dwContext, szProperty, lpValue, pcchValue);
// szPatchCode : LPCWSTR
// szProductCode : LPCWSTR
// szUserSid : LPCWSTR optional
// dwContext : MSIINSTALLCONTEXT
// szProperty : LPCWSTR
// lpValue : LPWSTR optional, out
// pcchValue : 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 MsiGetPatchInfoExW(
        WString szPatchCode,   // LPCWSTR
        WString szProductCode,   // LPCWSTR
        WString szUserSid,   // LPCWSTR optional
        int dwContext,   // MSIINSTALLCONTEXT
        WString szProperty,   // LPCWSTR
        char[] lpValue,   // LPWSTR optional, out
        IntByReference pcchValue   // DWORD* optional, in/out
    );
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。
@[Link("msi")]
lib Libmsi
  fun MsiGetPatchInfoExW = MsiGetPatchInfoExW(
    szPatchCode : UInt16*,   # LPCWSTR
    szProductCode : UInt16*,   # LPCWSTR
    szUserSid : UInt16*,   # LPCWSTR optional
    dwContext : Int32,   # MSIINSTALLCONTEXT
    szProperty : UInt16*,   # LPCWSTR
    lpValue : UInt16*,   # LPWSTR optional, out
    pcchValue : 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 MsiGetPatchInfoExWNative = Uint32 Function(Pointer<Utf16>, Pointer<Utf16>, Pointer<Utf16>, Int32, Pointer<Utf16>, Pointer<Utf16>, Pointer<Uint32>);
typedef MsiGetPatchInfoExWDart = int Function(Pointer<Utf16>, Pointer<Utf16>, Pointer<Utf16>, int, Pointer<Utf16>, Pointer<Utf16>, Pointer<Uint32>);
final MsiGetPatchInfoExW = DynamicLibrary.open('msi.dll')
    .lookupFunction<MsiGetPatchInfoExWNative, MsiGetPatchInfoExWDart>('MsiGetPatchInfoExW');
// szPatchCode : LPCWSTR -> Pointer<Utf16>
// szProductCode : LPCWSTR -> Pointer<Utf16>
// szUserSid : LPCWSTR optional -> Pointer<Utf16>
// dwContext : MSIINSTALLCONTEXT -> Int32
// szProperty : LPCWSTR -> Pointer<Utf16>
// lpValue : LPWSTR optional, out -> Pointer<Utf16>
// pcchValue : DWORD* optional, in/out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function MsiGetPatchInfoExW(
  szPatchCode: PWideChar;   // LPCWSTR
  szProductCode: PWideChar;   // LPCWSTR
  szUserSid: PWideChar;   // LPCWSTR optional
  dwContext: Integer;   // MSIINSTALLCONTEXT
  szProperty: PWideChar;   // LPCWSTR
  lpValue: PWideChar;   // LPWSTR optional, out
  pcchValue: Pointer   // DWORD* optional, in/out
): DWORD; stdcall;
  external 'msi.dll' name 'MsiGetPatchInfoExW';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "MsiGetPatchInfoExW"
  c_MsiGetPatchInfoExW :: CWString -> CWString -> CWString -> Int32 -> CWString -> CWString -> Ptr Word32 -> IO Word32
-- szPatchCode : LPCWSTR -> CWString
-- szProductCode : LPCWSTR -> CWString
-- szUserSid : LPCWSTR optional -> CWString
-- dwContext : MSIINSTALLCONTEXT -> Int32
-- szProperty : LPCWSTR -> CWString
-- lpValue : LPWSTR optional, out -> CWString
-- pcchValue : DWORD* optional, in/out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let msigetpatchinfoexw =
  foreign "MsiGetPatchInfoExW"
    ((ptr uint16_t) @-> (ptr uint16_t) @-> (ptr uint16_t) @-> int32_t @-> (ptr uint16_t) @-> (ptr uint16_t) @-> (ptr uint32_t) @-> returning uint32_t)
(* szPatchCode : LPCWSTR -> (ptr uint16_t) *)
(* szProductCode : LPCWSTR -> (ptr uint16_t) *)
(* szUserSid : LPCWSTR optional -> (ptr uint16_t) *)
(* dwContext : MSIINSTALLCONTEXT -> int32_t *)
(* szProperty : LPCWSTR -> (ptr uint16_t) *)
(* lpValue : LPWSTR optional, out -> (ptr uint16_t) *)
(* pcchValue : 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 ("MsiGetPatchInfoExW" msi-get-patch-info-ex-w :convention :stdcall) :uint32
  (sz-patch-code (:string :encoding :utf-16le))   ; LPCWSTR
  (sz-product-code (:string :encoding :utf-16le))   ; LPCWSTR
  (sz-user-sid (:string :encoding :utf-16le))   ; LPCWSTR optional
  (dw-context :int32)   ; MSIINSTALLCONTEXT
  (sz-property (:string :encoding :utf-16le))   ; LPCWSTR
  (lp-value :pointer)   ; LPWSTR optional, out
  (pcch-value :pointer))   ; DWORD* optional, in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $MsiGetPatchInfoExW = Win32::API::More->new('msi',
    'DWORD MsiGetPatchInfoExW(LPCWSTR szPatchCode, LPCWSTR szProductCode, LPCWSTR szUserSid, int dwContext, LPCWSTR szProperty, LPWSTR lpValue, LPVOID pcchValue)');
# my $ret = $MsiGetPatchInfoExW->Call($szPatchCode, $szProductCode, $szUserSid, $dwContext, $szProperty, $lpValue, $pcchValue);
# szPatchCode : LPCWSTR -> LPCWSTR
# szProductCode : LPCWSTR -> LPCWSTR
# szUserSid : LPCWSTR optional -> LPCWSTR
# dwContext : MSIINSTALLCONTEXT -> int
# szProperty : LPCWSTR -> LPCWSTR
# lpValue : LPWSTR optional, out -> LPWSTR
# pcchValue : DWORD* optional, in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。

関連項目

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