Win32 API 日本語リファレンス
ホームSystem.Diagnostics.Debug › SetUnhandledExceptionFilter

SetUnhandledExceptionFilter

関数
未処理例外を処理するトップレベルフィルタ関数を設定する。
DLLKERNEL32.dll呼出規約winapi対応OSWindows XP 以降

シグネチャ

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

LPTOP_LEVEL_EXCEPTION_FILTER SetUnhandledExceptionFilter(
    LPTOP_LEVEL_EXCEPTION_FILTER lpTopLevelExceptionFilter   // optional
);

パラメーター

名前方向
lpTopLevelExceptionFilterLPTOP_LEVEL_EXCEPTION_FILTERinoptional

戻り値の型: LPTOP_LEVEL_EXCEPTION_FILTER

各言語での呼び出し定義

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

LPTOP_LEVEL_EXCEPTION_FILTER SetUnhandledExceptionFilter(
    LPTOP_LEVEL_EXCEPTION_FILTER lpTopLevelExceptionFilter   // optional
);
[DllImport("KERNEL32.dll", ExactSpelling = true)]
static extern IntPtr SetUnhandledExceptionFilter(
    IntPtr lpTopLevelExceptionFilter   // LPTOP_LEVEL_EXCEPTION_FILTER optional
);
<DllImport("KERNEL32.dll", ExactSpelling:=True)>
Public Shared Function SetUnhandledExceptionFilter(
    lpTopLevelExceptionFilter As IntPtr   ' LPTOP_LEVEL_EXCEPTION_FILTER optional
) As IntPtr
End Function
' lpTopLevelExceptionFilter : LPTOP_LEVEL_EXCEPTION_FILTER optional
Declare PtrSafe Function SetUnhandledExceptionFilter Lib "kernel32" ( _
    ByVal lpTopLevelExceptionFilter As LongPtr) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SetUnhandledExceptionFilter = ctypes.windll.kernel32.SetUnhandledExceptionFilter
SetUnhandledExceptionFilter.restype = ctypes.c_void_p
SetUnhandledExceptionFilter.argtypes = [
    ctypes.c_void_p,  # lpTopLevelExceptionFilter : LPTOP_LEVEL_EXCEPTION_FILTER optional
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('KERNEL32.dll')
SetUnhandledExceptionFilter = Fiddle::Function.new(
  lib['SetUnhandledExceptionFilter'],
  [
    Fiddle::TYPE_VOIDP,  # lpTopLevelExceptionFilter : LPTOP_LEVEL_EXCEPTION_FILTER optional
  ],
  Fiddle::TYPE_VOIDP)
#[link(name = "kernel32")]
extern "system" {
    fn SetUnhandledExceptionFilter(
        lpTopLevelExceptionFilter: *const core::ffi::c_void  // LPTOP_LEVEL_EXCEPTION_FILTER optional
    ) -> *const core::ffi::c_void;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("KERNEL32.dll")]
public static extern IntPtr SetUnhandledExceptionFilter(IntPtr lpTopLevelExceptionFilter);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_SetUnhandledExceptionFilter' -Namespace Win32 -PassThru
# $api::SetUnhandledExceptionFilter(lpTopLevelExceptionFilter)
#uselib "KERNEL32.dll"
#func global SetUnhandledExceptionFilter "SetUnhandledExceptionFilter" sptr
; SetUnhandledExceptionFilter lpTopLevelExceptionFilter   ; 戻り値は stat
; lpTopLevelExceptionFilter : LPTOP_LEVEL_EXCEPTION_FILTER optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "KERNEL32.dll"
#cfunc global SetUnhandledExceptionFilter "SetUnhandledExceptionFilter" sptr
; res = SetUnhandledExceptionFilter(lpTopLevelExceptionFilter)
; lpTopLevelExceptionFilter : LPTOP_LEVEL_EXCEPTION_FILTER optional -> "sptr"
; LPTOP_LEVEL_EXCEPTION_FILTER SetUnhandledExceptionFilter(LPTOP_LEVEL_EXCEPTION_FILTER lpTopLevelExceptionFilter)
#uselib "KERNEL32.dll"
#cfunc global SetUnhandledExceptionFilter "SetUnhandledExceptionFilter" intptr
; res = SetUnhandledExceptionFilter(lpTopLevelExceptionFilter)
; lpTopLevelExceptionFilter : LPTOP_LEVEL_EXCEPTION_FILTER optional -> "intptr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procSetUnhandledExceptionFilter = kernel32.NewProc("SetUnhandledExceptionFilter")
)

// lpTopLevelExceptionFilter (LPTOP_LEVEL_EXCEPTION_FILTER optional)
r1, _, err := procSetUnhandledExceptionFilter.Call(
	uintptr(lpTopLevelExceptionFilter),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // LPTOP_LEVEL_EXCEPTION_FILTER
function SetUnhandledExceptionFilter(
  lpTopLevelExceptionFilter: Pointer   // LPTOP_LEVEL_EXCEPTION_FILTER optional
): Pointer; stdcall;
  external 'KERNEL32.dll' name 'SetUnhandledExceptionFilter';
result := DllCall("KERNEL32\SetUnhandledExceptionFilter"
    , "Ptr", lpTopLevelExceptionFilter   ; LPTOP_LEVEL_EXCEPTION_FILTER optional
    , "Ptr")   ; return: LPTOP_LEVEL_EXCEPTION_FILTER
●SetUnhandledExceptionFilter(lpTopLevelExceptionFilter) = DLL("KERNEL32.dll", "void* SetUnhandledExceptionFilter(void*)")
# 呼び出し: SetUnhandledExceptionFilter(lpTopLevelExceptionFilter)
# lpTopLevelExceptionFilter : LPTOP_LEVEL_EXCEPTION_FILTER optional -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。