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対象レポートのHREPORTハンドル。
pwzPathLPCWSTRinレポートに添付するファイルのパスを指すワイド文字列。
repFileTypeWER_FILE_TYPEin添付ファイルの種類を指定するWER_FILE_TYPE列挙値。
dwFileFlagsWER_FILEinファイル処理を制御するWER_FILEビットフラグ。

戻り値の型: HRESULT

各言語での呼び出し定義

// 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 を使用。

関連項目

使用する型