ホーム › System.Diagnostics.Debug › RaiseException
RaiseException
関数指定したコードとフラグでソフトウェア例外を発生させる。
シグネチャ
// KERNEL32.dll
#include <windows.h>
void RaiseException(
DWORD dwExceptionCode,
DWORD dwExceptionFlags,
DWORD nNumberOfArguments,
const UINT_PTR* lpArguments // optional
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| dwExceptionCode | DWORD | in |
| dwExceptionFlags | DWORD | in |
| nNumberOfArguments | DWORD | in |
| lpArguments | UINT_PTR* | inoptional |
戻り値の型: void
各言語での呼び出し定義
// KERNEL32.dll
#include <windows.h>
void RaiseException(
DWORD dwExceptionCode,
DWORD dwExceptionFlags,
DWORD nNumberOfArguments,
const UINT_PTR* lpArguments // optional
);[DllImport("KERNEL32.dll", ExactSpelling = true)]
static extern void RaiseException(
uint dwExceptionCode, // DWORD
uint dwExceptionFlags, // DWORD
uint nNumberOfArguments, // DWORD
IntPtr lpArguments // UINT_PTR* optional
);<DllImport("KERNEL32.dll", ExactSpelling:=True)>
Public Shared Sub RaiseException(
dwExceptionCode As UInteger, ' DWORD
dwExceptionFlags As UInteger, ' DWORD
nNumberOfArguments As UInteger, ' DWORD
lpArguments As IntPtr ' UINT_PTR* optional
)
End Sub' dwExceptionCode : DWORD
' dwExceptionFlags : DWORD
' nNumberOfArguments : DWORD
' lpArguments : UINT_PTR* optional
Declare PtrSafe Sub RaiseException Lib "kernel32" ( _
ByVal dwExceptionCode As Long, _
ByVal dwExceptionFlags As Long, _
ByVal nNumberOfArguments As Long, _
ByVal lpArguments As LongPtr)
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
RaiseException = ctypes.windll.kernel32.RaiseException
RaiseException.restype = None
RaiseException.argtypes = [
wintypes.DWORD, # dwExceptionCode : DWORD
wintypes.DWORD, # dwExceptionFlags : DWORD
wintypes.DWORD, # nNumberOfArguments : DWORD
ctypes.POINTER(ctypes.c_size_t), # lpArguments : UINT_PTR* optional
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('KERNEL32.dll')
RaiseException = Fiddle::Function.new(
lib['RaiseException'],
[
-Fiddle::TYPE_INT, # dwExceptionCode : DWORD
-Fiddle::TYPE_INT, # dwExceptionFlags : DWORD
-Fiddle::TYPE_INT, # nNumberOfArguments : DWORD
Fiddle::TYPE_VOIDP, # lpArguments : UINT_PTR* optional
],
Fiddle::TYPE_VOID)#[link(name = "kernel32")]
extern "system" {
fn RaiseException(
dwExceptionCode: u32, // DWORD
dwExceptionFlags: u32, // DWORD
nNumberOfArguments: u32, // DWORD
lpArguments: *const usize // UINT_PTR* optional
);
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("KERNEL32.dll")]
public static extern void RaiseException(uint dwExceptionCode, uint dwExceptionFlags, uint nNumberOfArguments, IntPtr lpArguments);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_RaiseException' -Namespace Win32 -PassThru
# $api::RaiseException(dwExceptionCode, dwExceptionFlags, nNumberOfArguments, lpArguments)#uselib "KERNEL32.dll"
#func global RaiseException "RaiseException" sptr, sptr, sptr, sptr
; RaiseException dwExceptionCode, dwExceptionFlags, nNumberOfArguments, varptr(lpArguments)
; dwExceptionCode : DWORD -> "sptr"
; dwExceptionFlags : DWORD -> "sptr"
; nNumberOfArguments : DWORD -> "sptr"
; lpArguments : UINT_PTR* optional -> "sptr"出力引数:
#uselib "KERNEL32.dll" #func global RaiseException "RaiseException" int, int, int, var ; RaiseException dwExceptionCode, dwExceptionFlags, nNumberOfArguments, lpArguments ; dwExceptionCode : DWORD -> "int" ; dwExceptionFlags : DWORD -> "int" ; nNumberOfArguments : DWORD -> "int" ; lpArguments : UINT_PTR* optional -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "KERNEL32.dll" #func global RaiseException "RaiseException" int, int, int, sptr ; RaiseException dwExceptionCode, dwExceptionFlags, nNumberOfArguments, varptr(lpArguments) ; dwExceptionCode : DWORD -> "int" ; dwExceptionFlags : DWORD -> "int" ; nNumberOfArguments : DWORD -> "int" ; lpArguments : UINT_PTR* optional -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; void RaiseException(DWORD dwExceptionCode, DWORD dwExceptionFlags, DWORD nNumberOfArguments, UINT_PTR* lpArguments) #uselib "KERNEL32.dll" #func global RaiseException "RaiseException" int, int, int, var ; RaiseException dwExceptionCode, dwExceptionFlags, nNumberOfArguments, lpArguments ; dwExceptionCode : DWORD -> "int" ; dwExceptionFlags : DWORD -> "int" ; nNumberOfArguments : DWORD -> "int" ; lpArguments : UINT_PTR* optional -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; void RaiseException(DWORD dwExceptionCode, DWORD dwExceptionFlags, DWORD nNumberOfArguments, UINT_PTR* lpArguments) #uselib "KERNEL32.dll" #func global RaiseException "RaiseException" int, int, int, intptr ; RaiseException dwExceptionCode, dwExceptionFlags, nNumberOfArguments, varptr(lpArguments) ; dwExceptionCode : DWORD -> "int" ; dwExceptionFlags : DWORD -> "int" ; nNumberOfArguments : DWORD -> "int" ; lpArguments : UINT_PTR* optional -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
procRaiseException = kernel32.NewProc("RaiseException")
)
// dwExceptionCode (DWORD), dwExceptionFlags (DWORD), nNumberOfArguments (DWORD), lpArguments (UINT_PTR* optional)
r1, _, err := procRaiseException.Call(
uintptr(dwExceptionCode),
uintptr(dwExceptionFlags),
uintptr(nNumberOfArguments),
uintptr(lpArguments),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // voidprocedure RaiseException(
dwExceptionCode: DWORD; // DWORD
dwExceptionFlags: DWORD; // DWORD
nNumberOfArguments: DWORD; // DWORD
lpArguments: Pointer // UINT_PTR* optional
); stdcall;
external 'KERNEL32.dll' name 'RaiseException';result := DllCall("KERNEL32\RaiseException"
, "UInt", dwExceptionCode ; DWORD
, "UInt", dwExceptionFlags ; DWORD
, "UInt", nNumberOfArguments ; DWORD
, "Ptr", lpArguments ; UINT_PTR* optional
, "Int") ; return: void●RaiseException(dwExceptionCode, dwExceptionFlags, nNumberOfArguments, lpArguments) = DLL("KERNEL32.dll", "int RaiseException(dword, dword, dword, void*)")
# 呼び出し: RaiseException(dwExceptionCode, dwExceptionFlags, nNumberOfArguments, lpArguments)
# dwExceptionCode : DWORD -> "dword"
# dwExceptionFlags : DWORD -> "dword"
# nNumberOfArguments : DWORD -> "dword"
# lpArguments : UINT_PTR* optional -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。