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

ReportFault

関数
発生した例外の障害をWERに報告する。
DLLfaultrep.dll呼出規約winapi対応OSWindows XP 以降

シグネチャ

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

EFaultRepRetVal ReportFault(
    EXCEPTION_POINTERS* pep,
    DWORD dwOpt
);

パラメーター

名前方向説明
pepEXCEPTION_POINTERS*in報告する例外情報を格納したEXCEPTION_POINTERSへのポインタ。
dwOptDWORDin報告動作を制御するオプションフラグ。

戻り値の型: EFaultRepRetVal

各言語での呼び出し定義

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

EFaultRepRetVal ReportFault(
    EXCEPTION_POINTERS* pep,
    DWORD dwOpt
);
[DllImport("faultrep.dll", ExactSpelling = true)]
static extern int ReportFault(
    IntPtr pep,   // EXCEPTION_POINTERS*
    uint dwOpt   // DWORD
);
<DllImport("faultrep.dll", ExactSpelling:=True)>
Public Shared Function ReportFault(
    pep As IntPtr,   ' EXCEPTION_POINTERS*
    dwOpt As UInteger   ' DWORD
) As Integer
End Function
' pep : EXCEPTION_POINTERS*
' dwOpt : DWORD
Declare PtrSafe Function ReportFault Lib "faultrep" ( _
    ByVal pep As LongPtr, _
    ByVal dwOpt As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

ReportFault = ctypes.windll.faultrep.ReportFault
ReportFault.restype = ctypes.c_int
ReportFault.argtypes = [
    ctypes.c_void_p,  # pep : EXCEPTION_POINTERS*
    wintypes.DWORD,  # dwOpt : DWORD
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('faultrep.dll')
ReportFault = Fiddle::Function.new(
  lib['ReportFault'],
  [
    Fiddle::TYPE_VOIDP,  # pep : EXCEPTION_POINTERS*
    -Fiddle::TYPE_INT,  # dwOpt : DWORD
  ],
  Fiddle::TYPE_INT)
#[link(name = "faultrep")]
extern "system" {
    fn ReportFault(
        pep: *mut EXCEPTION_POINTERS,  // EXCEPTION_POINTERS*
        dwOpt: u32  // DWORD
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("faultrep.dll")]
public static extern int ReportFault(IntPtr pep, uint dwOpt);
"@
$api = Add-Type -MemberDefinition $sig -Name 'faultrep_ReportFault' -Namespace Win32 -PassThru
# $api::ReportFault(pep, dwOpt)
#uselib "faultrep.dll"
#func global ReportFault "ReportFault" sptr, sptr
; ReportFault varptr(pep), dwOpt   ; 戻り値は stat
; pep : EXCEPTION_POINTERS* -> "sptr"
; dwOpt : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "faultrep.dll"
#cfunc global ReportFault "ReportFault" var, int
; res = ReportFault(pep, dwOpt)
; pep : EXCEPTION_POINTERS* -> "var"
; dwOpt : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; EFaultRepRetVal ReportFault(EXCEPTION_POINTERS* pep, DWORD dwOpt)
#uselib "faultrep.dll"
#cfunc global ReportFault "ReportFault" var, int
; res = ReportFault(pep, dwOpt)
; pep : EXCEPTION_POINTERS* -> "var"
; dwOpt : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	faultrep = windows.NewLazySystemDLL("faultrep.dll")
	procReportFault = faultrep.NewProc("ReportFault")
)

// pep (EXCEPTION_POINTERS*), dwOpt (DWORD)
r1, _, err := procReportFault.Call(
	uintptr(pep),
	uintptr(dwOpt),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // EFaultRepRetVal
function ReportFault(
  pep: Pointer;   // EXCEPTION_POINTERS*
  dwOpt: DWORD   // DWORD
): Integer; stdcall;
  external 'faultrep.dll' name 'ReportFault';
result := DllCall("faultrep\ReportFault"
    , "Ptr", pep   ; EXCEPTION_POINTERS*
    , "UInt", dwOpt   ; DWORD
    , "Int")   ; return: EFaultRepRetVal
●ReportFault(pep, dwOpt) = DLL("faultrep.dll", "int ReportFault(void*, dword)")
# 呼び出し: ReportFault(pep, dwOpt)
# pep : EXCEPTION_POINTERS* -> "void*"
# dwOpt : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

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

typedef ReportFaultNative = Int32 Function(Pointer<Void>, Uint32);
typedef ReportFaultDart = int Function(Pointer<Void>, int);
final ReportFault = DynamicLibrary.open('faultrep.dll')
    .lookupFunction<ReportFaultNative, ReportFaultDart>('ReportFault');
// pep : EXCEPTION_POINTERS* -> Pointer<Void>
// dwOpt : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function ReportFault(
  pep: Pointer;   // EXCEPTION_POINTERS*
  dwOpt: DWORD   // DWORD
): Integer; stdcall;
  external 'faultrep.dll' name 'ReportFault';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "ReportFault"
  c_ReportFault :: Ptr () -> Word32 -> IO Int32
-- pep : EXCEPTION_POINTERS* -> Ptr ()
-- dwOpt : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let reportfault =
  foreign "ReportFault"
    ((ptr void) @-> uint32_t @-> returning int32_t)
(* pep : EXCEPTION_POINTERS* -> (ptr void) *)
(* dwOpt : DWORD -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library faultrep (t "faultrep.dll"))
(cffi:use-foreign-library faultrep)

(cffi:defcfun ("ReportFault" report-fault :convention :stdcall) :int32
  (pep :pointer)   ; EXCEPTION_POINTERS*
  (dw-opt :uint32))   ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $ReportFault = Win32::API::More->new('faultrep',
    'int ReportFault(LPVOID pep, DWORD dwOpt)');
# my $ret = $ReportFault->Call($pep, $dwOpt);
# pep : EXCEPTION_POINTERS* -> LPVOID
# dwOpt : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型