ホーム › System.ApplicationInstallationAndServicing › MsiGetPatchInfoW
MsiGetPatchInfoW
関数適用済みパッチの情報を取得する(Unicode版)。
シグネチャ
// msi.dll (Unicode / -W)
#include <windows.h>
DWORD MsiGetPatchInfoW(
LPCWSTR szPatch,
LPCWSTR szAttribute,
LPWSTR lpValueBuf, // optional
DWORD* pcchValueBuf // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 | ||||
|---|---|---|---|---|---|---|---|
| szPatch | LPCWSTR | in | パッチパッケージのパッチコードを指定します。 | ||||
| szAttribute | LPCWSTR | in | 取得する属性を指定します。
| ||||
| lpValueBuf | LPWSTR | outoptional | プロパティ値を受け取るバッファへのポインター。このパラメーターは null にできます。 | ||||
| pcchValueBuf | DWORD* | inoutoptional | lpValueBuf パラメーターが指すバッファのサイズ(文字数)を指定する変数へのポインター。入力時には、終端の null 文字用の領域を含むバッファ全体のサイズを指定します。渡したバッファが小さすぎる場合、返される文字数には終端の null 文字は含まれません。 lpValueBuf が null の場合、pcchValueBuf も null にできます。 |
戻り値の型: DWORD
公式ドキュメント
MsiGetPatchInfo 関数は、パッチに関する情報を返します。(Unicode)
戻り値
MsiGetPatchInfo 関数は次の値を返します。
| 値 | 意味 |
|---|---|
| 構成データが破損しています。 | |
| 無効なパラメーターが関数に渡されました。 | |
| バッファが小さすぎて、要求されたデータを保持できません。 | |
| 関数が正常に完了しました。 | |
| パッチパッケージがインストールされていません。 | |
| プロパティが認識されません。 |
解説(Remarks)
MsiGetPatchInfo 関数が返ると、pcchValueBuf パラメーターにはバッファに格納されたクラス文字列の長さが格納されます。返される文字数には終端の null 文字は含まれません。
バッファが小さすぎて要求されたデータを保持できない場合、MsiGetPatchInfo は ERROR_MORE_DATA を返し、pcchValueBuf には lpValueBuf にコピーされた文字数(null 文字を除く)が格納されます。
メモ
msi.h ヘッダーは、MsiGetPatchInfo を、UNICODE プリプロセッサ定数の定義に基づいてこの関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして定義します。エンコーディングに依存しないこのエイリアスの使用と、エンコーディングに依存しないわけではないコードを混在させると、不一致が生じ、コンパイルエラーや実行時エラーの原因となることがあります。詳細については、関数プロトタイプの規則を参照してください。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// msi.dll (Unicode / -W)
#include <windows.h>
DWORD MsiGetPatchInfoW(
LPCWSTR szPatch,
LPCWSTR szAttribute,
LPWSTR lpValueBuf, // optional
DWORD* pcchValueBuf // optional
);[DllImport("msi.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern uint MsiGetPatchInfoW(
[MarshalAs(UnmanagedType.LPWStr)] string szPatch, // LPCWSTR
[MarshalAs(UnmanagedType.LPWStr)] string szAttribute, // LPCWSTR
[MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder lpValueBuf, // LPWSTR optional, out
IntPtr pcchValueBuf // DWORD* optional, in/out
);<DllImport("msi.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function MsiGetPatchInfoW(
<MarshalAs(UnmanagedType.LPWStr)> szPatch As String, ' LPCWSTR
<MarshalAs(UnmanagedType.LPWStr)> szAttribute As String, ' LPCWSTR
<MarshalAs(UnmanagedType.LPWStr)> lpValueBuf As System.Text.StringBuilder, ' LPWSTR optional, out
pcchValueBuf As IntPtr ' DWORD* optional, in/out
) As UInteger
End Function' szPatch : LPCWSTR
' szAttribute : LPCWSTR
' lpValueBuf : LPWSTR optional, out
' pcchValueBuf : DWORD* optional, in/out
Declare PtrSafe Function MsiGetPatchInfoW Lib "msi" ( _
ByVal szPatch As LongPtr, _
ByVal szAttribute As LongPtr, _
ByVal lpValueBuf As LongPtr, _
ByVal pcchValueBuf 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
MsiGetPatchInfoW = ctypes.windll.msi.MsiGetPatchInfoW
MsiGetPatchInfoW.restype = wintypes.DWORD
MsiGetPatchInfoW.argtypes = [
wintypes.LPCWSTR, # szPatch : LPCWSTR
wintypes.LPCWSTR, # szAttribute : LPCWSTR
wintypes.LPWSTR, # lpValueBuf : LPWSTR optional, out
ctypes.POINTER(wintypes.DWORD), # pcchValueBuf : DWORD* optional, in/out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('msi.dll')
MsiGetPatchInfoW = Fiddle::Function.new(
lib['MsiGetPatchInfoW'],
[
Fiddle::TYPE_VOIDP, # szPatch : LPCWSTR
Fiddle::TYPE_VOIDP, # szAttribute : LPCWSTR
Fiddle::TYPE_VOIDP, # lpValueBuf : LPWSTR optional, out
Fiddle::TYPE_VOIDP, # pcchValueBuf : DWORD* optional, in/out
],
-Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "msi")]
extern "system" {
fn MsiGetPatchInfoW(
szPatch: *const u16, // LPCWSTR
szAttribute: *const u16, // LPCWSTR
lpValueBuf: *mut u16, // LPWSTR optional, out
pcchValueBuf: *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 MsiGetPatchInfoW([MarshalAs(UnmanagedType.LPWStr)] string szPatch, [MarshalAs(UnmanagedType.LPWStr)] string szAttribute, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder lpValueBuf, IntPtr pcchValueBuf);
"@
$api = Add-Type -MemberDefinition $sig -Name 'msi_MsiGetPatchInfoW' -Namespace Win32 -PassThru
# $api::MsiGetPatchInfoW(szPatch, szAttribute, lpValueBuf, pcchValueBuf)#uselib "msi.dll"
#func global MsiGetPatchInfoW "MsiGetPatchInfoW" wptr, wptr, wptr, wptr
; MsiGetPatchInfoW szPatch, szAttribute, varptr(lpValueBuf), varptr(pcchValueBuf) ; 戻り値は stat
; szPatch : LPCWSTR -> "wptr"
; szAttribute : LPCWSTR -> "wptr"
; lpValueBuf : LPWSTR optional, out -> "wptr"
; pcchValueBuf : DWORD* optional, in/out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "msi.dll" #cfunc global MsiGetPatchInfoW "MsiGetPatchInfoW" wstr, wstr, var, var ; res = MsiGetPatchInfoW(szPatch, szAttribute, lpValueBuf, pcchValueBuf) ; szPatch : LPCWSTR -> "wstr" ; szAttribute : LPCWSTR -> "wstr" ; lpValueBuf : LPWSTR optional, out -> "var" ; pcchValueBuf : DWORD* optional, in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "msi.dll" #cfunc global MsiGetPatchInfoW "MsiGetPatchInfoW" wstr, wstr, sptr, sptr ; res = MsiGetPatchInfoW(szPatch, szAttribute, varptr(lpValueBuf), varptr(pcchValueBuf)) ; szPatch : LPCWSTR -> "wstr" ; szAttribute : LPCWSTR -> "wstr" ; lpValueBuf : LPWSTR optional, out -> "sptr" ; pcchValueBuf : DWORD* optional, in/out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; DWORD MsiGetPatchInfoW(LPCWSTR szPatch, LPCWSTR szAttribute, LPWSTR lpValueBuf, DWORD* pcchValueBuf) #uselib "msi.dll" #cfunc global MsiGetPatchInfoW "MsiGetPatchInfoW" wstr, wstr, var, var ; res = MsiGetPatchInfoW(szPatch, szAttribute, lpValueBuf, pcchValueBuf) ; szPatch : LPCWSTR -> "wstr" ; szAttribute : LPCWSTR -> "wstr" ; lpValueBuf : LPWSTR optional, out -> "var" ; pcchValueBuf : DWORD* optional, in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; DWORD MsiGetPatchInfoW(LPCWSTR szPatch, LPCWSTR szAttribute, LPWSTR lpValueBuf, DWORD* pcchValueBuf) #uselib "msi.dll" #cfunc global MsiGetPatchInfoW "MsiGetPatchInfoW" wstr, wstr, intptr, intptr ; res = MsiGetPatchInfoW(szPatch, szAttribute, varptr(lpValueBuf), varptr(pcchValueBuf)) ; szPatch : LPCWSTR -> "wstr" ; szAttribute : LPCWSTR -> "wstr" ; lpValueBuf : LPWSTR optional, out -> "intptr" ; pcchValueBuf : DWORD* optional, in/out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
msi = windows.NewLazySystemDLL("msi.dll")
procMsiGetPatchInfoW = msi.NewProc("MsiGetPatchInfoW")
)
// szPatch (LPCWSTR), szAttribute (LPCWSTR), lpValueBuf (LPWSTR optional, out), pcchValueBuf (DWORD* optional, in/out)
r1, _, err := procMsiGetPatchInfoW.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(szPatch))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(szAttribute))),
uintptr(lpValueBuf),
uintptr(pcchValueBuf),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction MsiGetPatchInfoW(
szPatch: PWideChar; // LPCWSTR
szAttribute: PWideChar; // LPCWSTR
lpValueBuf: PWideChar; // LPWSTR optional, out
pcchValueBuf: Pointer // DWORD* optional, in/out
): DWORD; stdcall;
external 'msi.dll' name 'MsiGetPatchInfoW';result := DllCall("msi\MsiGetPatchInfoW"
, "WStr", szPatch ; LPCWSTR
, "WStr", szAttribute ; LPCWSTR
, "Ptr", lpValueBuf ; LPWSTR optional, out
, "Ptr", pcchValueBuf ; DWORD* optional, in/out
, "UInt") ; return: DWORD●MsiGetPatchInfoW(szPatch, szAttribute, lpValueBuf, pcchValueBuf) = DLL("msi.dll", "dword MsiGetPatchInfoW(char*, char*, char*, void*)")
# 呼び出し: MsiGetPatchInfoW(szPatch, szAttribute, lpValueBuf, pcchValueBuf)
# szPatch : LPCWSTR -> "char*"
# szAttribute : LPCWSTR -> "char*"
# lpValueBuf : LPWSTR optional, out -> "char*"
# pcchValueBuf : 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 MsiGetPatchInfoW(
szPatch: [*c]const u16, // LPCWSTR
szAttribute: [*c]const u16, // LPCWSTR
lpValueBuf: [*c]u16, // LPWSTR optional, out
pcchValueBuf: [*c]u32 // DWORD* optional, in/out
) callconv(std.os.windows.WINAPI) u32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。proc MsiGetPatchInfoW(
szPatch: WideCString, # LPCWSTR
szAttribute: WideCString, # LPCWSTR
lpValueBuf: ptr uint16, # LPWSTR optional, out
pcchValueBuf: ptr uint32 # DWORD* optional, in/out
): uint32 {.importc: "MsiGetPatchInfoW", stdcall, dynlib: "msi.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。pragma(lib, "msi");
extern(Windows)
uint MsiGetPatchInfoW(
const(wchar)* szPatch, // LPCWSTR
const(wchar)* szAttribute, // LPCWSTR
wchar* lpValueBuf, // LPWSTR optional, out
uint* pcchValueBuf // DWORD* optional, in/out
);ccall((:MsiGetPatchInfoW, "msi.dll"), stdcall, UInt32,
(Cwstring, Cwstring, Ptr{UInt16}, Ptr{UInt32}),
szPatch, szAttribute, lpValueBuf, pcchValueBuf)
# szPatch : LPCWSTR -> Cwstring
# szAttribute : LPCWSTR -> Cwstring
# lpValueBuf : LPWSTR optional, out -> Ptr{UInt16}
# pcchValueBuf : DWORD* optional, in/out -> Ptr{UInt32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。local ffi = require("ffi")
ffi.cdef[[
uint32_t MsiGetPatchInfoW(
const uint16_t* szPatch,
const uint16_t* szAttribute,
uint16_t* lpValueBuf,
uint32_t* pcchValueBuf);
]]
local msi = ffi.load("msi")
-- msi.MsiGetPatchInfoW(szPatch, szAttribute, lpValueBuf, pcchValueBuf)
-- szPatch : LPCWSTR
-- szAttribute : LPCWSTR
-- lpValueBuf : LPWSTR optional, out
-- pcchValueBuf : 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 MsiGetPatchInfoW = lib.func('__stdcall', 'MsiGetPatchInfoW', 'uint32_t', ['str16', 'str16', 'uint16_t *', 'uint32_t *']);
// MsiGetPatchInfoW(szPatch, szAttribute, lpValueBuf, pcchValueBuf)
// szPatch : LPCWSTR -> 'str16'
// szAttribute : LPCWSTR -> 'str16'
// lpValueBuf : LPWSTR optional, out -> 'uint16_t *'
// pcchValueBuf : DWORD* optional, in/out -> 'uint32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("msi.dll", {
MsiGetPatchInfoW: { parameters: ["buffer", "buffer", "buffer", "pointer"], result: "u32" },
});
// lib.symbols.MsiGetPatchInfoW(szPatch, szAttribute, lpValueBuf, pcchValueBuf)
// szPatch : LPCWSTR -> "buffer"
// szAttribute : LPCWSTR -> "buffer"
// lpValueBuf : LPWSTR optional, out -> "buffer"
// pcchValueBuf : 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 MsiGetPatchInfoW(
const uint16_t* szPatch,
const uint16_t* szAttribute,
uint16_t* lpValueBuf,
uint32_t* pcchValueBuf);
C, "msi.dll");
// $ffi->MsiGetPatchInfoW(szPatch, szAttribute, lpValueBuf, pcchValueBuf);
// szPatch : LPCWSTR
// szAttribute : LPCWSTR
// lpValueBuf : LPWSTR optional, out
// pcchValueBuf : 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 MsiGetPatchInfoW(
WString szPatch, // LPCWSTR
WString szAttribute, // LPCWSTR
char[] lpValueBuf, // LPWSTR optional, out
IntByReference pcchValueBuf // DWORD* optional, in/out
);
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。@[Link("msi")]
lib Libmsi
fun MsiGetPatchInfoW = MsiGetPatchInfoW(
szPatch : UInt16*, # LPCWSTR
szAttribute : UInt16*, # LPCWSTR
lpValueBuf : UInt16*, # LPWSTR optional, out
pcchValueBuf : 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 MsiGetPatchInfoWNative = Uint32 Function(Pointer<Utf16>, Pointer<Utf16>, Pointer<Utf16>, Pointer<Uint32>);
typedef MsiGetPatchInfoWDart = int Function(Pointer<Utf16>, Pointer<Utf16>, Pointer<Utf16>, Pointer<Uint32>);
final MsiGetPatchInfoW = DynamicLibrary.open('msi.dll')
.lookupFunction<MsiGetPatchInfoWNative, MsiGetPatchInfoWDart>('MsiGetPatchInfoW');
// szPatch : LPCWSTR -> Pointer<Utf16>
// szAttribute : LPCWSTR -> Pointer<Utf16>
// lpValueBuf : LPWSTR optional, out -> Pointer<Utf16>
// pcchValueBuf : DWORD* optional, in/out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function MsiGetPatchInfoW(
szPatch: PWideChar; // LPCWSTR
szAttribute: PWideChar; // LPCWSTR
lpValueBuf: PWideChar; // LPWSTR optional, out
pcchValueBuf: Pointer // DWORD* optional, in/out
): DWORD; stdcall;
external 'msi.dll' name 'MsiGetPatchInfoW';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "MsiGetPatchInfoW"
c_MsiGetPatchInfoW :: CWString -> CWString -> CWString -> Ptr Word32 -> IO Word32
-- szPatch : LPCWSTR -> CWString
-- szAttribute : LPCWSTR -> CWString
-- lpValueBuf : LPWSTR optional, out -> CWString
-- pcchValueBuf : DWORD* optional, in/out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let msigetpatchinfow =
foreign "MsiGetPatchInfoW"
((ptr uint16_t) @-> (ptr uint16_t) @-> (ptr uint16_t) @-> (ptr uint32_t) @-> returning uint32_t)
(* szPatch : LPCWSTR -> (ptr uint16_t) *)
(* szAttribute : LPCWSTR -> (ptr uint16_t) *)
(* lpValueBuf : LPWSTR optional, out -> (ptr uint16_t) *)
(* pcchValueBuf : 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 ("MsiGetPatchInfoW" msi-get-patch-info-w :convention :stdcall) :uint32
(sz-patch (:string :encoding :utf-16le)) ; LPCWSTR
(sz-attribute (:string :encoding :utf-16le)) ; LPCWSTR
(lp-value-buf :pointer) ; LPWSTR optional, out
(pcch-value-buf :pointer)) ; DWORD* optional, in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $MsiGetPatchInfoW = Win32::API::More->new('msi',
'DWORD MsiGetPatchInfoW(LPCWSTR szPatch, LPCWSTR szAttribute, LPWSTR lpValueBuf, LPVOID pcchValueBuf)');
# my $ret = $MsiGetPatchInfoW->Call($szPatch, $szAttribute, $lpValueBuf, $pcchValueBuf);
# szPatch : LPCWSTR -> LPCWSTR
# szAttribute : LPCWSTR -> LPCWSTR
# lpValueBuf : LPWSTR optional, out -> LPWSTR
# pcchValueBuf : DWORD* optional, in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。関連項目
文字セット違い
- f MsiGetPatchInfoA (ANSI版) — 適用済みパッチの情報を取得する(ANSI版)。
類似 API
- f MsiGetPatchInfoExW — コンテキスト指定でパッチの詳細情報を取得する(Unicode版)。