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

MsiEnableLogW

関数
インストーラのログ出力を有効化する(Unicode版)。
DLLmsi.dll文字セットUnicode (-W)呼出規約winapi対応OSwindows8.0

シグネチャ

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

DWORD MsiEnableLogW(
    DWORD dwLogMode,
    LPCWSTR szLogFile,   // optional
    DWORD dwLogAttributes
);

パラメーター

名前方向説明
dwLogModeDWORDin

ログモードを指定します。このパラメーターには、次の値の 1 つ以上を指定できます。

意味
INSTALLLOGMODE_FATALEXIT
メモリ不足または致命的な終了に関する情報をログに記録します。
INSTALLLOGMODE_ERROR
エラーメッセージをログに記録します。
INSTALLLOGMODE_EXTRADEBUG
ハンドル作成情報などの追加のデバッグ情報をログファイルに送ります。

Windows 2000 および Windows XP: この機能はサポートされていません。

INSTALLLOGMODE_WARNING
警告メッセージをログに記録します。
INSTALLLOGMODE_USER
ユーザー要求をログに記録します。
INSTALLLOGMODE_INFO
表示されないステータスメッセージをログに記録します。
INSTALLLOGMODE_RESOLVESOURCE
有効なソースの場所を特定する要求です。
INSTALLLOGMODE_OUTOFDISKSPACE
ディスク容量の不足を示します。
INSTALLLOGMODE_ACTIONSTART
新しいインストールアクションの開始をログに記録します。
INSTALLLOGMODE_ACTIONDATA
インストールアクションに伴うデータレコードをログに記録します。
INSTALLLOGMODE_COMMONDATA
ユーザーインターフェイスの初期化のためのパラメーターをログに記録します。
INSTALLLOGMODE_PROPERTYDUMP
終了時のプロパティ値をログに記録します。
INSTALLLOGMODE_VERBOSE
INSTALLLOGMODE_EXTRADEBUG を除く、他のすべてのログモードの情報をログに記録します。これにより、一般的にユーザーにとって有用ではない大量の情報がログファイルに送られます。テクニカルサポートで使用される場合があります。
INSTALLLOGMODE_LOGONLYONERROR
ログ情報は収集されますが、ログファイルへの保存頻度は低くなります。これにより一部のインストールではパフォーマンスが向上することがありますが、大規模なインストールではほとんど効果がない場合があります。インストールが成功すると、ログファイルは削除されます。インストールが失敗した場合は、すべてのログ情報がログファイルに保存されます。

Windows Installer 2.0: このログモードは使用できません。

szLogFileLPCWSTRinoptionalログファイルへのフルパスを保持する文字列を指定します。null を指定するとログ記録が無効になり、その場合 dwlogmode は無視されます。パスを指定する場合は、dwlogmode を 0 にすることはできません。
dwLogAttributesDWORDin

ログバッファをフラッシュする頻度を指定します。

意味
INSTALLLOGATTRIBUTES_APPEND
この値が設定されている場合、インストーラーは szLogFile で指定された既存のログに追記します。設定されていない場合、szLogFile で指定された既存のログは上書きされます。
INSTALLLOGATTRIBUTES_FLUSHEACHLINE
各行ごとにログバッファを強制的にフラッシュします。この値が設定されていない場合、インストーラーは FlushFileBuffers を呼び出して 20 行ごとにログバッファをフラッシュします。

戻り値の型: DWORD

公式ドキュメント

MsiEnableLog 関数は、呼び出し元プロセスで開始される以降のすべてのインストールに対するログモードを設定します。(Unicode)

戻り値

意味
ERROR_INVALID_PARAMETER
無効なログモードが指定されました。
ERROR_SUCCESS
関数が成功しました。

解説(Remarks)

ログ記録ポリシーの説明については、 System Policy を参照してください。

この関数を使用する際は、ログファイルの場所へのパスがあらかじめ存在している必要があります。インストーラーはログファイル用のディレクトリ構造を作成しません。

メモ

msi.h ヘッダーは MsiEnableLog を、UNICODE プリプロセッサ定数の定義に基づいてこの関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして定義しています。エンコーディング中立のエイリアスの使用を、エンコーディング中立でないコードと混在させると、不一致が発生し、コンパイルエラーやランタイムエラーを引き起こす可能性があります。詳細については、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 MsiEnableLogW(
    DWORD dwLogMode,
    LPCWSTR szLogFile,   // optional
    DWORD dwLogAttributes
);
[DllImport("msi.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern uint MsiEnableLogW(
    uint dwLogMode,   // DWORD
    [MarshalAs(UnmanagedType.LPWStr)] string szLogFile,   // LPCWSTR optional
    uint dwLogAttributes   // DWORD
);
<DllImport("msi.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function MsiEnableLogW(
    dwLogMode As UInteger,   ' DWORD
    <MarshalAs(UnmanagedType.LPWStr)> szLogFile As String,   ' LPCWSTR optional
    dwLogAttributes As UInteger   ' DWORD
) As UInteger
End Function
' dwLogMode : DWORD
' szLogFile : LPCWSTR optional
' dwLogAttributes : DWORD
Declare PtrSafe Function MsiEnableLogW Lib "msi" ( _
    ByVal dwLogMode As Long, _
    ByVal szLogFile As LongPtr, _
    ByVal dwLogAttributes 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

MsiEnableLogW = ctypes.windll.msi.MsiEnableLogW
MsiEnableLogW.restype = wintypes.DWORD
MsiEnableLogW.argtypes = [
    wintypes.DWORD,  # dwLogMode : DWORD
    wintypes.LPCWSTR,  # szLogFile : LPCWSTR optional
    wintypes.DWORD,  # dwLogAttributes : DWORD
]
require 'fiddle'
require 'fiddle/import'

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

var (
	msi = windows.NewLazySystemDLL("msi.dll")
	procMsiEnableLogW = msi.NewProc("MsiEnableLogW")
)

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

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

typedef MsiEnableLogWNative = Uint32 Function(Uint32, Pointer<Utf16>, Uint32);
typedef MsiEnableLogWDart = int Function(int, Pointer<Utf16>, int);
final MsiEnableLogW = DynamicLibrary.open('msi.dll')
    .lookupFunction<MsiEnableLogWNative, MsiEnableLogWDart>('MsiEnableLogW');
// dwLogMode : DWORD -> Uint32
// szLogFile : LPCWSTR optional -> Pointer<Utf16>
// dwLogAttributes : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function MsiEnableLogW(
  dwLogMode: DWORD;   // DWORD
  szLogFile: PWideChar;   // LPCWSTR optional
  dwLogAttributes: DWORD   // DWORD
): DWORD; stdcall;
  external 'msi.dll' name 'MsiEnableLogW';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "MsiEnableLogW"
  c_MsiEnableLogW :: Word32 -> CWString -> Word32 -> IO Word32
-- dwLogMode : DWORD -> Word32
-- szLogFile : LPCWSTR optional -> CWString
-- dwLogAttributes : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let msienablelogw =
  foreign "MsiEnableLogW"
    (uint32_t @-> (ptr uint16_t) @-> uint32_t @-> returning uint32_t)
(* dwLogMode : DWORD -> uint32_t *)
(* szLogFile : LPCWSTR optional -> (ptr uint16_t) *)
(* dwLogAttributes : DWORD -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library msi (t "msi.dll"))
(cffi:use-foreign-library msi)

(cffi:defcfun ("MsiEnableLogW" msi-enable-log-w :convention :stdcall) :uint32
  (dw-log-mode :uint32)   ; DWORD
  (sz-log-file (:string :encoding :utf-16le))   ; LPCWSTR optional
  (dw-log-attributes :uint32))   ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $MsiEnableLogW = Win32::API::More->new('msi',
    'DWORD MsiEnableLogW(DWORD dwLogMode, LPCWSTR szLogFile, DWORD dwLogAttributes)');
# my $ret = $MsiEnableLogW->Call($dwLogMode, $szLogFile, $dwLogAttributes);
# dwLogMode : DWORD -> DWORD
# szLogFile : LPCWSTR optional -> LPCWSTR
# dwLogAttributes : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。

関連項目

文字セット違い