MsiGetPatchInfoExA
関数シグネチャ
// msi.dll (ANSI / -A)
#include <windows.h>
DWORD MsiGetPatchInfoExA(
LPCSTR szPatchCode,
LPCSTR szProductCode,
LPCSTR szUserSid, // optional
MSIINSTALLCONTEXT dwContext,
LPCSTR szProperty,
LPSTR lpValue, // optional
DWORD* pcchValue // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| szPatchCode | LPCSTR | in | パッチの GUID を格納する null 終端文字列です。このパラメーターを NULL にすることはできません。 | ||||||||||||||||
| szProductCode | LPCSTR | in | 製品インスタンスの ProductCode GUID を格納する null 終端文字列です。このパラメーターを NULL にすることはできません。 | ||||||||||||||||
| szUserSid | LPCSTR | inoptional | 照会対象のパッチインスタンスが存在するセキュリティ識別子 (SID) を指定する null 終端文字列です。NULL を指定すると、現在のユーザーを指定したことになります。
注意 特殊な SID 文字列 "S-1-5-18" (system) は、コンピューター単位 (per-machine) でインストールされた製品の列挙には使用できません。dwContext が MSIINSTALLCONTEXT_MACHINE の場合、szUserSid は NULL でなければなりません。
| ||||||||||||||||
| dwContext | MSIINSTALLCONTEXT | in | 列挙を、ユーザー単位の非管理 (per-user-unmanaged)、ユーザー単位の管理 (per-user-managed)、またはコンピューター単位 (per-machine) のいずれかのコンテキストに限定します。このパラメーターには、次のいずれかの値を指定できます。
| ||||||||||||||||
| szProperty | LPCSTR | in | 取得するプロパティ値を指定する null 終端文字列です。szProperty パラメーターには、次のいずれかを指定できます。
| ||||||||||||||||
| lpValue | LPSTR | 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
公式ドキュメント
指定した製品インスタンスへのパッチの適用に関する情報を照会します。(ANSI)
戻り値
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 (ANSI / -A)
#include <windows.h>
DWORD MsiGetPatchInfoExA(
LPCSTR szPatchCode,
LPCSTR szProductCode,
LPCSTR szUserSid, // optional
MSIINSTALLCONTEXT dwContext,
LPCSTR szProperty,
LPSTR lpValue, // optional
DWORD* pcchValue // optional
);[DllImport("msi.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern uint MsiGetPatchInfoExA(
[MarshalAs(UnmanagedType.LPStr)] string szPatchCode, // LPCSTR
[MarshalAs(UnmanagedType.LPStr)] string szProductCode, // LPCSTR
[MarshalAs(UnmanagedType.LPStr)] string szUserSid, // LPCSTR optional
int dwContext, // MSIINSTALLCONTEXT
[MarshalAs(UnmanagedType.LPStr)] string szProperty, // LPCSTR
[MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder lpValue, // LPSTR optional, out
IntPtr pcchValue // DWORD* optional, in/out
);<DllImport("msi.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function MsiGetPatchInfoExA(
<MarshalAs(UnmanagedType.LPStr)> szPatchCode As String, ' LPCSTR
<MarshalAs(UnmanagedType.LPStr)> szProductCode As String, ' LPCSTR
<MarshalAs(UnmanagedType.LPStr)> szUserSid As String, ' LPCSTR optional
dwContext As Integer, ' MSIINSTALLCONTEXT
<MarshalAs(UnmanagedType.LPStr)> szProperty As String, ' LPCSTR
<MarshalAs(UnmanagedType.LPStr)> lpValue As System.Text.StringBuilder, ' LPSTR optional, out
pcchValue As IntPtr ' DWORD* optional, in/out
) As UInteger
End Function' szPatchCode : LPCSTR
' szProductCode : LPCSTR
' szUserSid : LPCSTR optional
' dwContext : MSIINSTALLCONTEXT
' szProperty : LPCSTR
' lpValue : LPSTR optional, out
' pcchValue : DWORD* optional, in/out
Declare PtrSafe Function MsiGetPatchInfoExA Lib "msi" ( _
ByVal szPatchCode As String, _
ByVal szProductCode As String, _
ByVal szUserSid As String, _
ByVal dwContext As Long, _
ByVal szProperty As String, _
ByVal lpValue As String, _
ByVal pcchValue As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
MsiGetPatchInfoExA = ctypes.windll.msi.MsiGetPatchInfoExA
MsiGetPatchInfoExA.restype = wintypes.DWORD
MsiGetPatchInfoExA.argtypes = [
wintypes.LPCSTR, # szPatchCode : LPCSTR
wintypes.LPCSTR, # szProductCode : LPCSTR
wintypes.LPCSTR, # szUserSid : LPCSTR optional
ctypes.c_int, # dwContext : MSIINSTALLCONTEXT
wintypes.LPCSTR, # szProperty : LPCSTR
wintypes.LPSTR, # lpValue : LPSTR optional, out
ctypes.POINTER(wintypes.DWORD), # pcchValue : DWORD* optional, in/out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('msi.dll')
MsiGetPatchInfoExA = Fiddle::Function.new(
lib['MsiGetPatchInfoExA'],
[
Fiddle::TYPE_VOIDP, # szPatchCode : LPCSTR
Fiddle::TYPE_VOIDP, # szProductCode : LPCSTR
Fiddle::TYPE_VOIDP, # szUserSid : LPCSTR optional
Fiddle::TYPE_INT, # dwContext : MSIINSTALLCONTEXT
Fiddle::TYPE_VOIDP, # szProperty : LPCSTR
Fiddle::TYPE_VOIDP, # lpValue : LPSTR optional, out
Fiddle::TYPE_VOIDP, # pcchValue : DWORD* optional, in/out
],
-Fiddle::TYPE_INT)#[link(name = "msi")]
extern "system" {
fn MsiGetPatchInfoExA(
szPatchCode: *const u8, // LPCSTR
szProductCode: *const u8, // LPCSTR
szUserSid: *const u8, // LPCSTR optional
dwContext: i32, // MSIINSTALLCONTEXT
szProperty: *const u8, // LPCSTR
lpValue: *mut u8, // LPSTR 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.Ansi)]
public static extern uint MsiGetPatchInfoExA([MarshalAs(UnmanagedType.LPStr)] string szPatchCode, [MarshalAs(UnmanagedType.LPStr)] string szProductCode, [MarshalAs(UnmanagedType.LPStr)] string szUserSid, int dwContext, [MarshalAs(UnmanagedType.LPStr)] string szProperty, [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder lpValue, IntPtr pcchValue);
"@
$api = Add-Type -MemberDefinition $sig -Name 'msi_MsiGetPatchInfoExA' -Namespace Win32 -PassThru
# $api::MsiGetPatchInfoExA(szPatchCode, szProductCode, szUserSid, dwContext, szProperty, lpValue, pcchValue)#uselib "msi.dll"
#func global MsiGetPatchInfoExA "MsiGetPatchInfoExA" sptr, sptr, sptr, sptr, sptr, sptr, sptr
; MsiGetPatchInfoExA szPatchCode, szProductCode, szUserSid, dwContext, szProperty, varptr(lpValue), varptr(pcchValue) ; 戻り値は stat
; szPatchCode : LPCSTR -> "sptr"
; szProductCode : LPCSTR -> "sptr"
; szUserSid : LPCSTR optional -> "sptr"
; dwContext : MSIINSTALLCONTEXT -> "sptr"
; szProperty : LPCSTR -> "sptr"
; lpValue : LPSTR optional, out -> "sptr"
; pcchValue : DWORD* optional, in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "msi.dll" #cfunc global MsiGetPatchInfoExA "MsiGetPatchInfoExA" str, str, str, int, str, var, var ; res = MsiGetPatchInfoExA(szPatchCode, szProductCode, szUserSid, dwContext, szProperty, lpValue, pcchValue) ; szPatchCode : LPCSTR -> "str" ; szProductCode : LPCSTR -> "str" ; szUserSid : LPCSTR optional -> "str" ; dwContext : MSIINSTALLCONTEXT -> "int" ; szProperty : LPCSTR -> "str" ; lpValue : LPSTR optional, out -> "var" ; pcchValue : DWORD* optional, in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "msi.dll" #cfunc global MsiGetPatchInfoExA "MsiGetPatchInfoExA" str, str, str, int, str, sptr, sptr ; res = MsiGetPatchInfoExA(szPatchCode, szProductCode, szUserSid, dwContext, szProperty, varptr(lpValue), varptr(pcchValue)) ; szPatchCode : LPCSTR -> "str" ; szProductCode : LPCSTR -> "str" ; szUserSid : LPCSTR optional -> "str" ; dwContext : MSIINSTALLCONTEXT -> "int" ; szProperty : LPCSTR -> "str" ; lpValue : LPSTR optional, out -> "sptr" ; pcchValue : DWORD* optional, in/out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
; DWORD MsiGetPatchInfoExA(LPCSTR szPatchCode, LPCSTR szProductCode, LPCSTR szUserSid, MSIINSTALLCONTEXT dwContext, LPCSTR szProperty, LPSTR lpValue, DWORD* pcchValue) #uselib "msi.dll" #cfunc global MsiGetPatchInfoExA "MsiGetPatchInfoExA" str, str, str, int, str, var, var ; res = MsiGetPatchInfoExA(szPatchCode, szProductCode, szUserSid, dwContext, szProperty, lpValue, pcchValue) ; szPatchCode : LPCSTR -> "str" ; szProductCode : LPCSTR -> "str" ; szUserSid : LPCSTR optional -> "str" ; dwContext : MSIINSTALLCONTEXT -> "int" ; szProperty : LPCSTR -> "str" ; lpValue : LPSTR optional, out -> "var" ; pcchValue : DWORD* optional, in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; DWORD MsiGetPatchInfoExA(LPCSTR szPatchCode, LPCSTR szProductCode, LPCSTR szUserSid, MSIINSTALLCONTEXT dwContext, LPCSTR szProperty, LPSTR lpValue, DWORD* pcchValue) #uselib "msi.dll" #cfunc global MsiGetPatchInfoExA "MsiGetPatchInfoExA" str, str, str, int, str, intptr, intptr ; res = MsiGetPatchInfoExA(szPatchCode, szProductCode, szUserSid, dwContext, szProperty, varptr(lpValue), varptr(pcchValue)) ; szPatchCode : LPCSTR -> "str" ; szProductCode : LPCSTR -> "str" ; szUserSid : LPCSTR optional -> "str" ; dwContext : MSIINSTALLCONTEXT -> "int" ; szProperty : LPCSTR -> "str" ; lpValue : LPSTR 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")
procMsiGetPatchInfoExA = msi.NewProc("MsiGetPatchInfoExA")
)
// szPatchCode (LPCSTR), szProductCode (LPCSTR), szUserSid (LPCSTR optional), dwContext (MSIINSTALLCONTEXT), szProperty (LPCSTR), lpValue (LPSTR optional, out), pcchValue (DWORD* optional, in/out)
r1, _, err := procMsiGetPatchInfoExA.Call(
uintptr(unsafe.Pointer(windows.BytePtrFromString(szPatchCode))),
uintptr(unsafe.Pointer(windows.BytePtrFromString(szProductCode))),
uintptr(unsafe.Pointer(windows.BytePtrFromString(szUserSid))),
uintptr(dwContext),
uintptr(unsafe.Pointer(windows.BytePtrFromString(szProperty))),
uintptr(lpValue),
uintptr(pcchValue),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction MsiGetPatchInfoExA(
szPatchCode: PAnsiChar; // LPCSTR
szProductCode: PAnsiChar; // LPCSTR
szUserSid: PAnsiChar; // LPCSTR optional
dwContext: Integer; // MSIINSTALLCONTEXT
szProperty: PAnsiChar; // LPCSTR
lpValue: PAnsiChar; // LPSTR optional, out
pcchValue: Pointer // DWORD* optional, in/out
): DWORD; stdcall;
external 'msi.dll' name 'MsiGetPatchInfoExA';result := DllCall("msi\MsiGetPatchInfoExA"
, "AStr", szPatchCode ; LPCSTR
, "AStr", szProductCode ; LPCSTR
, "AStr", szUserSid ; LPCSTR optional
, "Int", dwContext ; MSIINSTALLCONTEXT
, "AStr", szProperty ; LPCSTR
, "Ptr", lpValue ; LPSTR optional, out
, "Ptr", pcchValue ; DWORD* optional, in/out
, "UInt") ; return: DWORD●MsiGetPatchInfoExA(szPatchCode, szProductCode, szUserSid, dwContext, szProperty, lpValue, pcchValue) = DLL("msi.dll", "dword MsiGetPatchInfoExA(char*, char*, char*, int, char*, char*, void*)")
# 呼び出し: MsiGetPatchInfoExA(szPatchCode, szProductCode, szUserSid, dwContext, szProperty, lpValue, pcchValue)
# szPatchCode : LPCSTR -> "char*"
# szProductCode : LPCSTR -> "char*"
# szUserSid : LPCSTR optional -> "char*"
# dwContext : MSIINSTALLCONTEXT -> "int"
# szProperty : LPCSTR -> "char*"
# lpValue : LPSTR optional, out -> "char*"
# pcchValue : DWORD* optional, in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "msi" fn MsiGetPatchInfoExA(
szPatchCode: [*c]const u8, // LPCSTR
szProductCode: [*c]const u8, // LPCSTR
szUserSid: [*c]const u8, // LPCSTR optional
dwContext: i32, // MSIINSTALLCONTEXT
szProperty: [*c]const u8, // LPCSTR
lpValue: [*c]u8, // LPSTR optional, out
pcchValue: [*c]u32 // DWORD* optional, in/out
) callconv(std.os.windows.WINAPI) u32;proc MsiGetPatchInfoExA(
szPatchCode: cstring, # LPCSTR
szProductCode: cstring, # LPCSTR
szUserSid: cstring, # LPCSTR optional
dwContext: int32, # MSIINSTALLCONTEXT
szProperty: cstring, # LPCSTR
lpValue: ptr char, # LPSTR optional, out
pcchValue: ptr uint32 # DWORD* optional, in/out
): uint32 {.importc: "MsiGetPatchInfoExA", stdcall, dynlib: "msi.dll".}pragma(lib, "msi");
extern(Windows)
uint MsiGetPatchInfoExA(
const(char)* szPatchCode, // LPCSTR
const(char)* szProductCode, // LPCSTR
const(char)* szUserSid, // LPCSTR optional
int dwContext, // MSIINSTALLCONTEXT
const(char)* szProperty, // LPCSTR
char* lpValue, // LPSTR optional, out
uint* pcchValue // DWORD* optional, in/out
);ccall((:MsiGetPatchInfoExA, "msi.dll"), stdcall, UInt32,
(Cstring, Cstring, Cstring, Int32, Cstring, Ptr{UInt8}, Ptr{UInt32}),
szPatchCode, szProductCode, szUserSid, dwContext, szProperty, lpValue, pcchValue)
# szPatchCode : LPCSTR -> Cstring
# szProductCode : LPCSTR -> Cstring
# szUserSid : LPCSTR optional -> Cstring
# dwContext : MSIINSTALLCONTEXT -> Int32
# szProperty : LPCSTR -> Cstring
# lpValue : LPSTR optional, out -> Ptr{UInt8}
# pcchValue : DWORD* optional, in/out -> Ptr{UInt32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
uint32_t MsiGetPatchInfoExA(
const char* szPatchCode,
const char* szProductCode,
const char* szUserSid,
int32_t dwContext,
const char* szProperty,
char* lpValue,
uint32_t* pcchValue);
]]
local msi = ffi.load("msi")
-- msi.MsiGetPatchInfoExA(szPatchCode, szProductCode, szUserSid, dwContext, szProperty, lpValue, pcchValue)
-- szPatchCode : LPCSTR
-- szProductCode : LPCSTR
-- szUserSid : LPCSTR optional
-- dwContext : MSIINSTALLCONTEXT
-- szProperty : LPCSTR
-- lpValue : LPSTR optional, out
-- pcchValue : DWORD* optional, in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('msi.dll');
const MsiGetPatchInfoExA = lib.func('__stdcall', 'MsiGetPatchInfoExA', 'uint32_t', ['str', 'str', 'str', 'int32_t', 'str', 'char *', 'uint32_t *']);
// MsiGetPatchInfoExA(szPatchCode, szProductCode, szUserSid, dwContext, szProperty, lpValue, pcchValue)
// szPatchCode : LPCSTR -> 'str'
// szProductCode : LPCSTR -> 'str'
// szUserSid : LPCSTR optional -> 'str'
// dwContext : MSIINSTALLCONTEXT -> 'int32_t'
// szProperty : LPCSTR -> 'str'
// lpValue : LPSTR optional, out -> 'char *'
// pcchValue : DWORD* optional, in/out -> 'uint32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("msi.dll", {
MsiGetPatchInfoExA: { parameters: ["buffer", "buffer", "buffer", "i32", "buffer", "buffer", "pointer"], result: "u32" },
});
// lib.symbols.MsiGetPatchInfoExA(szPatchCode, szProductCode, szUserSid, dwContext, szProperty, lpValue, pcchValue)
// szPatchCode : LPCSTR -> "buffer"
// szProductCode : LPCSTR -> "buffer"
// szUserSid : LPCSTR optional -> "buffer"
// dwContext : MSIINSTALLCONTEXT -> "i32"
// szProperty : LPCSTR -> "buffer"
// lpValue : LPSTR optional, out -> "buffer"
// pcchValue : DWORD* optional, in/out -> "pointer"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t MsiGetPatchInfoExA(
const char* szPatchCode,
const char* szProductCode,
const char* szUserSid,
int32_t dwContext,
const char* szProperty,
char* lpValue,
uint32_t* pcchValue);
C, "msi.dll");
// $ffi->MsiGetPatchInfoExA(szPatchCode, szProductCode, szUserSid, dwContext, szProperty, lpValue, pcchValue);
// szPatchCode : LPCSTR
// szProductCode : LPCSTR
// szUserSid : LPCSTR optional
// dwContext : MSIINSTALLCONTEXT
// szProperty : LPCSTR
// lpValue : LPSTR 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.ASCII_OPTIONS);
int MsiGetPatchInfoExA(
String szPatchCode, // LPCSTR
String szProductCode, // LPCSTR
String szUserSid, // LPCSTR optional
int dwContext, // MSIINSTALLCONTEXT
String szProperty, // LPCSTR
byte[] lpValue, // LPSTR optional, out
IntByReference pcchValue // DWORD* optional, in/out
);
}@[Link("msi")]
lib Libmsi
fun MsiGetPatchInfoExA = MsiGetPatchInfoExA(
szPatchCode : UInt8*, # LPCSTR
szProductCode : UInt8*, # LPCSTR
szUserSid : UInt8*, # LPCSTR optional
dwContext : Int32, # MSIINSTALLCONTEXT
szProperty : UInt8*, # LPCSTR
lpValue : UInt8*, # LPSTR 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 MsiGetPatchInfoExANative = Uint32 Function(Pointer<Utf8>, Pointer<Utf8>, Pointer<Utf8>, Int32, Pointer<Utf8>, Pointer<Utf8>, Pointer<Uint32>);
typedef MsiGetPatchInfoExADart = int Function(Pointer<Utf8>, Pointer<Utf8>, Pointer<Utf8>, int, Pointer<Utf8>, Pointer<Utf8>, Pointer<Uint32>);
final MsiGetPatchInfoExA = DynamicLibrary.open('msi.dll')
.lookupFunction<MsiGetPatchInfoExANative, MsiGetPatchInfoExADart>('MsiGetPatchInfoExA');
// szPatchCode : LPCSTR -> Pointer<Utf8>
// szProductCode : LPCSTR -> Pointer<Utf8>
// szUserSid : LPCSTR optional -> Pointer<Utf8>
// dwContext : MSIINSTALLCONTEXT -> Int32
// szProperty : LPCSTR -> Pointer<Utf8>
// lpValue : LPSTR optional, out -> Pointer<Utf8>
// pcchValue : DWORD* optional, in/out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function MsiGetPatchInfoExA(
szPatchCode: PAnsiChar; // LPCSTR
szProductCode: PAnsiChar; // LPCSTR
szUserSid: PAnsiChar; // LPCSTR optional
dwContext: Integer; // MSIINSTALLCONTEXT
szProperty: PAnsiChar; // LPCSTR
lpValue: PAnsiChar; // LPSTR optional, out
pcchValue: Pointer // DWORD* optional, in/out
): DWORD; stdcall;
external 'msi.dll' name 'MsiGetPatchInfoExA';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "MsiGetPatchInfoExA"
c_MsiGetPatchInfoExA :: CString -> CString -> CString -> Int32 -> CString -> CString -> Ptr Word32 -> IO Word32
-- szPatchCode : LPCSTR -> CString
-- szProductCode : LPCSTR -> CString
-- szUserSid : LPCSTR optional -> CString
-- dwContext : MSIINSTALLCONTEXT -> Int32
-- szProperty : LPCSTR -> CString
-- lpValue : LPSTR optional, out -> CString
-- pcchValue : DWORD* optional, in/out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let msigetpatchinfoexa =
foreign "MsiGetPatchInfoExA"
(string @-> string @-> string @-> int32_t @-> string @-> string @-> (ptr uint32_t) @-> returning uint32_t)
(* szPatchCode : LPCSTR -> string *)
(* szProductCode : LPCSTR -> string *)
(* szUserSid : LPCSTR optional -> string *)
(* dwContext : MSIINSTALLCONTEXT -> int32_t *)
(* szProperty : LPCSTR -> string *)
(* lpValue : LPSTR optional, out -> string *)
(* 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 ("MsiGetPatchInfoExA" msi-get-patch-info-ex-a :convention :stdcall) :uint32
(sz-patch-code :string) ; LPCSTR
(sz-product-code :string) ; LPCSTR
(sz-user-sid :string) ; LPCSTR optional
(dw-context :int32) ; MSIINSTALLCONTEXT
(sz-property :string) ; LPCSTR
(lp-value :pointer) ; LPSTR 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 $MsiGetPatchInfoExA = Win32::API::More->new('msi',
'DWORD MsiGetPatchInfoExA(LPCSTR szPatchCode, LPCSTR szProductCode, LPCSTR szUserSid, int dwContext, LPCSTR szProperty, LPSTR lpValue, LPVOID pcchValue)');
# my $ret = $MsiGetPatchInfoExA->Call($szPatchCode, $szProductCode, $szUserSid, $dwContext, $szProperty, $lpValue, $pcchValue);
# szPatchCode : LPCSTR -> LPCSTR
# szProductCode : LPCSTR -> LPCSTR
# szUserSid : LPCSTR optional -> LPCSTR
# dwContext : MSIINSTALLCONTEXT -> int
# szProperty : LPCSTR -> LPCSTR
# lpValue : LPSTR optional, out -> LPSTR
# pcchValue : DWORD* optional, in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
- f MsiGetPatchInfoExW (Unicode版) — コンテキスト指定でパッチの詳細情報を取得する(Unicode版)。
- f MsiGetPatchInfoA — 適用済みパッチの情報を取得する(ANSI版)。