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

MsiViewGetErrorW

関数
ビュー操作で発生した検証エラーと該当カラム名を取得する。
DLLmsi.dll文字セットUnicode (-W)呼出規約winapi対応OSwindows8.0

シグネチャ

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

MSIDBERROR MsiViewGetErrorW(
    MSIHANDLE hView,
    LPWSTR szColumnNameBuffer,   // optional
    DWORD* pcchBuf   // optional
);

パラメーター

名前方向説明
hViewMSIHANDLEinビューへのハンドル。
szColumnNameBufferLPWSTRoutoptionalnull で終わる列名を受け取るバッファーへのポインター。szColumnName に null(値=0)を渡してバッファーのサイズを判定しようとしないでください。バッファーのサイズは、空文字列(例: "")を渡すことで取得できます。この場合、関数は MSIDBERROR_MOREDATA を返し、pcchBuf には終端の null 文字を含まない、必要なバッファーサイズが TCHAR 単位で格納されます。MSIDBERROR_NOERROR が返された場合、pcchBuf には終端の null 文字を含まない、バッファーに書き込まれた TCHAR 数が格納されます。エラーがない場合、このパラメーターは空文字列になります。
pcchBufDWORD*inoutoptionalszColumnNameBuffer 変数が指すバッファーのサイズを TCHAR 単位で指定する変数へのポインター。関数が MSIDBERROR_NOERROR を返すとき、この変数には終端の null 文字を含まない、szColumnNameBuffer にコピーされたデータのサイズが格納されます。szColumnNameBuffer が十分な大きさでない場合、関数は MSIDBERROR_MOREDATA を返し、終端の null 文字を含まない必要なサイズを pcchBuf が指す変数に格納します。

戻り値の型: MSIDBERROR

公式ドキュメント

MsiViewGetError 関数は、MsiViewModify 関数で発生したエラーを返します。(Unicode)

戻り値

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

エラーコード 意味
MSIDBERROR_INVALIDARG
引数が無効でした。
MSIDBERROR_MOREDATA
バッファーが小さすぎてデータを受け取れませんでした。
MSIDBERROR_FUNCTIONERROR
関数が失敗しました。
MSIDBERROR_NOERROR
関数はエラーなく正常に完了しました。
MSIDBERROR_DUPLICATEKEY
新しいレコードが、テーブル内の既存レコードのプライマリキーと重複しています。
MSIDBERROR_REQUIRED
null 値が許可されていません。または、列を削除しようとしていますが、別の行から参照されています。
MSIDBERROR_BADLINK
外部テーブル内の対応するレコードが見つかりませんでした。
MSIDBERROR_OVERFLOW
データが許容される最大値を超えています。
MSIDBERROR_UNDERFLOW
データが許容される最小値を下回っています。
MSIDBERROR_NOTINSET
データがセット内で許可された値のメンバーではありません。
MSIDBERROR_BADVERSION
無効なバージョン文字列が指定されました。
MSIDBERROR_BADCASE
大文字小文字が無効でした。すべて大文字またはすべて小文字でなければなりません。
MSIDBERROR_BADGUID
無効な GUID が指定されました。
MSIDBERROR_BADWILDCARD
無効なワイルドカードファイル名が指定されたか、ワイルドカードの使用が無効でした。
MSIDBERROR_BADIDENTIFIER
無効な識別子が指定されました。
MSIDBERROR_BADLANGUAGE
無効な言語 ID が指定されました。
MSIDBERROR_BADFILENAME
無効なファイル名が指定されました。
MSIDBERROR_BADPATH
無効なパスが指定されました。
MSIDBERROR_BADCONDITION
無効な条件文が指定されました。
MSIDBERROR_BADFORMATTED
無効なフォーマット文字列が指定されました。
MSIDBERROR_BADTEMPLATE
無効なテンプレート文字列が指定されました。
MSIDBERROR_BADDEFAULTDIR

Directory テーブルの DefaultDir 列に無効な文字列が指定されました。

MSIDBERROR_BADREGPATH
無効なレジストリパス文字列が指定されました。
MSIDBERROR_BADCUSTOMSOURCE

CustomAction テーブルの CustomSource 列に無効な文字列が指定されました。

MSIDBERROR_BADPROPERTY
無効なプロパティ文字列が指定されました。
MSIDBERROR_MISSINGDATA

_Validation テーブルに列への参照がありません。

MSIDBERROR_BADCATEGORY
その列に対する _Validation テーブルの category 列が無効です。
MSIDBERROR_BADCABINET
無効なキャビネット名が指定されました。
MSIDBERROR_BADKEYTABLE
_Validation テーブルの Keytable 列で指定されたテーブルが見つからないか、読み込まれませんでした。
MSIDBERROR_BADMAXMINVALUES
_Validation テーブルの MaxValue 列の値が MinValue 列の値より小さくなっています。
MSIDBERROR_BADSHORTCUT
無効なショートカットターゲット名が指定されました。
MSIDBERROR_STRINGOVERFLOW
文字列が列定義で指定された長さに対して長すぎます。
MSIDBERROR_BADLOCALIZEATTRIB
無効なローカライズ属性が指定されました。(プライマリキーはローカライズできません。)

メモリ不足の状況では、この関数が STATUS_NO_MEMORY 例外を発生させる場合があることに注意してください。

解説(Remarks)

MsiViewGetError 関数は、 MsiViewModify がデータが無効であることを示す ERROR_INVALID_DATA を返した場合にのみ呼び出してください。エラーは MSIMODIFY_VALIDATEMSIMODIFY_VALIDATE_NEW、および MSIMODIFY_VALIDATEFIELD に対してのみ記録されます。

ERROR_MORE_DATA が返された場合、ポインターであるパラメーターは文字列を保持するために必要なバッファーのサイズを示します。成功した場合は、文字列バッファーに書き込まれた文字数を示します。したがって、小さなバッファー(最低 1 文字)を渡し、関数が MSIDBERROR_MOREDATA を返したときに pcchPathBuf の値を調べることで、必要なバッファーサイズを取得できます。szColumnNameBuffer に null を渡したり、pcchBuf が参照する DWORD にバッファーサイズ 0 を渡したりしてバッファーのサイズを判定しようとしないでください。

MSIDBERROR_NOERROR が返されると、検証エラーは残っていません。MSIDBERROR の戻り値は、szColumnNameBuffer で識別される列にある値について発生した検証エラーの種類を示します。

メモ

msiquery.h ヘッダーは MsiViewGetError を、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>

MSIDBERROR MsiViewGetErrorW(
    MSIHANDLE hView,
    LPWSTR szColumnNameBuffer,   // optional
    DWORD* pcchBuf   // optional
);
[DllImport("msi.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern int MsiViewGetErrorW(
    uint hView,   // MSIHANDLE
    [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder szColumnNameBuffer,   // LPWSTR optional, out
    IntPtr pcchBuf   // DWORD* optional, in/out
);
<DllImport("msi.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function MsiViewGetErrorW(
    hView As UInteger,   ' MSIHANDLE
    <MarshalAs(UnmanagedType.LPWStr)> szColumnNameBuffer As System.Text.StringBuilder,   ' LPWSTR optional, out
    pcchBuf As IntPtr   ' DWORD* optional, in/out
) As Integer
End Function
' hView : MSIHANDLE
' szColumnNameBuffer : LPWSTR optional, out
' pcchBuf : DWORD* optional, in/out
Declare PtrSafe Function MsiViewGetErrorW Lib "msi" ( _
    ByVal hView As Long, _
    ByVal szColumnNameBuffer As LongPtr, _
    ByVal pcchBuf 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

MsiViewGetErrorW = ctypes.windll.msi.MsiViewGetErrorW
MsiViewGetErrorW.restype = ctypes.c_int
MsiViewGetErrorW.argtypes = [
    wintypes.DWORD,  # hView : MSIHANDLE
    wintypes.LPWSTR,  # szColumnNameBuffer : LPWSTR optional, out
    ctypes.POINTER(wintypes.DWORD),  # pcchBuf : DWORD* optional, in/out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('msi.dll')
MsiViewGetErrorW = Fiddle::Function.new(
  lib['MsiViewGetErrorW'],
  [
    -Fiddle::TYPE_INT,  # hView : MSIHANDLE
    Fiddle::TYPE_VOIDP,  # szColumnNameBuffer : LPWSTR optional, out
    Fiddle::TYPE_VOIDP,  # pcchBuf : DWORD* optional, in/out
  ],
  Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "msi")]
extern "system" {
    fn MsiViewGetErrorW(
        hView: u32,  // MSIHANDLE
        szColumnNameBuffer: *mut u16,  // LPWSTR optional, out
        pcchBuf: *mut u32  // DWORD* optional, in/out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("msi.dll", CharSet = CharSet.Unicode)]
public static extern int MsiViewGetErrorW(uint hView, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder szColumnNameBuffer, IntPtr pcchBuf);
"@
$api = Add-Type -MemberDefinition $sig -Name 'msi_MsiViewGetErrorW' -Namespace Win32 -PassThru
# $api::MsiViewGetErrorW(hView, szColumnNameBuffer, pcchBuf)
#uselib "msi.dll"
#func global MsiViewGetErrorW "MsiViewGetErrorW" wptr, wptr, wptr
; MsiViewGetErrorW hView, varptr(szColumnNameBuffer), varptr(pcchBuf)   ; 戻り値は stat
; hView : MSIHANDLE -> "wptr"
; szColumnNameBuffer : LPWSTR optional, out -> "wptr"
; pcchBuf : DWORD* optional, in/out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "msi.dll"
#cfunc global MsiViewGetErrorW "MsiViewGetErrorW" int, var, var
; res = MsiViewGetErrorW(hView, szColumnNameBuffer, pcchBuf)
; hView : MSIHANDLE -> "int"
; szColumnNameBuffer : LPWSTR optional, out -> "var"
; pcchBuf : DWORD* optional, in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; MSIDBERROR MsiViewGetErrorW(MSIHANDLE hView, LPWSTR szColumnNameBuffer, DWORD* pcchBuf)
#uselib "msi.dll"
#cfunc global MsiViewGetErrorW "MsiViewGetErrorW" int, var, var
; res = MsiViewGetErrorW(hView, szColumnNameBuffer, pcchBuf)
; hView : MSIHANDLE -> "int"
; szColumnNameBuffer : LPWSTR optional, out -> "var"
; pcchBuf : DWORD* optional, in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	msi = windows.NewLazySystemDLL("msi.dll")
	procMsiViewGetErrorW = msi.NewProc("MsiViewGetErrorW")
)

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

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

typedef MsiViewGetErrorWNative = Int32 Function(Uint32, Pointer<Utf16>, Pointer<Uint32>);
typedef MsiViewGetErrorWDart = int Function(int, Pointer<Utf16>, Pointer<Uint32>);
final MsiViewGetErrorW = DynamicLibrary.open('msi.dll')
    .lookupFunction<MsiViewGetErrorWNative, MsiViewGetErrorWDart>('MsiViewGetErrorW');
// hView : MSIHANDLE -> Uint32
// szColumnNameBuffer : LPWSTR optional, out -> Pointer<Utf16>
// pcchBuf : DWORD* optional, in/out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function MsiViewGetErrorW(
  hView: DWORD;   // MSIHANDLE
  szColumnNameBuffer: PWideChar;   // LPWSTR optional, out
  pcchBuf: Pointer   // DWORD* optional, in/out
): Integer; stdcall;
  external 'msi.dll' name 'MsiViewGetErrorW';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "MsiViewGetErrorW"
  c_MsiViewGetErrorW :: Word32 -> CWString -> Ptr Word32 -> IO Int32
-- hView : MSIHANDLE -> Word32
-- szColumnNameBuffer : LPWSTR optional, out -> CWString
-- pcchBuf : DWORD* optional, in/out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let msiviewgeterrorw =
  foreign "MsiViewGetErrorW"
    (uint32_t @-> (ptr uint16_t) @-> (ptr uint32_t) @-> returning int32_t)
(* hView : MSIHANDLE -> uint32_t *)
(* szColumnNameBuffer : LPWSTR optional, out -> (ptr uint16_t) *)
(* pcchBuf : DWORD* optional, in/out -> (ptr uint32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library msi (t "msi.dll"))
(cffi:use-foreign-library msi)

(cffi:defcfun ("MsiViewGetErrorW" msi-view-get-error-w :convention :stdcall) :int32
  (h-view :uint32)   ; MSIHANDLE
  (sz-column-name-buffer :pointer)   ; LPWSTR optional, out
  (pcch-buf :pointer))   ; DWORD* optional, in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $MsiViewGetErrorW = Win32::API::More->new('msi',
    'int MsiViewGetErrorW(DWORD hView, LPWSTR szColumnNameBuffer, LPVOID pcchBuf)');
# my $ret = $MsiViewGetErrorW->Call($hView, $szColumnNameBuffer, $pcchBuf);
# hView : MSIHANDLE -> DWORD
# szColumnNameBuffer : LPWSTR optional, out -> LPWSTR
# pcchBuf : DWORD* optional, in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。

関連項目

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