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

MsiGetPatchFileListW

関数
パッチパッケージが変更するファイルの一覧をレコードとして取得する。
DLLmsi.dll文字セットUnicode (-W)呼出規約winapi対応OSwindows8.0

シグネチャ

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

DWORD MsiGetPatchFileListW(
    LPCWSTR szProductCode,
    LPCWSTR szPatchPackages,
    DWORD* pcFiles,
    MSIHANDLE** pphFileRecords
);

パラメーター

名前方向説明
szProductCodeLPCWSTRinパッチの対象となる製品の ProductCode(GUID)を含む、null で終わる文字列値です。このパラメーターを NULL にすることはできません。
szPatchPackagesLPCWSTRinWindows Installer パッチ(.msp ファイル)のリストを含む、null で終わる文字列値です。各パッチは、パッチパッケージへのフルパスで指定できます。リスト内のパッチはセミコロンで区切ります。少なくとも 1 つのパッチを指定する必要があります。
pcFilesDWORD*outszPatchList で指定されたパッチのリストによって、このシステム上で更新されるファイルの数を受け取る場所へのポインターです。このパラメーターは必須です。
pphFileRecordsMSIHANDLE**outレコードの配列へのポインターを受け取る場所へのポインターです。各レコードの最初のフィールド(インデックス 0)には、szPatchList 内のパッチのリストをこのコンピューターに適用したときに更新可能となるファイルのフルパスが格納されます。このパラメーターは必須です。

戻り値の型: DWORD

公式ドキュメント

MsiGetPatchFileList 関数は、セミコロンで区切られた .msp ファイルのリストを受け取り、それらのパッチによって更新可能なファイルのリストを取得します。(Unicode)

戻り値

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

意味
ERROR_SUCCESS
関数は正常に完了しました。
ERROR_INVALID_PARAMETER
無効なパラメーターが関数に渡されました。
ERROR_FUNCTION_FAILED
関数は失敗しました。

解説(Remarks)

たとえば、szPatchList には次のような値を指定できます: "c:\sus\download\cache\Office\sp1.msp; c:\sus\download\cache\Office\QFE1.msp; c:\sus\download\cache\Office\QFEn.msp"。

この関数は呼び出し元のコンテキストで実行されます。製品コードは、ユーザー単位の非管理対象コンテキスト、ユーザー単位の管理対象コンテキスト、マシンコンテキストの順に検索されます。

この関数によって返される MSIHANDLE オブジェクトは、すべて MsiCloseHandle 関数を呼び出して閉じる必要があります。

関数が失敗した場合は、MsiGetLastErrorRecord 関数を使用して拡張エラー情報を取得できます。

MsiGetPatchFileList 関数の使用方法の詳細については、Listing the Files that can be Updated を参照してください。

メモ

msi.h ヘッダーは、UNICODE プリプロセッサ定数の定義に基づいて、この関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして MsiGetPatchFileList を定義します。エンコーディング非依存のエイリアスを、エンコーディング非依存ではないコードと混在させると、コンパイルエラーや実行時エラーを引き起こす不整合が生じる可能性があります。詳細については、Conventions for Function Prototypes を参照してください。

出典・ライセンス: 上記「公式ドキュメント」の内容は 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 MsiGetPatchFileListW(
    LPCWSTR szProductCode,
    LPCWSTR szPatchPackages,
    DWORD* pcFiles,
    MSIHANDLE** pphFileRecords
);
[DllImport("msi.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern uint MsiGetPatchFileListW(
    [MarshalAs(UnmanagedType.LPWStr)] string szProductCode,   // LPCWSTR
    [MarshalAs(UnmanagedType.LPWStr)] string szPatchPackages,   // LPCWSTR
    out uint pcFiles,   // DWORD* out
    IntPtr pphFileRecords   // MSIHANDLE** out
);
<DllImport("msi.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function MsiGetPatchFileListW(
    <MarshalAs(UnmanagedType.LPWStr)> szProductCode As String,   ' LPCWSTR
    <MarshalAs(UnmanagedType.LPWStr)> szPatchPackages As String,   ' LPCWSTR
    <Out> ByRef pcFiles As UInteger,   ' DWORD* out
    pphFileRecords As IntPtr   ' MSIHANDLE** out
) As UInteger
End Function
' szProductCode : LPCWSTR
' szPatchPackages : LPCWSTR
' pcFiles : DWORD* out
' pphFileRecords : MSIHANDLE** out
Declare PtrSafe Function MsiGetPatchFileListW Lib "msi" ( _
    ByVal szProductCode As LongPtr, _
    ByVal szPatchPackages As LongPtr, _
    ByRef pcFiles As Long, _
    ByVal pphFileRecords 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

MsiGetPatchFileListW = ctypes.windll.msi.MsiGetPatchFileListW
MsiGetPatchFileListW.restype = wintypes.DWORD
MsiGetPatchFileListW.argtypes = [
    wintypes.LPCWSTR,  # szProductCode : LPCWSTR
    wintypes.LPCWSTR,  # szPatchPackages : LPCWSTR
    ctypes.POINTER(wintypes.DWORD),  # pcFiles : DWORD* out
    ctypes.c_void_p,  # pphFileRecords : MSIHANDLE** out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('msi.dll')
MsiGetPatchFileListW = Fiddle::Function.new(
  lib['MsiGetPatchFileListW'],
  [
    Fiddle::TYPE_VOIDP,  # szProductCode : LPCWSTR
    Fiddle::TYPE_VOIDP,  # szPatchPackages : LPCWSTR
    Fiddle::TYPE_VOIDP,  # pcFiles : DWORD* out
    Fiddle::TYPE_VOIDP,  # pphFileRecords : MSIHANDLE** out
  ],
  -Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "msi")]
extern "system" {
    fn MsiGetPatchFileListW(
        szProductCode: *const u16,  // LPCWSTR
        szPatchPackages: *const u16,  // LPCWSTR
        pcFiles: *mut u32,  // DWORD* out
        pphFileRecords: *mut *mut u32  // MSIHANDLE** out
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("msi.dll", CharSet = CharSet.Unicode)]
public static extern uint MsiGetPatchFileListW([MarshalAs(UnmanagedType.LPWStr)] string szProductCode, [MarshalAs(UnmanagedType.LPWStr)] string szPatchPackages, out uint pcFiles, IntPtr pphFileRecords);
"@
$api = Add-Type -MemberDefinition $sig -Name 'msi_MsiGetPatchFileListW' -Namespace Win32 -PassThru
# $api::MsiGetPatchFileListW(szProductCode, szPatchPackages, pcFiles, pphFileRecords)
#uselib "msi.dll"
#func global MsiGetPatchFileListW "MsiGetPatchFileListW" wptr, wptr, wptr, wptr
; MsiGetPatchFileListW szProductCode, szPatchPackages, varptr(pcFiles), varptr(pphFileRecords)   ; 戻り値は stat
; szProductCode : LPCWSTR -> "wptr"
; szPatchPackages : LPCWSTR -> "wptr"
; pcFiles : DWORD* out -> "wptr"
; pphFileRecords : MSIHANDLE** out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "msi.dll"
#cfunc global MsiGetPatchFileListW "MsiGetPatchFileListW" wstr, wstr, var, var
; res = MsiGetPatchFileListW(szProductCode, szPatchPackages, pcFiles, pphFileRecords)
; szProductCode : LPCWSTR -> "wstr"
; szPatchPackages : LPCWSTR -> "wstr"
; pcFiles : DWORD* out -> "var"
; pphFileRecords : MSIHANDLE** out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; DWORD MsiGetPatchFileListW(LPCWSTR szProductCode, LPCWSTR szPatchPackages, DWORD* pcFiles, MSIHANDLE** pphFileRecords)
#uselib "msi.dll"
#cfunc global MsiGetPatchFileListW "MsiGetPatchFileListW" wstr, wstr, var, var
; res = MsiGetPatchFileListW(szProductCode, szPatchPackages, pcFiles, pphFileRecords)
; szProductCode : LPCWSTR -> "wstr"
; szPatchPackages : LPCWSTR -> "wstr"
; pcFiles : DWORD* out -> "var"
; pphFileRecords : MSIHANDLE** out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	msi = windows.NewLazySystemDLL("msi.dll")
	procMsiGetPatchFileListW = msi.NewProc("MsiGetPatchFileListW")
)

// szProductCode (LPCWSTR), szPatchPackages (LPCWSTR), pcFiles (DWORD* out), pphFileRecords (MSIHANDLE** out)
r1, _, err := procMsiGetPatchFileListW.Call(
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(szProductCode))),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(szPatchPackages))),
	uintptr(pcFiles),
	uintptr(pphFileRecords),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function MsiGetPatchFileListW(
  szProductCode: PWideChar;   // LPCWSTR
  szPatchPackages: PWideChar;   // LPCWSTR
  pcFiles: Pointer;   // DWORD* out
  pphFileRecords: Pointer   // MSIHANDLE** out
): DWORD; stdcall;
  external 'msi.dll' name 'MsiGetPatchFileListW';
result := DllCall("msi\MsiGetPatchFileListW"
    , "WStr", szProductCode   ; LPCWSTR
    , "WStr", szPatchPackages   ; LPCWSTR
    , "Ptr", pcFiles   ; DWORD* out
    , "Ptr", pphFileRecords   ; MSIHANDLE** out
    , "UInt")   ; return: DWORD
●MsiGetPatchFileListW(szProductCode, szPatchPackages, pcFiles, pphFileRecords) = DLL("msi.dll", "dword MsiGetPatchFileListW(char*, char*, void*, void*)")
# 呼び出し: MsiGetPatchFileListW(szProductCode, szPatchPackages, pcFiles, pphFileRecords)
# szProductCode : LPCWSTR -> "char*"
# szPatchPackages : LPCWSTR -> "char*"
# pcFiles : DWORD* out -> "void*"
# pphFileRecords : MSIHANDLE** out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。
const std = @import("std");

extern "msi" fn MsiGetPatchFileListW(
    szProductCode: [*c]const u16, // LPCWSTR
    szPatchPackages: [*c]const u16, // LPCWSTR
    pcFiles: [*c]u32, // DWORD* out
    pphFileRecords: [*c][*c]u32 // MSIHANDLE** out
) callconv(std.os.windows.WINAPI) u32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。
proc MsiGetPatchFileListW(
    szProductCode: WideCString,  # LPCWSTR
    szPatchPackages: WideCString,  # LPCWSTR
    pcFiles: ptr uint32,  # DWORD* out
    pphFileRecords: ptr uint32  # MSIHANDLE** out
): uint32 {.importc: "MsiGetPatchFileListW", stdcall, dynlib: "msi.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。
pragma(lib, "msi");
extern(Windows)
uint MsiGetPatchFileListW(
    const(wchar)* szProductCode,   // LPCWSTR
    const(wchar)* szPatchPackages,   // LPCWSTR
    uint* pcFiles,   // DWORD* out
    uint** pphFileRecords   // MSIHANDLE** out
);
ccall((:MsiGetPatchFileListW, "msi.dll"), stdcall, UInt32,
      (Cwstring, Cwstring, Ptr{UInt32}, Ptr{UInt32}),
      szProductCode, szPatchPackages, pcFiles, pphFileRecords)
# szProductCode : LPCWSTR -> Cwstring
# szPatchPackages : LPCWSTR -> Cwstring
# pcFiles : DWORD* out -> Ptr{UInt32}
# pphFileRecords : MSIHANDLE** out -> Ptr{UInt32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。
local ffi = require("ffi")
ffi.cdef[[
uint32_t MsiGetPatchFileListW(
    const uint16_t* szProductCode,
    const uint16_t* szPatchPackages,
    uint32_t* pcFiles,
    uint32_t** pphFileRecords);
]]
local msi = ffi.load("msi")
-- msi.MsiGetPatchFileListW(szProductCode, szPatchPackages, pcFiles, pphFileRecords)
-- szProductCode : LPCWSTR
-- szPatchPackages : LPCWSTR
-- pcFiles : DWORD* out
-- pphFileRecords : MSIHANDLE** 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 MsiGetPatchFileListW = lib.func('__stdcall', 'MsiGetPatchFileListW', 'uint32_t', ['str16', 'str16', 'uint32_t *', 'uint32_t *']);
// MsiGetPatchFileListW(szProductCode, szPatchPackages, pcFiles, pphFileRecords)
// szProductCode : LPCWSTR -> 'str16'
// szPatchPackages : LPCWSTR -> 'str16'
// pcFiles : DWORD* out -> 'uint32_t *'
// pphFileRecords : MSIHANDLE** out -> 'uint32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("msi.dll", {
  MsiGetPatchFileListW: { parameters: ["buffer", "buffer", "pointer", "pointer"], result: "u32" },
});
// lib.symbols.MsiGetPatchFileListW(szProductCode, szPatchPackages, pcFiles, pphFileRecords)
// szProductCode : LPCWSTR -> "buffer"
// szPatchPackages : LPCWSTR -> "buffer"
// pcFiles : DWORD* out -> "pointer"
// pphFileRecords : MSIHANDLE** out -> "pointer"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
uint32_t MsiGetPatchFileListW(
    const uint16_t* szProductCode,
    const uint16_t* szPatchPackages,
    uint32_t* pcFiles,
    uint32_t** pphFileRecords);
C, "msi.dll");
// $ffi->MsiGetPatchFileListW(szProductCode, szPatchPackages, pcFiles, pphFileRecords);
// szProductCode : LPCWSTR
// szPatchPackages : LPCWSTR
// pcFiles : DWORD* out
// pphFileRecords : MSIHANDLE** 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 MsiGetPatchFileListW(
        WString szProductCode,   // LPCWSTR
        WString szPatchPackages,   // LPCWSTR
        IntByReference pcFiles,   // DWORD* out
        Pointer pphFileRecords   // MSIHANDLE** out
    );
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。
@[Link("msi")]
lib Libmsi
  fun MsiGetPatchFileListW = MsiGetPatchFileListW(
    szProductCode : UInt16*,   # LPCWSTR
    szPatchPackages : UInt16*,   # LPCWSTR
    pcFiles : UInt32*,   # DWORD* out
    pphFileRecords : UInt32**   # MSIHANDLE** out
  ) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef MsiGetPatchFileListWNative = Uint32 Function(Pointer<Utf16>, Pointer<Utf16>, Pointer<Uint32>, Pointer<Uint32>);
typedef MsiGetPatchFileListWDart = int Function(Pointer<Utf16>, Pointer<Utf16>, Pointer<Uint32>, Pointer<Uint32>);
final MsiGetPatchFileListW = DynamicLibrary.open('msi.dll')
    .lookupFunction<MsiGetPatchFileListWNative, MsiGetPatchFileListWDart>('MsiGetPatchFileListW');
// szProductCode : LPCWSTR -> Pointer<Utf16>
// szPatchPackages : LPCWSTR -> Pointer<Utf16>
// pcFiles : DWORD* out -> Pointer<Uint32>
// pphFileRecords : MSIHANDLE** out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function MsiGetPatchFileListW(
  szProductCode: PWideChar;   // LPCWSTR
  szPatchPackages: PWideChar;   // LPCWSTR
  pcFiles: Pointer;   // DWORD* out
  pphFileRecords: Pointer   // MSIHANDLE** out
): DWORD; stdcall;
  external 'msi.dll' name 'MsiGetPatchFileListW';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "MsiGetPatchFileListW"
  c_MsiGetPatchFileListW :: CWString -> CWString -> Ptr Word32 -> Ptr Word32 -> IO Word32
-- szProductCode : LPCWSTR -> CWString
-- szPatchPackages : LPCWSTR -> CWString
-- pcFiles : DWORD* out -> Ptr Word32
-- pphFileRecords : MSIHANDLE** out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let msigetpatchfilelistw =
  foreign "MsiGetPatchFileListW"
    ((ptr uint16_t) @-> (ptr uint16_t) @-> (ptr uint32_t) @-> (ptr uint32_t) @-> returning uint32_t)
(* szProductCode : LPCWSTR -> (ptr uint16_t) *)
(* szPatchPackages : LPCWSTR -> (ptr uint16_t) *)
(* pcFiles : DWORD* out -> (ptr uint32_t) *)
(* pphFileRecords : MSIHANDLE** 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 ("MsiGetPatchFileListW" msi-get-patch-file-list-w :convention :stdcall) :uint32
  (sz-product-code (:string :encoding :utf-16le))   ; LPCWSTR
  (sz-patch-packages (:string :encoding :utf-16le))   ; LPCWSTR
  (pc-files :pointer)   ; DWORD* out
  (pph-file-records :pointer))   ; MSIHANDLE** out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $MsiGetPatchFileListW = Win32::API::More->new('msi',
    'DWORD MsiGetPatchFileListW(LPCWSTR szProductCode, LPCWSTR szPatchPackages, LPVOID pcFiles, LPVOID pphFileRecords)');
# my $ret = $MsiGetPatchFileListW->Call($szProductCode, $szPatchPackages, $pcFiles, $pphFileRecords);
# szProductCode : LPCWSTR -> LPCWSTR
# szPatchPackages : LPCWSTR -> LPCWSTR
# pcFiles : DWORD* out -> LPVOID
# pphFileRecords : MSIHANDLE** out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。

関連項目

文字セット違い