MsiApplyPatchW
関数シグネチャ
// msi.dll (Unicode / -W)
#include <windows.h>
DWORD MsiApplyPatchW(
LPCWSTR szPatchPackage,
LPCWSTR szInstallPackage, // optional
INSTALLTYPE eInstallType,
LPCWSTR szCommandLine // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| szPatchPackage | LPCWSTR | in | パッチパッケージへのフルパスを指定する、null 終端文字列です。 | ||||||||
| szInstallPackage | LPCWSTR | inoptional | eInstallType が INSTALLTYPE_NETWORK_IMAGE に設定されている場合、このパラメーターはパッチ適用対象となる製品へのパスを指定する null 終端文字列です。szInstallPackage が null に設定され、eInstallType が INSTALLTYPE_DEFAULT に設定されている場合、インストーラーはパッチパッケージに列挙されている適格なすべての製品にパッチを適用します。 eInstallType が INSTALLTYPE_SINGLE_INSTANCE の場合、インストーラーは szInstallPackage で指定された製品にパッチを適用します。この場合、パッチパッケージに列挙されている他の適格な製品は無視され、szInstallPackage パラメーターにはパッチを適用するインスタンスのプロダクトコードを表す null 終端文字列が含まれます。この種類のインストールでは、インストーラーが Windows Server 2003 または Windows XP 上で動作している必要があります。 | ||||||||
| eInstallType | INSTALLTYPE | in | このパラメーターは、パッチを適用するインストールの種類を指定します。
| ||||||||
| szCommandLine | LPCWSTR | inoptional | コマンドラインでのプロパティ設定を指定する、null 終端文字列です。プロパティについておよびコマンドラインでのパブリックプロパティ値の設定を参照してください。「解説」セクションも参照してください。 |
戻り値の型: DWORD
公式ドキュメント
パッチパッケージがパッチ適用対象として列挙している各製品に対して、MsiApplyPatch 関数はインストールを呼び出し、PATCH プロパティにパッチパッケージのパスを設定します。(Unicode)
戻り値
| 値 | 意味 |
|---|---|
| 関数は正常に完了しました。 | |
| パッチパッケージを開けませんでした。 | |
| パッチパッケージが無効です。 | |
| パッチパッケージがサポートされていません。 | |
|
エラーコードを参照してください。 |
| 初期化エラーが発生しました。 |
解説(Remarks)
変換、ソース、パッチのリスト区切り文字はセミコロンであるため、この文字はファイル名やパスに使用しないでください。
小規模更新またはマイナーアップグレードのパッチを適用する際は、コマンドラインで REINSTALL プロパティを設定する必要があります。このプロパティを設定しないと、パッチはシステムに登録されますがファイルを更新できません。カスタムアクションタイプ 51 を使用して REINSTALL および REINSTALLMODE プロパティを自動的に設定しないパッチの場合、REINSTALL プロパティは szCommandLine パラメーターで明示的に設定する必要があります。パッチの影響を受ける機能を列挙するように REINSTALL プロパティを設定するか、実用的な既定値として "REINSTALL=ALL" を使用してください。REINSTALLMODE プロパティの既定値は "omus" です。Windows Installer バージョン 3.0 以降では、REINSTALL プロパティはインストーラーによって構成されるため、コマンドラインで設定する必要はありません。
msi.h ヘッダーは MsiApplyPatch を、UNICODE プリプロセッサ定数の定義に基づいてこの関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして定義します。エンコーディング中立のエイリアスを、エンコーディング中立でないコードと混在して使用すると、不一致が生じてコンパイルエラーや実行時エラーを引き起こす可能性があります。詳細については、関数プロトタイプの規則を参照してください。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// msi.dll (Unicode / -W)
#include <windows.h>
DWORD MsiApplyPatchW(
LPCWSTR szPatchPackage,
LPCWSTR szInstallPackage, // optional
INSTALLTYPE eInstallType,
LPCWSTR szCommandLine // optional
);[DllImport("msi.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern uint MsiApplyPatchW(
[MarshalAs(UnmanagedType.LPWStr)] string szPatchPackage, // LPCWSTR
[MarshalAs(UnmanagedType.LPWStr)] string szInstallPackage, // LPCWSTR optional
int eInstallType, // INSTALLTYPE
[MarshalAs(UnmanagedType.LPWStr)] string szCommandLine // LPCWSTR optional
);<DllImport("msi.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function MsiApplyPatchW(
<MarshalAs(UnmanagedType.LPWStr)> szPatchPackage As String, ' LPCWSTR
<MarshalAs(UnmanagedType.LPWStr)> szInstallPackage As String, ' LPCWSTR optional
eInstallType As Integer, ' INSTALLTYPE
<MarshalAs(UnmanagedType.LPWStr)> szCommandLine As String ' LPCWSTR optional
) As UInteger
End Function' szPatchPackage : LPCWSTR
' szInstallPackage : LPCWSTR optional
' eInstallType : INSTALLTYPE
' szCommandLine : LPCWSTR optional
Declare PtrSafe Function MsiApplyPatchW Lib "msi" ( _
ByVal szPatchPackage As LongPtr, _
ByVal szInstallPackage As LongPtr, _
ByVal eInstallType As Long, _
ByVal szCommandLine 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
MsiApplyPatchW = ctypes.windll.msi.MsiApplyPatchW
MsiApplyPatchW.restype = wintypes.DWORD
MsiApplyPatchW.argtypes = [
wintypes.LPCWSTR, # szPatchPackage : LPCWSTR
wintypes.LPCWSTR, # szInstallPackage : LPCWSTR optional
ctypes.c_int, # eInstallType : INSTALLTYPE
wintypes.LPCWSTR, # szCommandLine : LPCWSTR optional
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('msi.dll')
MsiApplyPatchW = Fiddle::Function.new(
lib['MsiApplyPatchW'],
[
Fiddle::TYPE_VOIDP, # szPatchPackage : LPCWSTR
Fiddle::TYPE_VOIDP, # szInstallPackage : LPCWSTR optional
Fiddle::TYPE_INT, # eInstallType : INSTALLTYPE
Fiddle::TYPE_VOIDP, # szCommandLine : LPCWSTR optional
],
-Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "msi")]
extern "system" {
fn MsiApplyPatchW(
szPatchPackage: *const u16, // LPCWSTR
szInstallPackage: *const u16, // LPCWSTR optional
eInstallType: i32, // INSTALLTYPE
szCommandLine: *const u16 // LPCWSTR optional
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("msi.dll", CharSet = CharSet.Unicode)]
public static extern uint MsiApplyPatchW([MarshalAs(UnmanagedType.LPWStr)] string szPatchPackage, [MarshalAs(UnmanagedType.LPWStr)] string szInstallPackage, int eInstallType, [MarshalAs(UnmanagedType.LPWStr)] string szCommandLine);
"@
$api = Add-Type -MemberDefinition $sig -Name 'msi_MsiApplyPatchW' -Namespace Win32 -PassThru
# $api::MsiApplyPatchW(szPatchPackage, szInstallPackage, eInstallType, szCommandLine)#uselib "msi.dll"
#func global MsiApplyPatchW "MsiApplyPatchW" wptr, wptr, wptr, wptr
; MsiApplyPatchW szPatchPackage, szInstallPackage, eInstallType, szCommandLine ; 戻り値は stat
; szPatchPackage : LPCWSTR -> "wptr"
; szInstallPackage : LPCWSTR optional -> "wptr"
; eInstallType : INSTALLTYPE -> "wptr"
; szCommandLine : LPCWSTR optional -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "msi.dll"
#cfunc global MsiApplyPatchW "MsiApplyPatchW" wstr, wstr, int, wstr
; res = MsiApplyPatchW(szPatchPackage, szInstallPackage, eInstallType, szCommandLine)
; szPatchPackage : LPCWSTR -> "wstr"
; szInstallPackage : LPCWSTR optional -> "wstr"
; eInstallType : INSTALLTYPE -> "int"
; szCommandLine : LPCWSTR optional -> "wstr"; DWORD MsiApplyPatchW(LPCWSTR szPatchPackage, LPCWSTR szInstallPackage, INSTALLTYPE eInstallType, LPCWSTR szCommandLine)
#uselib "msi.dll"
#cfunc global MsiApplyPatchW "MsiApplyPatchW" wstr, wstr, int, wstr
; res = MsiApplyPatchW(szPatchPackage, szInstallPackage, eInstallType, szCommandLine)
; szPatchPackage : LPCWSTR -> "wstr"
; szInstallPackage : LPCWSTR optional -> "wstr"
; eInstallType : INSTALLTYPE -> "int"
; szCommandLine : LPCWSTR optional -> "wstr"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
msi = windows.NewLazySystemDLL("msi.dll")
procMsiApplyPatchW = msi.NewProc("MsiApplyPatchW")
)
// szPatchPackage (LPCWSTR), szInstallPackage (LPCWSTR optional), eInstallType (INSTALLTYPE), szCommandLine (LPCWSTR optional)
r1, _, err := procMsiApplyPatchW.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(szPatchPackage))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(szInstallPackage))),
uintptr(eInstallType),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(szCommandLine))),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction MsiApplyPatchW(
szPatchPackage: PWideChar; // LPCWSTR
szInstallPackage: PWideChar; // LPCWSTR optional
eInstallType: Integer; // INSTALLTYPE
szCommandLine: PWideChar // LPCWSTR optional
): DWORD; stdcall;
external 'msi.dll' name 'MsiApplyPatchW';result := DllCall("msi\MsiApplyPatchW"
, "WStr", szPatchPackage ; LPCWSTR
, "WStr", szInstallPackage ; LPCWSTR optional
, "Int", eInstallType ; INSTALLTYPE
, "WStr", szCommandLine ; LPCWSTR optional
, "UInt") ; return: DWORD●MsiApplyPatchW(szPatchPackage, szInstallPackage, eInstallType, szCommandLine) = DLL("msi.dll", "dword MsiApplyPatchW(char*, char*, int, char*)")
# 呼び出し: MsiApplyPatchW(szPatchPackage, szInstallPackage, eInstallType, szCommandLine)
# szPatchPackage : LPCWSTR -> "char*"
# szInstallPackage : LPCWSTR optional -> "char*"
# eInstallType : INSTALLTYPE -> "int"
# szCommandLine : LPCWSTR optional -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。const std = @import("std");
extern "msi" fn MsiApplyPatchW(
szPatchPackage: [*c]const u16, // LPCWSTR
szInstallPackage: [*c]const u16, // LPCWSTR optional
eInstallType: i32, // INSTALLTYPE
szCommandLine: [*c]const u16 // LPCWSTR optional
) callconv(std.os.windows.WINAPI) u32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。proc MsiApplyPatchW(
szPatchPackage: WideCString, # LPCWSTR
szInstallPackage: WideCString, # LPCWSTR optional
eInstallType: int32, # INSTALLTYPE
szCommandLine: WideCString # LPCWSTR optional
): uint32 {.importc: "MsiApplyPatchW", stdcall, dynlib: "msi.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。pragma(lib, "msi");
extern(Windows)
uint MsiApplyPatchW(
const(wchar)* szPatchPackage, // LPCWSTR
const(wchar)* szInstallPackage, // LPCWSTR optional
int eInstallType, // INSTALLTYPE
const(wchar)* szCommandLine // LPCWSTR optional
);ccall((:MsiApplyPatchW, "msi.dll"), stdcall, UInt32,
(Cwstring, Cwstring, Int32, Cwstring),
szPatchPackage, szInstallPackage, eInstallType, szCommandLine)
# szPatchPackage : LPCWSTR -> Cwstring
# szInstallPackage : LPCWSTR optional -> Cwstring
# eInstallType : INSTALLTYPE -> Int32
# szCommandLine : LPCWSTR optional -> Cwstring
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。local ffi = require("ffi")
ffi.cdef[[
uint32_t MsiApplyPatchW(
const uint16_t* szPatchPackage,
const uint16_t* szInstallPackage,
int32_t eInstallType,
const uint16_t* szCommandLine);
]]
local msi = ffi.load("msi")
-- msi.MsiApplyPatchW(szPatchPackage, szInstallPackage, eInstallType, szCommandLine)
-- szPatchPackage : LPCWSTR
-- szInstallPackage : LPCWSTR optional
-- eInstallType : INSTALLTYPE
-- szCommandLine : LPCWSTR optional
-- 構造体/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 MsiApplyPatchW = lib.func('__stdcall', 'MsiApplyPatchW', 'uint32_t', ['str16', 'str16', 'int32_t', 'str16']);
// MsiApplyPatchW(szPatchPackage, szInstallPackage, eInstallType, szCommandLine)
// szPatchPackage : LPCWSTR -> 'str16'
// szInstallPackage : LPCWSTR optional -> 'str16'
// eInstallType : INSTALLTYPE -> 'int32_t'
// szCommandLine : LPCWSTR optional -> 'str16'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("msi.dll", {
MsiApplyPatchW: { parameters: ["buffer", "buffer", "i32", "buffer"], result: "u32" },
});
// lib.symbols.MsiApplyPatchW(szPatchPackage, szInstallPackage, eInstallType, szCommandLine)
// szPatchPackage : LPCWSTR -> "buffer"
// szInstallPackage : LPCWSTR optional -> "buffer"
// eInstallType : INSTALLTYPE -> "i32"
// szCommandLine : LPCWSTR optional -> "buffer"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t MsiApplyPatchW(
const uint16_t* szPatchPackage,
const uint16_t* szInstallPackage,
int32_t eInstallType,
const uint16_t* szCommandLine);
C, "msi.dll");
// $ffi->MsiApplyPatchW(szPatchPackage, szInstallPackage, eInstallType, szCommandLine);
// szPatchPackage : LPCWSTR
// szInstallPackage : LPCWSTR optional
// eInstallType : INSTALLTYPE
// szCommandLine : LPCWSTR optional
// 構造体/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 MsiApplyPatchW(
WString szPatchPackage, // LPCWSTR
WString szInstallPackage, // LPCWSTR optional
int eInstallType, // INSTALLTYPE
WString szCommandLine // LPCWSTR optional
);
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。@[Link("msi")]
lib Libmsi
fun MsiApplyPatchW = MsiApplyPatchW(
szPatchPackage : UInt16*, # LPCWSTR
szInstallPackage : UInt16*, # LPCWSTR optional
eInstallType : Int32, # INSTALLTYPE
szCommandLine : UInt16* # LPCWSTR optional
) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef MsiApplyPatchWNative = Uint32 Function(Pointer<Utf16>, Pointer<Utf16>, Int32, Pointer<Utf16>);
typedef MsiApplyPatchWDart = int Function(Pointer<Utf16>, Pointer<Utf16>, int, Pointer<Utf16>);
final MsiApplyPatchW = DynamicLibrary.open('msi.dll')
.lookupFunction<MsiApplyPatchWNative, MsiApplyPatchWDart>('MsiApplyPatchW');
// szPatchPackage : LPCWSTR -> Pointer<Utf16>
// szInstallPackage : LPCWSTR optional -> Pointer<Utf16>
// eInstallType : INSTALLTYPE -> Int32
// szCommandLine : LPCWSTR optional -> Pointer<Utf16>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function MsiApplyPatchW(
szPatchPackage: PWideChar; // LPCWSTR
szInstallPackage: PWideChar; // LPCWSTR optional
eInstallType: Integer; // INSTALLTYPE
szCommandLine: PWideChar // LPCWSTR optional
): DWORD; stdcall;
external 'msi.dll' name 'MsiApplyPatchW';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "MsiApplyPatchW"
c_MsiApplyPatchW :: CWString -> CWString -> Int32 -> CWString -> IO Word32
-- szPatchPackage : LPCWSTR -> CWString
-- szInstallPackage : LPCWSTR optional -> CWString
-- eInstallType : INSTALLTYPE -> Int32
-- szCommandLine : LPCWSTR optional -> CWString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let msiapplypatchw =
foreign "MsiApplyPatchW"
((ptr uint16_t) @-> (ptr uint16_t) @-> int32_t @-> (ptr uint16_t) @-> returning uint32_t)
(* szPatchPackage : LPCWSTR -> (ptr uint16_t) *)
(* szInstallPackage : LPCWSTR optional -> (ptr uint16_t) *)
(* eInstallType : INSTALLTYPE -> int32_t *)
(* szCommandLine : LPCWSTR optional -> (ptr uint16_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library msi (t "msi.dll"))
(cffi:use-foreign-library msi)
(cffi:defcfun ("MsiApplyPatchW" msi-apply-patch-w :convention :stdcall) :uint32
(sz-patch-package (:string :encoding :utf-16le)) ; LPCWSTR
(sz-install-package (:string :encoding :utf-16le)) ; LPCWSTR optional
(e-install-type :int32) ; INSTALLTYPE
(sz-command-line (:string :encoding :utf-16le))) ; LPCWSTR optional
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $MsiApplyPatchW = Win32::API::More->new('msi',
'DWORD MsiApplyPatchW(LPCWSTR szPatchPackage, LPCWSTR szInstallPackage, int eInstallType, LPCWSTR szCommandLine)');
# my $ret = $MsiApplyPatchW->Call($szPatchPackage, $szInstallPackage, $eInstallType, $szCommandLine);
# szPatchPackage : LPCWSTR -> LPCWSTR
# szInstallPackage : LPCWSTR optional -> LPCWSTR
# eInstallType : INSTALLTYPE -> int
# szCommandLine : LPCWSTR optional -> LPCWSTR
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。関連項目
- f MsiApplyPatchA (ANSI版) — 製品にパッチパッケージを適用する(ANSI版)。