MsiGetPatchInfoExW
関数シグネチャ
// 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
);パラメーター
| 名前 | 型 | 方向 | 説明 | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| szPatchCode | LPCWSTR | in | パッチの GUID を含む null 終端文字列です。このパラメーターを NULL にすることはできません。 | ||||||||||||||||
| szProductCode | LPCWSTR | in | 製品インスタンスの ProductCode GUID を含む null 終端文字列です。このパラメーターを NULL にすることはできません。 | ||||||||||||||||
| szUserSid | LPCWSTR | inoptional | 照会対象のパッチインスタンスが存在するセキュリティ識別子 (SID) を指定する null 終端文字列です。NULL を指定すると、現在のユーザーを指定したことになります。
注 特殊な SID 文字列 "S-1-5-18" (システム) を使用して、コンピューター単位 (per-machine) でインストールされた製品を列挙することはできません。dwContext が MSIINSTALLCONTEXT_MACHINE の場合、szUserSid は NULL でなければなりません。
| ||||||||||||||||
| dwContext | MSIINSTALLCONTEXT | in | 列挙を、ユーザー単位の非管理 (per-user-unmanaged)、ユーザー単位の管理 (per-user-managed)、またはコンピューター単位 (per-machine) のコンテキストに限定します。このパラメーターには、次のいずれかの値を指定できます。 | ||||||||||||||||
| szProperty | LPCWSTR | in | 取得するプロパティ値を指定する null 終端文字列です。szProperty パラメーターには、次のいずれかを指定できます。
| ||||||||||||||||
| lpValue | LPWSTR | outoptional | このパラメーターは、プロパティ値を受け取るバッファーへのポインターです。このバッファーは、情報を格納するのに十分な大きさである必要があります。バッファーが小さすぎる場合、関数は ERROR_MORE_DATA を返し、*pcchValue に、終端の NULL 文字を含まないプロパティ値内の TCHAR 数を設定します。 lpValue を NULL に設定し、pcchValue を有効なポインターに設定した場合、関数は ERROR_SUCCESS を返し、pcchValue に、終端の NULL 文字を含まない値内の TCHAR 数を設定します。その後、pcchValue + 1 文字を格納できる十分な大きさの lpValue バッファーを用意して、関数を再度呼び出すことで値を取得できます。 lpValue と pcchValue の両方を NULL に設定した場合、関数は値を取得せずに、値が存在すれば ERROR_SUCCESS を返します。 | ||||||||||||||||
| pcchValue | DWORD* | inoutoptional | 関数を呼び出すときには、このパラメーターは lpValue バッファー内の TCHAR 数を指定する変数へのポインターである必要があります。関数が返るときには、このパラメーターには、関数が値を指定したバッファーにコピーしたかどうかにかかわらず、要求された値のサイズが設定されます。サイズは、終端の null 文字を含まない、要求された値内の TCHAR 数として返されます。 このパラメーターを NULL に設定できるのは、lpValue も NULL である場合のみです。それ以外の場合、関数は ERROR_INVALID_PARAMETER を返します。 |
戻り値の型: DWORD
公式ドキュメント
指定した製品インスタンスへのパッチ適用に関する情報を照会します。(Unicode)
戻り値
MsiGetPatchInfoEx 関数は、次の値を返します。
| リターンコード | 説明 |
|---|---|
| 権限が不足した状態でリソースにアクセスしようとして、関数が失敗しました。 | |
| 構成データが破損しています。 | |
| 関数が失敗し、そのエラーが他のエラーコードで識別されません。 | |
| 無効なパラメーターが関数に渡されました。 | |
| 値が指定されたバッファーに収まりません。 | |
| パッチが正常に列挙されました。 | |
| szProduct で指定された製品がコンピューターにインストールされていません。 | |
| プロパティが認識されません。 | |
| パッチが認識されません。 |
解説(Remarks)
Windows Installer 2.0: サポートされていません。この関数は Windows Installer バージョン 3.0 以降で利用できます。
ユーザーは、参照可能な任意の製品インスタンスについてパッチデータを照会できます。Administrators グループは、コンピューター上の任意の製品インスタンスおよび任意のユーザーについてパッチデータを照会できます。ユーザーがログオンしていない場合、ユーザー単位の非管理アプリケーションでは、すべての値が利用できることが保証されるわけではありません。
msi.h ヘッダーは、UNICODE プリプロセッサ定数の定義に基づいて、この関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして MsiGetPatchInfoEx を定義しています。エンコーディング非依存のエイリアスの使用を、エンコーディング非依存でないコードと混在させると、不一致が生じ、コンパイルエラーや実行時エラーの原因となることがあります。詳細については、関数プロトタイプの規則 を参照してください。
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 方式にも切替可。#uselib "msi.dll" #cfunc global MsiGetPatchInfoExW "MsiGetPatchInfoExW" wstr, wstr, wstr, int, wstr, sptr, sptr ; res = MsiGetPatchInfoExW(szPatchCode, szProductCode, szUserSid, dwContext, szProperty, varptr(lpValue), varptr(pcchValue)) ; szPatchCode : LPCWSTR -> "wstr" ; szProductCode : LPCWSTR -> "wstr" ; szUserSid : LPCWSTR optional -> "wstr" ; dwContext : MSIINSTALLCONTEXT -> "int" ; szProperty : LPCWSTR -> "wstr" ; lpValue : LPWSTR optional, out -> "sptr" ; pcchValue : DWORD* optional, in/out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは 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 方式にも切替可。; 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, intptr, intptr ; res = MsiGetPatchInfoExW(szPatchCode, szProductCode, szUserSid, dwContext, szProperty, varptr(lpValue), varptr(pcchValue)) ; szPatchCode : LPCWSTR -> "wstr" ; szProductCode : LPCWSTR -> "wstr" ; szUserSid : LPCWSTR optional -> "wstr" ; dwContext : MSIINSTALLCONTEXT -> "int" ; szProperty : LPCWSTR -> "wstr" ; lpValue : LPWSTR optional, out -> "intptr" ; pcchValue : DWORD* optional, in/out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは 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 // DWORDfunction 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 変換を行う。関連項目
- f MsiGetPatchInfoExA (ANSI版) — コンテキスト指定でパッチの詳細情報を取得する(ANSI版)。
- f MsiGetPatchInfoW — 適用済みパッチの情報を取得する(Unicode版)。