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

WerReportAddFile

関数
WERレポートに添付ファイルを追加する。
DLLwer.dll呼出規約winapi対応OSWindows Vista 以降

シグネチャ

// wer.dll
#include <windows.h>

HRESULT WerReportAddFile(
    HREPORT hReportHandle,
    LPCWSTR pwzPath,
    WER_FILE_TYPE repFileType,
    WER_FILE dwFileFlags
);

パラメーター

名前型方向説明
hReportHandleHREPORTinレポートへのハンドル。このハンドルは WerReportCreate 関数から返されます。
pwzPathLPCWSTRin追加するファイルへのフルパスを格納した Unicode 文字列へのポインター。このパスには環境変数を使用できます。このパスの最大長は MAX_PATH 文字です。
repFileTypeWER_FILE_TYPEin

ファイルの種類。このパラメーターには、WER_FILE_TYPE 列挙型の次のいずれかの値を指定できます。

値 意味
WerFileTypeHeapdump プロセスのメモリなど、追加のデータを含む拡張ミニダンプ。
WerFileTypeMicrodump スタックトレースのみを含む限定的なミニダンプ。
WerFileTypeMinidump ミニダンプファイル。
WerFileTypeOther その他の種類のファイル。このファイルは常に cab に追加されます (ただし、サーバーが cab を要求した場合のみ)。
WerFileTypeUserDocument イベント発生時にアプリケーションが使用していたドキュメント。このドキュメントは、サーバーがこの種類のドキュメントを要求した場合にのみ追加されます。
dwFileFlagsWER_FILEin

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

値 意味
WER_FILE_ANONYMOUS_DATA このファイルには、ユーザーの特定や連絡に利用できる個人情報は含まれていません。
WER_FILE_DELETE_WHEN_DONE レポートの送信後に、このファイルを自動的に削除します。

戻り値の型: HRESULT

公式ドキュメント

指定された Windows エラー報告 (WER) レポートにファイルを追加します。

戻り値

この関数は、成功した場合は S_OK を返し、失敗した場合は次のエラーコードを含むエラーコードを返します。

戻り値 説明
HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) 指定されたファイルが存在しません。
HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED) 指定されたファイルはユーザードキュメントであり、暗号化されたファイルシステム上に格納されています。この組み合わせはサポートされていません。

解説(Remarks)

この関数は (特定のフラグを指定することで) メモリダンプをエラーレポートに追加する用途にも使用できますが、メモリダンプの追加には WerReportAddDump 関数を使用することをお勧めします。この関数は、自分でダンプを収集してレポートに追加する場合にのみ使用してください。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

// wer.dll
#include <windows.h>

HRESULT WerReportAddFile(
    HREPORT hReportHandle,
    LPCWSTR pwzPath,
    WER_FILE_TYPE repFileType,
    WER_FILE dwFileFlags
);
[DllImport("wer.dll", ExactSpelling = true)]
static extern int WerReportAddFile(
    IntPtr hReportHandle,   // HREPORT
    [MarshalAs(UnmanagedType.LPWStr)] string pwzPath,   // LPCWSTR
    int repFileType,   // WER_FILE_TYPE
    uint dwFileFlags   // WER_FILE
);
<DllImport("wer.dll", ExactSpelling:=True)>
Public Shared Function WerReportAddFile(
    hReportHandle As IntPtr,   ' HREPORT
    <MarshalAs(UnmanagedType.LPWStr)> pwzPath As String,   ' LPCWSTR
    repFileType As Integer,   ' WER_FILE_TYPE
    dwFileFlags As UInteger   ' WER_FILE
) As Integer
End Function
' hReportHandle : HREPORT
' pwzPath : LPCWSTR
' repFileType : WER_FILE_TYPE
' dwFileFlags : WER_FILE
Declare PtrSafe Function WerReportAddFile Lib "wer" ( _
    ByVal hReportHandle As LongPtr, _
    ByVal pwzPath As LongPtr, _
    ByVal repFileType As Long, _
    ByVal dwFileFlags As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

WerReportAddFile = ctypes.windll.wer.WerReportAddFile
WerReportAddFile.restype = ctypes.c_int
WerReportAddFile.argtypes = [
    wintypes.HANDLE,  # hReportHandle : HREPORT
    wintypes.LPCWSTR,  # pwzPath : LPCWSTR
    ctypes.c_int,  # repFileType : WER_FILE_TYPE
    wintypes.DWORD,  # dwFileFlags : WER_FILE
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('wer.dll')
WerReportAddFile = Fiddle::Function.new(
  lib['WerReportAddFile'],
  [
    Fiddle::TYPE_VOIDP,  # hReportHandle : HREPORT
    Fiddle::TYPE_VOIDP,  # pwzPath : LPCWSTR
    Fiddle::TYPE_INT,  # repFileType : WER_FILE_TYPE
    -Fiddle::TYPE_INT,  # dwFileFlags : WER_FILE
  ],
  Fiddle::TYPE_INT)
#[link(name = "wer")]
extern "system" {
    fn WerReportAddFile(
        hReportHandle: *mut core::ffi::c_void,  // HREPORT
        pwzPath: *const u16,  // LPCWSTR
        repFileType: i32,  // WER_FILE_TYPE
        dwFileFlags: u32  // WER_FILE
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("wer.dll")]
public static extern int WerReportAddFile(IntPtr hReportHandle, [MarshalAs(UnmanagedType.LPWStr)] string pwzPath, int repFileType, uint dwFileFlags);
"@
$api = Add-Type -MemberDefinition $sig -Name 'wer_WerReportAddFile' -Namespace Win32 -PassThru
# $api::WerReportAddFile(hReportHandle, pwzPath, repFileType, dwFileFlags)
#uselib "wer.dll"
#func global WerReportAddFile "WerReportAddFile" sptr, sptr, sptr, sptr
; WerReportAddFile hReportHandle, pwzPath, repFileType, dwFileFlags   ; 戻り値は stat
; hReportHandle : HREPORT -> "sptr"
; pwzPath : LPCWSTR -> "sptr"
; repFileType : WER_FILE_TYPE -> "sptr"
; dwFileFlags : WER_FILE -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "wer.dll"
#cfunc global WerReportAddFile "WerReportAddFile" sptr, wstr, int, int
; res = WerReportAddFile(hReportHandle, pwzPath, repFileType, dwFileFlags)
; hReportHandle : HREPORT -> "sptr"
; pwzPath : LPCWSTR -> "wstr"
; repFileType : WER_FILE_TYPE -> "int"
; dwFileFlags : WER_FILE -> "int"
; HRESULT WerReportAddFile(HREPORT hReportHandle, LPCWSTR pwzPath, WER_FILE_TYPE repFileType, WER_FILE dwFileFlags)
#uselib "wer.dll"
#cfunc global WerReportAddFile "WerReportAddFile" intptr, wstr, int, int
; res = WerReportAddFile(hReportHandle, pwzPath, repFileType, dwFileFlags)
; hReportHandle : HREPORT -> "intptr"
; pwzPath : LPCWSTR -> "wstr"
; repFileType : WER_FILE_TYPE -> "int"
; dwFileFlags : WER_FILE -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	wer = windows.NewLazySystemDLL("wer.dll")
	procWerReportAddFile = wer.NewProc("WerReportAddFile")
)

// hReportHandle (HREPORT), pwzPath (LPCWSTR), repFileType (WER_FILE_TYPE), dwFileFlags (WER_FILE)
r1, _, err := procWerReportAddFile.Call(
	uintptr(hReportHandle),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pwzPath))),
	uintptr(repFileType),
	uintptr(dwFileFlags),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function WerReportAddFile(
  hReportHandle: THandle;   // HREPORT
  pwzPath: PWideChar;   // LPCWSTR
  repFileType: Integer;   // WER_FILE_TYPE
  dwFileFlags: DWORD   // WER_FILE
): Integer; stdcall;
  external 'wer.dll' name 'WerReportAddFile';
result := DllCall("wer\WerReportAddFile"
    , "Ptr", hReportHandle   ; HREPORT
    , "WStr", pwzPath   ; LPCWSTR
    , "Int", repFileType   ; WER_FILE_TYPE
    , "UInt", dwFileFlags   ; WER_FILE
    , "Int")   ; return: HRESULT
●WerReportAddFile(hReportHandle, pwzPath, repFileType, dwFileFlags) = DLL("wer.dll", "int WerReportAddFile(void*, char*, int, dword)")
# 呼び出し: WerReportAddFile(hReportHandle, pwzPath, repFileType, dwFileFlags)
# hReportHandle : HREPORT -> "void*"
# pwzPath : LPCWSTR -> "char*"
# repFileType : WER_FILE_TYPE -> "int"
# dwFileFlags : WER_FILE -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "wer" fn WerReportAddFile(
    hReportHandle: ?*anyopaque, // HREPORT
    pwzPath: [*c]const u16, // LPCWSTR
    repFileType: i32, // WER_FILE_TYPE
    dwFileFlags: u32 // WER_FILE
) callconv(std.os.windows.WINAPI) i32;
proc WerReportAddFile(
    hReportHandle: pointer,  # HREPORT
    pwzPath: WideCString,  # LPCWSTR
    repFileType: int32,  # WER_FILE_TYPE
    dwFileFlags: uint32  # WER_FILE
): int32 {.importc: "WerReportAddFile", stdcall, dynlib: "wer.dll".}
pragma(lib, "wer");
extern(Windows)
int WerReportAddFile(
    void* hReportHandle,   // HREPORT
    const(wchar)* pwzPath,   // LPCWSTR
    int repFileType,   // WER_FILE_TYPE
    uint dwFileFlags   // WER_FILE
);
ccall((:WerReportAddFile, "wer.dll"), stdcall, Int32,
      (Ptr{Cvoid}, Cwstring, Int32, UInt32),
      hReportHandle, pwzPath, repFileType, dwFileFlags)
# hReportHandle : HREPORT -> Ptr{Cvoid}
# pwzPath : LPCWSTR -> Cwstring
# repFileType : WER_FILE_TYPE -> Int32
# dwFileFlags : WER_FILE -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t WerReportAddFile(
    void* hReportHandle,
    const uint16_t* pwzPath,
    int32_t repFileType,
    uint32_t dwFileFlags);
]]
local wer = ffi.load("wer")
-- wer.WerReportAddFile(hReportHandle, pwzPath, repFileType, dwFileFlags)
-- hReportHandle : HREPORT
-- pwzPath : LPCWSTR
-- repFileType : WER_FILE_TYPE
-- dwFileFlags : WER_FILE
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('wer.dll');
const WerReportAddFile = lib.func('__stdcall', 'WerReportAddFile', 'int32_t', ['void *', 'str16', 'int32_t', 'uint32_t']);
// WerReportAddFile(hReportHandle, pwzPath, repFileType, dwFileFlags)
// hReportHandle : HREPORT -> 'void *'
// pwzPath : LPCWSTR -> 'str16'
// repFileType : WER_FILE_TYPE -> 'int32_t'
// dwFileFlags : WER_FILE -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("wer.dll", {
  WerReportAddFile: { parameters: ["pointer", "buffer", "i32", "u32"], result: "i32" },
});
// lib.symbols.WerReportAddFile(hReportHandle, pwzPath, repFileType, dwFileFlags)
// hReportHandle : HREPORT -> "pointer"
// pwzPath : LPCWSTR -> "buffer"
// repFileType : WER_FILE_TYPE -> "i32"
// dwFileFlags : WER_FILE -> "u32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t WerReportAddFile(
    void* hReportHandle,
    const uint16_t* pwzPath,
    int32_t repFileType,
    uint32_t dwFileFlags);
C, "wer.dll");
// $ffi->WerReportAddFile(hReportHandle, pwzPath, repFileType, dwFileFlags);
// hReportHandle : HREPORT
// pwzPath : LPCWSTR
// repFileType : WER_FILE_TYPE
// dwFileFlags : WER_FILE
// 構造体/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 Wer extends StdCallLibrary {
    Wer INSTANCE = Native.load("wer", Wer.class);
    int WerReportAddFile(
        Pointer hReportHandle,   // HREPORT
        WString pwzPath,   // LPCWSTR
        int repFileType,   // WER_FILE_TYPE
        int dwFileFlags   // WER_FILE
    );
}
@[Link("wer")]
lib Libwer
  fun WerReportAddFile = WerReportAddFile(
    hReportHandle : Void*,   # HREPORT
    pwzPath : UInt16*,   # LPCWSTR
    repFileType : Int32,   # WER_FILE_TYPE
    dwFileFlags : UInt32   # WER_FILE
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef WerReportAddFileNative = Int32 Function(Pointer<Void>, Pointer<Utf16>, Int32, Uint32);
typedef WerReportAddFileDart = int Function(Pointer<Void>, Pointer<Utf16>, int, int);
final WerReportAddFile = DynamicLibrary.open('wer.dll')
    .lookupFunction<WerReportAddFileNative, WerReportAddFileDart>('WerReportAddFile');
// hReportHandle : HREPORT -> Pointer<Void>
// pwzPath : LPCWSTR -> Pointer<Utf16>
// repFileType : WER_FILE_TYPE -> Int32
// dwFileFlags : WER_FILE -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function WerReportAddFile(
  hReportHandle: THandle;   // HREPORT
  pwzPath: PWideChar;   // LPCWSTR
  repFileType: Integer;   // WER_FILE_TYPE
  dwFileFlags: DWORD   // WER_FILE
): Integer; stdcall;
  external 'wer.dll' name 'WerReportAddFile';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "WerReportAddFile"
  c_WerReportAddFile :: Ptr () -> CWString -> Int32 -> Word32 -> IO Int32
-- hReportHandle : HREPORT -> Ptr ()
-- pwzPath : LPCWSTR -> CWString
-- repFileType : WER_FILE_TYPE -> Int32
-- dwFileFlags : WER_FILE -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let werreportaddfile =
  foreign "WerReportAddFile"
    ((ptr void) @-> (ptr uint16_t) @-> int32_t @-> uint32_t @-> returning int32_t)
(* hReportHandle : HREPORT -> (ptr void) *)
(* pwzPath : LPCWSTR -> (ptr uint16_t) *)
(* repFileType : WER_FILE_TYPE -> int32_t *)
(* dwFileFlags : WER_FILE -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library wer (t "wer.dll"))
(cffi:use-foreign-library wer)

(cffi:defcfun ("WerReportAddFile" wer-report-add-file :convention :stdcall) :int32
  (h-report-handle :pointer)   ; HREPORT
  (pwz-path (:string :encoding :utf-16le))   ; LPCWSTR
  (rep-file-type :int32)   ; WER_FILE_TYPE
  (dw-file-flags :uint32))   ; WER_FILE
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $WerReportAddFile = Win32::API::More->new('wer',
    'int WerReportAddFile(HANDLE hReportHandle, LPCWSTR pwzPath, int repFileType, DWORD dwFileFlags)');
# my $ret = $WerReportAddFile->Call($hReportHandle, $pwzPath, $repFileType, $dwFileFlags);
# hReportHandle : HREPORT -> HANDLE
# pwzPath : LPCWSTR -> LPCWSTR
# repFileType : WER_FILE_TYPE -> int
# dwFileFlags : WER_FILE -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型