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

MsiDatabaseApplyTransformA

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

シグネチャ

// msi.dll  (ANSI / -A)
#include <windows.h>

DWORD MsiDatabaseApplyTransformA(
    MSIHANDLE hDatabase,
    LPCSTR szTransformFile,
    MSITRANSFORM_ERROR iErrorConditions
);

パラメーター

名前方向説明
hDatabaseMSIHANDLEinトランスフォームの適用先となる、MsiOpenDatabase から取得したデータベースへのハンドル。
szTransformFileLPCSTRin適用するトランスフォーム ファイルの名前を指定します。
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 関数は、データベースにトランスフォームを適用します。(ANSI)

戻り値

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  (ANSI / -A)
#include <windows.h>

DWORD MsiDatabaseApplyTransformA(
    MSIHANDLE hDatabase,
    LPCSTR szTransformFile,
    MSITRANSFORM_ERROR iErrorConditions
);
[DllImport("msi.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern uint MsiDatabaseApplyTransformA(
    uint hDatabase,   // MSIHANDLE
    [MarshalAs(UnmanagedType.LPStr)] string szTransformFile,   // LPCSTR
    int iErrorConditions   // MSITRANSFORM_ERROR
);
<DllImport("msi.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function MsiDatabaseApplyTransformA(
    hDatabase As UInteger,   ' MSIHANDLE
    <MarshalAs(UnmanagedType.LPStr)> szTransformFile As String,   ' LPCSTR
    iErrorConditions As Integer   ' MSITRANSFORM_ERROR
) As UInteger
End Function
' hDatabase : MSIHANDLE
' szTransformFile : LPCSTR
' iErrorConditions : MSITRANSFORM_ERROR
Declare PtrSafe Function MsiDatabaseApplyTransformA Lib "msi" ( _
    ByVal hDatabase As Long, _
    ByVal szTransformFile As String, _
    ByVal iErrorConditions As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

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

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

var (
	msi = windows.NewLazySystemDLL("msi.dll")
	procMsiDatabaseApplyTransformA = msi.NewProc("MsiDatabaseApplyTransformA")
)

// hDatabase (MSIHANDLE), szTransformFile (LPCSTR), iErrorConditions (MSITRANSFORM_ERROR)
r1, _, err := procMsiDatabaseApplyTransformA.Call(
	uintptr(hDatabase),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(szTransformFile))),
	uintptr(iErrorConditions),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function MsiDatabaseApplyTransformA(
  hDatabase: DWORD;   // MSIHANDLE
  szTransformFile: PAnsiChar;   // LPCSTR
  iErrorConditions: Integer   // MSITRANSFORM_ERROR
): DWORD; stdcall;
  external 'msi.dll' name 'MsiDatabaseApplyTransformA';
result := DllCall("msi\MsiDatabaseApplyTransformA"
    , "UInt", hDatabase   ; MSIHANDLE
    , "AStr", szTransformFile   ; LPCSTR
    , "Int", iErrorConditions   ; MSITRANSFORM_ERROR
    , "UInt")   ; return: DWORD
●MsiDatabaseApplyTransformA(hDatabase, szTransformFile, iErrorConditions) = DLL("msi.dll", "dword MsiDatabaseApplyTransformA(dword, char*, int)")
# 呼び出し: MsiDatabaseApplyTransformA(hDatabase, szTransformFile, iErrorConditions)
# hDatabase : MSIHANDLE -> "dword"
# szTransformFile : LPCSTR -> "char*"
# iErrorConditions : MSITRANSFORM_ERROR -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "msi" fn MsiDatabaseApplyTransformA(
    hDatabase: u32, // MSIHANDLE
    szTransformFile: [*c]const u8, // LPCSTR
    iErrorConditions: i32 // MSITRANSFORM_ERROR
) callconv(std.os.windows.WINAPI) u32;
proc MsiDatabaseApplyTransformA(
    hDatabase: uint32,  # MSIHANDLE
    szTransformFile: cstring,  # LPCSTR
    iErrorConditions: int32  # MSITRANSFORM_ERROR
): uint32 {.importc: "MsiDatabaseApplyTransformA", stdcall, dynlib: "msi.dll".}
pragma(lib, "msi");
extern(Windows)
uint MsiDatabaseApplyTransformA(
    uint hDatabase,   // MSIHANDLE
    const(char)* szTransformFile,   // LPCSTR
    int iErrorConditions   // MSITRANSFORM_ERROR
);
ccall((:MsiDatabaseApplyTransformA, "msi.dll"), stdcall, UInt32,
      (UInt32, Cstring, Int32),
      hDatabase, szTransformFile, iErrorConditions)
# hDatabase : MSIHANDLE -> UInt32
# szTransformFile : LPCSTR -> Cstring
# iErrorConditions : MSITRANSFORM_ERROR -> Int32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
uint32_t MsiDatabaseApplyTransformA(
    uint32_t hDatabase,
    const char* szTransformFile,
    int32_t iErrorConditions);
]]
local msi = ffi.load("msi")
-- msi.MsiDatabaseApplyTransformA(hDatabase, szTransformFile, iErrorConditions)
-- hDatabase : MSIHANDLE
-- szTransformFile : LPCSTR
-- iErrorConditions : MSITRANSFORM_ERROR
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('msi.dll');
const MsiDatabaseApplyTransformA = lib.func('__stdcall', 'MsiDatabaseApplyTransformA', 'uint32_t', ['uint32_t', 'str', 'int32_t']);
// MsiDatabaseApplyTransformA(hDatabase, szTransformFile, iErrorConditions)
// hDatabase : MSIHANDLE -> 'uint32_t'
// szTransformFile : LPCSTR -> 'str'
// iErrorConditions : MSITRANSFORM_ERROR -> 'int32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("msi.dll", {
  MsiDatabaseApplyTransformA: { parameters: ["u32", "buffer", "i32"], result: "u32" },
});
// lib.symbols.MsiDatabaseApplyTransformA(hDatabase, szTransformFile, iErrorConditions)
// hDatabase : MSIHANDLE -> "u32"
// szTransformFile : LPCSTR -> "buffer"
// iErrorConditions : MSITRANSFORM_ERROR -> "i32"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
uint32_t MsiDatabaseApplyTransformA(
    uint32_t hDatabase,
    const char* szTransformFile,
    int32_t iErrorConditions);
C, "msi.dll");
// $ffi->MsiDatabaseApplyTransformA(hDatabase, szTransformFile, iErrorConditions);
// hDatabase : MSIHANDLE
// szTransformFile : LPCSTR
// 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.ASCII_OPTIONS);
    int MsiDatabaseApplyTransformA(
        int hDatabase,   // MSIHANDLE
        String szTransformFile,   // LPCSTR
        int iErrorConditions   // MSITRANSFORM_ERROR
    );
}
@[Link("msi")]
lib Libmsi
  fun MsiDatabaseApplyTransformA = MsiDatabaseApplyTransformA(
    hDatabase : UInt32,   # MSIHANDLE
    szTransformFile : UInt8*,   # LPCSTR
    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 MsiDatabaseApplyTransformANative = Uint32 Function(Uint32, Pointer<Utf8>, Int32);
typedef MsiDatabaseApplyTransformADart = int Function(int, Pointer<Utf8>, int);
final MsiDatabaseApplyTransformA = DynamicLibrary.open('msi.dll')
    .lookupFunction<MsiDatabaseApplyTransformANative, MsiDatabaseApplyTransformADart>('MsiDatabaseApplyTransformA');
// hDatabase : MSIHANDLE -> Uint32
// szTransformFile : LPCSTR -> Pointer<Utf8>
// iErrorConditions : MSITRANSFORM_ERROR -> Int32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function MsiDatabaseApplyTransformA(
  hDatabase: DWORD;   // MSIHANDLE
  szTransformFile: PAnsiChar;   // LPCSTR
  iErrorConditions: Integer   // MSITRANSFORM_ERROR
): DWORD; stdcall;
  external 'msi.dll' name 'MsiDatabaseApplyTransformA';
import Foreign
import Foreign.C.Types
import Foreign.C.String

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

let msidatabaseapplytransforma =
  foreign "MsiDatabaseApplyTransformA"
    (uint32_t @-> string @-> int32_t @-> returning uint32_t)
(* hDatabase : MSIHANDLE -> uint32_t *)
(* szTransformFile : LPCSTR -> string *)
(* 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 ("MsiDatabaseApplyTransformA" msi-database-apply-transform-a :convention :stdcall) :uint32
  (h-database :uint32)   ; MSIHANDLE
  (sz-transform-file :string)   ; LPCSTR
  (i-error-conditions :int32))   ; MSITRANSFORM_ERROR
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $MsiDatabaseApplyTransformA = Win32::API::More->new('msi',
    'DWORD MsiDatabaseApplyTransformA(DWORD hDatabase, LPCSTR szTransformFile, int iErrorConditions)');
# my $ret = $MsiDatabaseApplyTransformA->Call($hDatabase, $szTransformFile, $iErrorConditions);
# hDatabase : MSIHANDLE -> DWORD
# szTransformFile : LPCSTR -> LPCSTR
# iErrorConditions : MSITRANSFORM_ERROR -> int
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

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