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

MsiDatabaseApplyTransformW

関数
データベースにトランスフォームを適用して変更を反映する。
DLLmsi.dll文字セットUnicode (-W)呼出規約winapi対応OSwindows8.0

シグネチャ

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

DWORD MsiDatabaseApplyTransformW(
    MSIHANDLE hDatabase,
    LPCWSTR szTransformFile,
    MSITRANSFORM_ERROR iErrorConditions
);

パラメーター

名前方向説明
hDatabaseMSIHANDLEinトランスフォームの適用先となるデータベースのハンドル。MsiOpenDatabase から取得します。
szTransformFileLPCWSTRin適用するトランスフォームファイルの名前を指定します。
iErrorConditionsMSITRANSFORM_ERRORin

抑制すべきエラー条件。このパラメーターはビットフィールドであり、次のビットを含めることができます。

エラー条件 意味
MSITRANSFORM_ERROR_ADDEXISTINGROW
0x0001
既に存在する行の追加。
MSITRANSFORM_ERROR_DELMISSINGROW
0x0002
存在しない行の削除。
MSITRANSFORM_ERROR_ADDEXISTINGTABLE
0x0004
既に存在するテーブルの追加。
MSITRANSFORM_ERROR_DELMISSINGTABLE
0x0008
存在しないテーブルの削除。
MSITRANSFORM_ERROR_UPDATEMISSINGROW
0x0010
存在しない行の更新。
MSITRANSFORM_ERROR_CHANGECODEPAGE
0x0020
トランスフォームとデータベースのコードページが一致せず、いずれもニュートラルなコードページを持たない。
MSITRANSFORM_ERROR_VIEWTRANSFORM
0x0100
一時的な _TransformView テーブルを作成する。

戻り値の型: DWORD

公式ドキュメント

MsiDatabaseApplyTransform 関数は、トランスフォームをデータベースに適用します。(Unicode)

戻り値

MsiDatabaseApplyTransform 関数は、次のいずれかの値を返します。

解説(Remarks)

MsiDatabaseApplyTransform 関数は、テーブルのトランスフォームを必要になるまで遅延します。追加または削除されるテーブルは即座に処理されます。ただし、既存のテーブルへの変更は、テーブルが読み込まれるかデータベースがコミットされるまで遅延されます。

テーブルが既に読み込まれてストレージに保存されている状態で MsiDatabaseApplyTransform を呼び出すと、エラーが発生します。

トランスフォーム、ソース、およびパッチのリスト区切り文字はセミコロンであるため、この文字をファイル名やパスに使用しないでください。

この関数はカスタムアクションから呼び出すことはできません。カスタムアクションからこの関数を呼び出すと、関数は失敗します。

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

メモ

msiquery.h ヘッダーは MsiDatabaseApplyTransform をエイリアスとして定義しており、UNICODE プリプロセッサ定数の定義に基づいて、この関数の ANSI 版または Unicode 版を自動的に選択します。エンコーディングに依存しないエイリアスの使用と、エンコーディングに依存しないコードではない記述とを混在させると、不一致が生じてコンパイルエラーや実行時エラーの原因となる可能性があります。詳細については、関数プロトタイプの規則を参照してください。

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

MsiDatabaseApplyTransformW = ctypes.windll.msi.MsiDatabaseApplyTransformW
MsiDatabaseApplyTransformW.restype = wintypes.DWORD
MsiDatabaseApplyTransformW.argtypes = [
    wintypes.DWORD,  # hDatabase : MSIHANDLE
    wintypes.LPCWSTR,  # szTransformFile : LPCWSTR
    ctypes.c_int,  # iErrorConditions : MSITRANSFORM_ERROR
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('msi.dll')
MsiDatabaseApplyTransformW = Fiddle::Function.new(
  lib['MsiDatabaseApplyTransformW'],
  [
    -Fiddle::TYPE_INT,  # hDatabase : MSIHANDLE
    Fiddle::TYPE_VOIDP,  # szTransformFile : LPCWSTR
    Fiddle::TYPE_INT,  # iErrorConditions : MSITRANSFORM_ERROR
  ],
  -Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "msi")]
extern "system" {
    fn MsiDatabaseApplyTransformW(
        hDatabase: u32,  // MSIHANDLE
        szTransformFile: *const u16,  // LPCWSTR
        iErrorConditions: i32  // MSITRANSFORM_ERROR
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("msi.dll", CharSet = CharSet.Unicode)]
public static extern uint MsiDatabaseApplyTransformW(uint hDatabase, [MarshalAs(UnmanagedType.LPWStr)] string szTransformFile, int iErrorConditions);
"@
$api = Add-Type -MemberDefinition $sig -Name 'msi_MsiDatabaseApplyTransformW' -Namespace Win32 -PassThru
# $api::MsiDatabaseApplyTransformW(hDatabase, szTransformFile, iErrorConditions)
#uselib "msi.dll"
#func global MsiDatabaseApplyTransformW "MsiDatabaseApplyTransformW" wptr, wptr, wptr
; MsiDatabaseApplyTransformW hDatabase, szTransformFile, iErrorConditions   ; 戻り値は stat
; hDatabase : MSIHANDLE -> "wptr"
; szTransformFile : LPCWSTR -> "wptr"
; iErrorConditions : MSITRANSFORM_ERROR -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "msi.dll"
#cfunc global MsiDatabaseApplyTransformW "MsiDatabaseApplyTransformW" int, wstr, int
; res = MsiDatabaseApplyTransformW(hDatabase, szTransformFile, iErrorConditions)
; hDatabase : MSIHANDLE -> "int"
; szTransformFile : LPCWSTR -> "wstr"
; iErrorConditions : MSITRANSFORM_ERROR -> "int"
; DWORD MsiDatabaseApplyTransformW(MSIHANDLE hDatabase, LPCWSTR szTransformFile, MSITRANSFORM_ERROR iErrorConditions)
#uselib "msi.dll"
#cfunc global MsiDatabaseApplyTransformW "MsiDatabaseApplyTransformW" int, wstr, int
; res = MsiDatabaseApplyTransformW(hDatabase, szTransformFile, iErrorConditions)
; hDatabase : MSIHANDLE -> "int"
; szTransformFile : LPCWSTR -> "wstr"
; iErrorConditions : MSITRANSFORM_ERROR -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	msi = windows.NewLazySystemDLL("msi.dll")
	procMsiDatabaseApplyTransformW = msi.NewProc("MsiDatabaseApplyTransformW")
)

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

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

typedef MsiDatabaseApplyTransformWNative = Uint32 Function(Uint32, Pointer<Utf16>, Int32);
typedef MsiDatabaseApplyTransformWDart = int Function(int, Pointer<Utf16>, int);
final MsiDatabaseApplyTransformW = DynamicLibrary.open('msi.dll')
    .lookupFunction<MsiDatabaseApplyTransformWNative, MsiDatabaseApplyTransformWDart>('MsiDatabaseApplyTransformW');
// hDatabase : MSIHANDLE -> Uint32
// szTransformFile : LPCWSTR -> Pointer<Utf16>
// iErrorConditions : MSITRANSFORM_ERROR -> Int32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function MsiDatabaseApplyTransformW(
  hDatabase: DWORD;   // MSIHANDLE
  szTransformFile: PWideChar;   // LPCWSTR
  iErrorConditions: Integer   // MSITRANSFORM_ERROR
): DWORD; stdcall;
  external 'msi.dll' name 'MsiDatabaseApplyTransformW';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "MsiDatabaseApplyTransformW"
  c_MsiDatabaseApplyTransformW :: Word32 -> CWString -> Int32 -> IO Word32
-- hDatabase : MSIHANDLE -> Word32
-- szTransformFile : LPCWSTR -> CWString
-- iErrorConditions : MSITRANSFORM_ERROR -> Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let msidatabaseapplytransformw =
  foreign "MsiDatabaseApplyTransformW"
    (uint32_t @-> (ptr uint16_t) @-> int32_t @-> returning uint32_t)
(* hDatabase : MSIHANDLE -> uint32_t *)
(* szTransformFile : LPCWSTR -> (ptr uint16_t) *)
(* iErrorConditions : MSITRANSFORM_ERROR -> int32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library msi (t "msi.dll"))
(cffi:use-foreign-library msi)

(cffi:defcfun ("MsiDatabaseApplyTransformW" msi-database-apply-transform-w :convention :stdcall) :uint32
  (h-database :uint32)   ; MSIHANDLE
  (sz-transform-file (:string :encoding :utf-16le))   ; LPCWSTR
  (i-error-conditions :int32))   ; MSITRANSFORM_ERROR
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $MsiDatabaseApplyTransformW = Win32::API::More->new('msi',
    'DWORD MsiDatabaseApplyTransformW(DWORD hDatabase, LPCWSTR szTransformFile, int iErrorConditions)');
# my $ret = $MsiDatabaseApplyTransformW->Call($hDatabase, $szTransformFile, $iErrorConditions);
# hDatabase : MSIHANDLE -> DWORD
# szTransformFile : LPCWSTR -> LPCWSTR
# iErrorConditions : MSITRANSFORM_ERROR -> int
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。

関連項目

文字セット違い
使用する型