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

RegisterApplicationRecoveryCallback

関数
アプリ障害時の回復用コールバック関数を登録する。
DLLKERNEL32.dll呼出規約winapi対応OSWindows Vista 以降

シグネチャ

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

HRESULT RegisterApplicationRecoveryCallback(
    APPLICATION_RECOVERY_CALLBACK pRecoveyCallback,
    void* pvParameter,   // optional
    DWORD dwPingInterval,
    DWORD dwFlags
);

パラメーター

名前方向説明
pRecoveyCallbackAPPLICATION_RECOVERY_CALLBACKinアプリのハング/クラッシュ時にWERから呼ばれる復旧コールバック関数へのポインタ。
pvParametervoid*inoptional復旧コールバックへ渡すユーザー定義データへのポインタ。NULL可。
dwPingIntervalDWORDin復旧処理の進行を報告すべき間隔(ミリ秒)を示すDWORD。
dwFlagsDWORDin予約済みのフラグ。通常は0を指定する。

戻り値の型: HRESULT

各言語での呼び出し定義

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

HRESULT RegisterApplicationRecoveryCallback(
    APPLICATION_RECOVERY_CALLBACK pRecoveyCallback,
    void* pvParameter,   // optional
    DWORD dwPingInterval,
    DWORD dwFlags
);
[DllImport("KERNEL32.dll", ExactSpelling = true)]
static extern int RegisterApplicationRecoveryCallback(
    IntPtr pRecoveyCallback,   // APPLICATION_RECOVERY_CALLBACK
    IntPtr pvParameter,   // void* optional
    uint dwPingInterval,   // DWORD
    uint dwFlags   // DWORD
);
<DllImport("KERNEL32.dll", ExactSpelling:=True)>
Public Shared Function RegisterApplicationRecoveryCallback(
    pRecoveyCallback As IntPtr,   ' APPLICATION_RECOVERY_CALLBACK
    pvParameter As IntPtr,   ' void* optional
    dwPingInterval As UInteger,   ' DWORD
    dwFlags As UInteger   ' DWORD
) As Integer
End Function
' pRecoveyCallback : APPLICATION_RECOVERY_CALLBACK
' pvParameter : void* optional
' dwPingInterval : DWORD
' dwFlags : DWORD
Declare PtrSafe Function RegisterApplicationRecoveryCallback Lib "kernel32" ( _
    ByVal pRecoveyCallback As LongPtr, _
    ByVal pvParameter As LongPtr, _
    ByVal dwPingInterval As Long, _
    ByVal dwFlags As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

RegisterApplicationRecoveryCallback = ctypes.windll.kernel32.RegisterApplicationRecoveryCallback
RegisterApplicationRecoveryCallback.restype = ctypes.c_int
RegisterApplicationRecoveryCallback.argtypes = [
    ctypes.c_void_p,  # pRecoveyCallback : APPLICATION_RECOVERY_CALLBACK
    ctypes.POINTER(None),  # pvParameter : void* optional
    wintypes.DWORD,  # dwPingInterval : DWORD
    wintypes.DWORD,  # dwFlags : DWORD
]
require 'fiddle'
require 'fiddle/import'

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

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procRegisterApplicationRecoveryCallback = kernel32.NewProc("RegisterApplicationRecoveryCallback")
)

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

extern "kernel32" fn RegisterApplicationRecoveryCallback(
    pRecoveyCallback: ?*anyopaque, // APPLICATION_RECOVERY_CALLBACK
    pvParameter: ?*anyopaque, // void* optional
    dwPingInterval: u32, // DWORD
    dwFlags: u32 // DWORD
) callconv(std.os.windows.WINAPI) i32;
proc RegisterApplicationRecoveryCallback(
    pRecoveyCallback: pointer,  # APPLICATION_RECOVERY_CALLBACK
    pvParameter: pointer,  # void* optional
    dwPingInterval: uint32,  # DWORD
    dwFlags: uint32  # DWORD
): int32 {.importc: "RegisterApplicationRecoveryCallback", stdcall, dynlib: "KERNEL32.dll".}
pragma(lib, "kernel32");
extern(Windows)
int RegisterApplicationRecoveryCallback(
    void* pRecoveyCallback,   // APPLICATION_RECOVERY_CALLBACK
    void* pvParameter,   // void* optional
    uint dwPingInterval,   // DWORD
    uint dwFlags   // DWORD
);
ccall((:RegisterApplicationRecoveryCallback, "KERNEL32.dll"), stdcall, Int32,
      (Ptr{Cvoid}, Ptr{Cvoid}, UInt32, UInt32),
      pRecoveyCallback, pvParameter, dwPingInterval, dwFlags)
# pRecoveyCallback : APPLICATION_RECOVERY_CALLBACK -> Ptr{Cvoid}
# pvParameter : void* optional -> Ptr{Cvoid}
# dwPingInterval : DWORD -> UInt32
# dwFlags : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t RegisterApplicationRecoveryCallback(
    void* pRecoveyCallback,
    void* pvParameter,
    uint32_t dwPingInterval,
    uint32_t dwFlags);
]]
local kernel32 = ffi.load("kernel32")
-- kernel32.RegisterApplicationRecoveryCallback(pRecoveyCallback, pvParameter, dwPingInterval, dwFlags)
-- pRecoveyCallback : APPLICATION_RECOVERY_CALLBACK
-- pvParameter : void* optional
-- dwPingInterval : DWORD
-- dwFlags : DWORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('KERNEL32.dll');
const RegisterApplicationRecoveryCallback = lib.func('__stdcall', 'RegisterApplicationRecoveryCallback', 'int32_t', ['void *', 'void *', 'uint32_t', 'uint32_t']);
// RegisterApplicationRecoveryCallback(pRecoveyCallback, pvParameter, dwPingInterval, dwFlags)
// pRecoveyCallback : APPLICATION_RECOVERY_CALLBACK -> 'void *'
// pvParameter : void* optional -> 'void *'
// dwPingInterval : DWORD -> 'uint32_t'
// dwFlags : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
// コールバック(関数ポインタ)は koffi.proto/koffi.register で型を定義して渡す(素の void* では JS 関数を渡せない)。
const lib = Deno.dlopen("KERNEL32.dll", {
  RegisterApplicationRecoveryCallback: { parameters: ["pointer", "pointer", "u32", "u32"], result: "i32" },
});
// lib.symbols.RegisterApplicationRecoveryCallback(pRecoveyCallback, pvParameter, dwPingInterval, dwFlags)
// pRecoveyCallback : APPLICATION_RECOVERY_CALLBACK -> "pointer"
// pvParameter : void* optional -> "pointer"
// dwPingInterval : DWORD -> "u32"
// dwFlags : DWORD -> "u32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t RegisterApplicationRecoveryCallback(
    void* pRecoveyCallback,
    void* pvParameter,
    uint32_t dwPingInterval,
    uint32_t dwFlags);
C, "KERNEL32.dll");
// $ffi->RegisterApplicationRecoveryCallback(pRecoveyCallback, pvParameter, dwPingInterval, dwFlags);
// pRecoveyCallback : APPLICATION_RECOVERY_CALLBACK
// pvParameter : void* optional
// dwPingInterval : DWORD
// dwFlags : 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 Kernel32 extends StdCallLibrary {
    Kernel32 INSTANCE = Native.load("kernel32", Kernel32.class);
    int RegisterApplicationRecoveryCallback(
        Callback pRecoveyCallback,   // APPLICATION_RECOVERY_CALLBACK
        Pointer pvParameter,   // void* optional
        int dwPingInterval,   // DWORD
        int dwFlags   // DWORD
    );
}
@[Link("kernel32")]
lib LibKERNEL32
  fun RegisterApplicationRecoveryCallback = RegisterApplicationRecoveryCallback(
    pRecoveyCallback : Void*,   # APPLICATION_RECOVERY_CALLBACK
    pvParameter : Void*,   # void* optional
    dwPingInterval : UInt32,   # DWORD
    dwFlags : 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 RegisterApplicationRecoveryCallbackNative = Int32 Function(Pointer<Void>, Pointer<Void>, Uint32, Uint32);
typedef RegisterApplicationRecoveryCallbackDart = int Function(Pointer<Void>, Pointer<Void>, int, int);
final RegisterApplicationRecoveryCallback = DynamicLibrary.open('KERNEL32.dll')
    .lookupFunction<RegisterApplicationRecoveryCallbackNative, RegisterApplicationRecoveryCallbackDart>('RegisterApplicationRecoveryCallback');
// pRecoveyCallback : APPLICATION_RECOVERY_CALLBACK -> Pointer<Void>
// pvParameter : void* optional -> Pointer<Void>
// dwPingInterval : DWORD -> Uint32
// dwFlags : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function RegisterApplicationRecoveryCallback(
  pRecoveyCallback: Pointer;   // APPLICATION_RECOVERY_CALLBACK
  pvParameter: Pointer;   // void* optional
  dwPingInterval: DWORD;   // DWORD
  dwFlags: DWORD   // DWORD
): Integer; stdcall;
  external 'KERNEL32.dll' name 'RegisterApplicationRecoveryCallback';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "RegisterApplicationRecoveryCallback"
  c_RegisterApplicationRecoveryCallback :: Ptr () -> Ptr () -> Word32 -> Word32 -> IO Int32
-- pRecoveyCallback : APPLICATION_RECOVERY_CALLBACK -> Ptr ()
-- pvParameter : void* optional -> Ptr ()
-- dwPingInterval : DWORD -> Word32
-- dwFlags : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let registerapplicationrecoverycallback =
  foreign "RegisterApplicationRecoveryCallback"
    ((ptr void) @-> (ptr void) @-> uint32_t @-> uint32_t @-> returning int32_t)
(* pRecoveyCallback : APPLICATION_RECOVERY_CALLBACK -> (ptr void) *)
(* pvParameter : void* optional -> (ptr void) *)
(* dwPingInterval : DWORD -> uint32_t *)
(* dwFlags : DWORD -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library kernel32 (t "KERNEL32.dll"))
(cffi:use-foreign-library kernel32)

(cffi:defcfun ("RegisterApplicationRecoveryCallback" register-application-recovery-callback :convention :stdcall) :int32
  (p-recovey-callback :pointer)   ; APPLICATION_RECOVERY_CALLBACK
  (pv-parameter :pointer)   ; void* optional
  (dw-ping-interval :uint32)   ; DWORD
  (dw-flags :uint32))   ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $RegisterApplicationRecoveryCallback = Win32::API::More->new('KERNEL32',
    'int RegisterApplicationRecoveryCallback(LPVOID pRecoveyCallback, LPVOID pvParameter, DWORD dwPingInterval, DWORD dwFlags)');
# my $ret = $RegisterApplicationRecoveryCallback->Call($pRecoveyCallback, $pvParameter, $dwPingInterval, $dwFlags);
# pRecoveyCallback : APPLICATION_RECOVERY_CALLBACK -> LPVOID
# pvParameter : void* optional -> LPVOID
# dwPingInterval : DWORD -> DWORD
# dwFlags : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# コールバック(関数ポインタ)は Perl sub を直接渡せません。Win32::API::Callback を使用してください。

関連項目

使用する型