ホーム › System.ApplicationInstallationAndServicing › MsiDatabaseExportW
MsiDatabaseExportW
関数データベースの指定テーブルをテキストアーカイブにエクスポートする。
シグネチャ
// msi.dll (Unicode / -W)
#include <windows.h>
DWORD MsiDatabaseExportW(
MSIHANDLE hDatabase,
LPCWSTR szTableName,
LPCWSTR szFolderPath,
LPCWSTR szFileName
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hDatabase | MSIHANDLE | in | MsiOpenDatabase から取得したデータベースのハンドル。 |
| szTableName | LPCWSTR | in | エクスポートするテーブルの名前。 |
| szFolderPath | LPCWSTR | in | アーカイブファイルが格納されるフォルダーの名前。 |
| szFileName | LPCWSTR | in | エクスポートされるテーブルアーカイブファイルの名前。 |
戻り値の型: DWORD
公式ドキュメント
MsiDatabaseExport 関数は、開いているデータベースから Microsoft Installer のテーブルをテキストアーカイブファイルにエクスポートします。(Unicode)
戻り値
MsiDatabaseExport 関数は、次のいずれかの値を返します。
| 戻り値 | 説明 |
|---|---|
| 無効なパスが関数に渡されました。 | |
| 関数が失敗しました。 | |
| 無効または非アクティブなハンドルが指定されました。 | |
| 無効なパラメーターが関数に渡されました。 | |
| 関数が成功しました。 |
解説(Remarks)
テーブルにストリームが含まれている場合、 MsiDatabaseExport は各ストリームを個別のファイルにエクスポートします。
詳細については、 MsiDatabaseImport を参照してください。
この関数はカスタムアクションから呼び出すことはできません。カスタムアクションからこの関数を呼び出すと、関数は失敗します。
関数が失敗した場合は、MsiGetLastErrorRecord を使用して拡張エラー情報を取得できます。
メモ
msiquery.h ヘッダーは、UNICODE プリプロセッサ定数の定義に基づいて、この関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして MsiDatabaseExport を定義します。エンコーディング非依存のエイリアスの使用と、エンコーディング非依存ではないコードを混在させると、不一致が生じ、コンパイルエラーや実行時エラーの原因となることがあります。詳細については、Conventions for Function Prototypes を参照してください。
出典・ライセンス: 上記「公式ドキュメント」の内容は 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 MsiDatabaseExportW(
MSIHANDLE hDatabase,
LPCWSTR szTableName,
LPCWSTR szFolderPath,
LPCWSTR szFileName
);[DllImport("msi.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern uint MsiDatabaseExportW(
uint hDatabase, // MSIHANDLE
[MarshalAs(UnmanagedType.LPWStr)] string szTableName, // LPCWSTR
[MarshalAs(UnmanagedType.LPWStr)] string szFolderPath, // LPCWSTR
[MarshalAs(UnmanagedType.LPWStr)] string szFileName // LPCWSTR
);<DllImport("msi.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function MsiDatabaseExportW(
hDatabase As UInteger, ' MSIHANDLE
<MarshalAs(UnmanagedType.LPWStr)> szTableName As String, ' LPCWSTR
<MarshalAs(UnmanagedType.LPWStr)> szFolderPath As String, ' LPCWSTR
<MarshalAs(UnmanagedType.LPWStr)> szFileName As String ' LPCWSTR
) As UInteger
End Function' hDatabase : MSIHANDLE
' szTableName : LPCWSTR
' szFolderPath : LPCWSTR
' szFileName : LPCWSTR
Declare PtrSafe Function MsiDatabaseExportW Lib "msi" ( _
ByVal hDatabase As Long, _
ByVal szTableName As LongPtr, _
ByVal szFolderPath As LongPtr, _
ByVal szFileName 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
MsiDatabaseExportW = ctypes.windll.msi.MsiDatabaseExportW
MsiDatabaseExportW.restype = wintypes.DWORD
MsiDatabaseExportW.argtypes = [
wintypes.DWORD, # hDatabase : MSIHANDLE
wintypes.LPCWSTR, # szTableName : LPCWSTR
wintypes.LPCWSTR, # szFolderPath : LPCWSTR
wintypes.LPCWSTR, # szFileName : LPCWSTR
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('msi.dll')
MsiDatabaseExportW = Fiddle::Function.new(
lib['MsiDatabaseExportW'],
[
-Fiddle::TYPE_INT, # hDatabase : MSIHANDLE
Fiddle::TYPE_VOIDP, # szTableName : LPCWSTR
Fiddle::TYPE_VOIDP, # szFolderPath : LPCWSTR
Fiddle::TYPE_VOIDP, # szFileName : LPCWSTR
],
-Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "msi")]
extern "system" {
fn MsiDatabaseExportW(
hDatabase: u32, // MSIHANDLE
szTableName: *const u16, // LPCWSTR
szFolderPath: *const u16, // LPCWSTR
szFileName: *const u16 // LPCWSTR
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("msi.dll", CharSet = CharSet.Unicode)]
public static extern uint MsiDatabaseExportW(uint hDatabase, [MarshalAs(UnmanagedType.LPWStr)] string szTableName, [MarshalAs(UnmanagedType.LPWStr)] string szFolderPath, [MarshalAs(UnmanagedType.LPWStr)] string szFileName);
"@
$api = Add-Type -MemberDefinition $sig -Name 'msi_MsiDatabaseExportW' -Namespace Win32 -PassThru
# $api::MsiDatabaseExportW(hDatabase, szTableName, szFolderPath, szFileName)#uselib "msi.dll"
#func global MsiDatabaseExportW "MsiDatabaseExportW" wptr, wptr, wptr, wptr
; MsiDatabaseExportW hDatabase, szTableName, szFolderPath, szFileName ; 戻り値は stat
; hDatabase : MSIHANDLE -> "wptr"
; szTableName : LPCWSTR -> "wptr"
; szFolderPath : LPCWSTR -> "wptr"
; szFileName : LPCWSTR -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "msi.dll"
#cfunc global MsiDatabaseExportW "MsiDatabaseExportW" int, wstr, wstr, wstr
; res = MsiDatabaseExportW(hDatabase, szTableName, szFolderPath, szFileName)
; hDatabase : MSIHANDLE -> "int"
; szTableName : LPCWSTR -> "wstr"
; szFolderPath : LPCWSTR -> "wstr"
; szFileName : LPCWSTR -> "wstr"; DWORD MsiDatabaseExportW(MSIHANDLE hDatabase, LPCWSTR szTableName, LPCWSTR szFolderPath, LPCWSTR szFileName)
#uselib "msi.dll"
#cfunc global MsiDatabaseExportW "MsiDatabaseExportW" int, wstr, wstr, wstr
; res = MsiDatabaseExportW(hDatabase, szTableName, szFolderPath, szFileName)
; hDatabase : MSIHANDLE -> "int"
; szTableName : LPCWSTR -> "wstr"
; szFolderPath : LPCWSTR -> "wstr"
; szFileName : LPCWSTR -> "wstr"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
msi = windows.NewLazySystemDLL("msi.dll")
procMsiDatabaseExportW = msi.NewProc("MsiDatabaseExportW")
)
// hDatabase (MSIHANDLE), szTableName (LPCWSTR), szFolderPath (LPCWSTR), szFileName (LPCWSTR)
r1, _, err := procMsiDatabaseExportW.Call(
uintptr(hDatabase),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(szTableName))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(szFolderPath))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(szFileName))),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction MsiDatabaseExportW(
hDatabase: DWORD; // MSIHANDLE
szTableName: PWideChar; // LPCWSTR
szFolderPath: PWideChar; // LPCWSTR
szFileName: PWideChar // LPCWSTR
): DWORD; stdcall;
external 'msi.dll' name 'MsiDatabaseExportW';result := DllCall("msi\MsiDatabaseExportW"
, "UInt", hDatabase ; MSIHANDLE
, "WStr", szTableName ; LPCWSTR
, "WStr", szFolderPath ; LPCWSTR
, "WStr", szFileName ; LPCWSTR
, "UInt") ; return: DWORD●MsiDatabaseExportW(hDatabase, szTableName, szFolderPath, szFileName) = DLL("msi.dll", "dword MsiDatabaseExportW(dword, char*, char*, char*)")
# 呼び出し: MsiDatabaseExportW(hDatabase, szTableName, szFolderPath, szFileName)
# hDatabase : MSIHANDLE -> "dword"
# szTableName : LPCWSTR -> "char*"
# szFolderPath : LPCWSTR -> "char*"
# szFileName : LPCWSTR -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。const std = @import("std");
extern "msi" fn MsiDatabaseExportW(
hDatabase: u32, // MSIHANDLE
szTableName: [*c]const u16, // LPCWSTR
szFolderPath: [*c]const u16, // LPCWSTR
szFileName: [*c]const u16 // LPCWSTR
) callconv(std.os.windows.WINAPI) u32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。proc MsiDatabaseExportW(
hDatabase: uint32, # MSIHANDLE
szTableName: WideCString, # LPCWSTR
szFolderPath: WideCString, # LPCWSTR
szFileName: WideCString # LPCWSTR
): uint32 {.importc: "MsiDatabaseExportW", stdcall, dynlib: "msi.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。pragma(lib, "msi");
extern(Windows)
uint MsiDatabaseExportW(
uint hDatabase, // MSIHANDLE
const(wchar)* szTableName, // LPCWSTR
const(wchar)* szFolderPath, // LPCWSTR
const(wchar)* szFileName // LPCWSTR
);ccall((:MsiDatabaseExportW, "msi.dll"), stdcall, UInt32,
(UInt32, Cwstring, Cwstring, Cwstring),
hDatabase, szTableName, szFolderPath, szFileName)
# hDatabase : MSIHANDLE -> UInt32
# szTableName : LPCWSTR -> Cwstring
# szFolderPath : LPCWSTR -> Cwstring
# szFileName : LPCWSTR -> Cwstring
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。local ffi = require("ffi")
ffi.cdef[[
uint32_t MsiDatabaseExportW(
uint32_t hDatabase,
const uint16_t* szTableName,
const uint16_t* szFolderPath,
const uint16_t* szFileName);
]]
local msi = ffi.load("msi")
-- msi.MsiDatabaseExportW(hDatabase, szTableName, szFolderPath, szFileName)
-- hDatabase : MSIHANDLE
-- szTableName : LPCWSTR
-- szFolderPath : LPCWSTR
-- szFileName : LPCWSTR
-- 構造体/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 MsiDatabaseExportW = lib.func('__stdcall', 'MsiDatabaseExportW', 'uint32_t', ['uint32_t', 'str16', 'str16', 'str16']);
// MsiDatabaseExportW(hDatabase, szTableName, szFolderPath, szFileName)
// hDatabase : MSIHANDLE -> 'uint32_t'
// szTableName : LPCWSTR -> 'str16'
// szFolderPath : LPCWSTR -> 'str16'
// szFileName : LPCWSTR -> 'str16'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("msi.dll", {
MsiDatabaseExportW: { parameters: ["u32", "buffer", "buffer", "buffer"], result: "u32" },
});
// lib.symbols.MsiDatabaseExportW(hDatabase, szTableName, szFolderPath, szFileName)
// hDatabase : MSIHANDLE -> "u32"
// szTableName : LPCWSTR -> "buffer"
// szFolderPath : LPCWSTR -> "buffer"
// szFileName : LPCWSTR -> "buffer"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t MsiDatabaseExportW(
uint32_t hDatabase,
const uint16_t* szTableName,
const uint16_t* szFolderPath,
const uint16_t* szFileName);
C, "msi.dll");
// $ffi->MsiDatabaseExportW(hDatabase, szTableName, szFolderPath, szFileName);
// hDatabase : MSIHANDLE
// szTableName : LPCWSTR
// szFolderPath : LPCWSTR
// szFileName : LPCWSTR
// 構造体/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 MsiDatabaseExportW(
int hDatabase, // MSIHANDLE
WString szTableName, // LPCWSTR
WString szFolderPath, // LPCWSTR
WString szFileName // LPCWSTR
);
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。@[Link("msi")]
lib Libmsi
fun MsiDatabaseExportW = MsiDatabaseExportW(
hDatabase : UInt32, # MSIHANDLE
szTableName : UInt16*, # LPCWSTR
szFolderPath : UInt16*, # LPCWSTR
szFileName : UInt16* # LPCWSTR
) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef MsiDatabaseExportWNative = Uint32 Function(Uint32, Pointer<Utf16>, Pointer<Utf16>, Pointer<Utf16>);
typedef MsiDatabaseExportWDart = int Function(int, Pointer<Utf16>, Pointer<Utf16>, Pointer<Utf16>);
final MsiDatabaseExportW = DynamicLibrary.open('msi.dll')
.lookupFunction<MsiDatabaseExportWNative, MsiDatabaseExportWDart>('MsiDatabaseExportW');
// hDatabase : MSIHANDLE -> Uint32
// szTableName : LPCWSTR -> Pointer<Utf16>
// szFolderPath : LPCWSTR -> Pointer<Utf16>
// szFileName : LPCWSTR -> Pointer<Utf16>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function MsiDatabaseExportW(
hDatabase: DWORD; // MSIHANDLE
szTableName: PWideChar; // LPCWSTR
szFolderPath: PWideChar; // LPCWSTR
szFileName: PWideChar // LPCWSTR
): DWORD; stdcall;
external 'msi.dll' name 'MsiDatabaseExportW';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "MsiDatabaseExportW"
c_MsiDatabaseExportW :: Word32 -> CWString -> CWString -> CWString -> IO Word32
-- hDatabase : MSIHANDLE -> Word32
-- szTableName : LPCWSTR -> CWString
-- szFolderPath : LPCWSTR -> CWString
-- szFileName : LPCWSTR -> CWString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let msidatabaseexportw =
foreign "MsiDatabaseExportW"
(uint32_t @-> (ptr uint16_t) @-> (ptr uint16_t) @-> (ptr uint16_t) @-> returning uint32_t)
(* hDatabase : MSIHANDLE -> uint32_t *)
(* szTableName : LPCWSTR -> (ptr uint16_t) *)
(* szFolderPath : LPCWSTR -> (ptr uint16_t) *)
(* szFileName : LPCWSTR -> (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 ("MsiDatabaseExportW" msi-database-export-w :convention :stdcall) :uint32
(h-database :uint32) ; MSIHANDLE
(sz-table-name (:string :encoding :utf-16le)) ; LPCWSTR
(sz-folder-path (:string :encoding :utf-16le)) ; LPCWSTR
(sz-file-name (:string :encoding :utf-16le))) ; LPCWSTR
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $MsiDatabaseExportW = Win32::API::More->new('msi',
'DWORD MsiDatabaseExportW(DWORD hDatabase, LPCWSTR szTableName, LPCWSTR szFolderPath, LPCWSTR szFileName)');
# my $ret = $MsiDatabaseExportW->Call($hDatabase, $szTableName, $szFolderPath, $szFileName);
# hDatabase : MSIHANDLE -> DWORD
# szTableName : LPCWSTR -> LPCWSTR
# szFolderPath : LPCWSTR -> LPCWSTR
# szFileName : LPCWSTR -> LPCWSTR
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。関連項目
文字セット違い
- f MsiDatabaseExportA (ANSI版) — データベースの指定テーブルをテキストアーカイブにエクスポートする。