' ########################################################################################
' Microsoft Windows
' File: werapi.inc
' Contents: This file contains the function prototypes for Windows Error Reporting (WER)
' Copyright (c) 2011 Jos? Roca
' Portions Copyright (c) Microsoft Corporation.
' All Rights Reserved.
' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
' EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
' MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
' ########################################################################################
#IF NOT %DEF(PBX_WERAPI_PBI)
#DEFINE PBX_WERAPI_PBI
%EQUATE `WERAPI_INC = 1
#INCLUDE ONCE "Core/Windows.inc"
'//////////////////////// Defines //////////////////////////////////////////////
'typedef HANDLE HREPORT;
'//
'// Do not add heap dumps for reports for the process
'//
%EQUATE `WER_FAULT_REPORTING_FLAG_NOHEAP = 1
'//
'// Queue critical reports for this process
'//
%EQUATE `WER_FAULT_REPORTING_FLAG_QUEUE = 2
'//
'// Do not suspend the process before error reporting
'//
%EQUATE `WER_FAULT_REPORTING_FLAG_DISABLE_THREAD_SUSPENSION = 4
'//
'// Queue critical reports for this process and upload from the queue
'//
%EQUATE `WER_FAULT_REPORTING_FLAG_QUEUE_UPLOAD = 8
'//
'// Fault reporting UI should always be shown. This is only applicable for interactive processes
'//
%EQUATE `WER_FAULT_REPORTING_ALWAYS_SHOW_UI = 16
'//
'// Maximum length of the report event name
'//
%EQUATE `WER_MAX_EVENT_NAME_LENGTH = 64
'//
'// Maximum length of the name of a signature element
'//
%EQUATE `WER_MAX_SIGNATURE_NAME_LENGTH = 128
'//
'// This is the maximum length of any created URL
'//
%EQUATE `WER_MAX_TOTAL_PARAM_LENGTH = 1720
'//
'// This is the maximum length of any parameter including the NULL character
'//
%EQUATE `WER_MAX_PARAM_LENGTH = %MAX_PATH
'//
'// Number of extra modules that we can select to get extra data in the minidump
'//
%EQUATE `WER_MAX_PREFERRED_MODULES = 128
%EQUATE `WER_MAX_PREFERRED_MODULES_BUFFER = 256
'//
'// Maximum number of parameters for a report
'//
%EQUATE `WER_MAX_PARAM_COUNT = 10
'//
'// The maximum size of memory block that can be registered
'//
%EQUATE `WER_MAX_MEM_BLOCK_SIZE = (64 * 1024)
'//
'// Event Type constant for application crashes
'//
'#define APPCRASH_EVENT L"APPCRASH"
$APPCRASH_EVENT = "APPCRASH"
'// Indexes for the parameter ids
%EQUATE `WER_P0 = 0
%EQUATE `WER_P1 = 1
%EQUATE `WER_P2 = 2
%EQUATE `WER_P3 = 3
%EQUATE `WER_P4 = 4
%EQUATE `WER_P5 = 5
%EQUATE `WER_P6 = 6
%EQUATE `WER_P7 = 7
%EQUATE `WER_P8 = 8
%EQUATE `WER_P9 = 9
'//
'// Custom error HRESULTS
'//
'// This error occurs if we are adding some parameter and this will cause the URL string to
'// exceed the maximum length
%EQUATE `WER_ERROR_START = &Hff00&
'#define WER_E_INSUFFICIENT_BUFFER (HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER))
%EQUATE `WER_E_INSUFFICIENT_BUFFER = &H8007007A&
'#define WER_E_NOT_FOUND (HRESULT_FROM_WIN32(ERROR_NOT_FOUND))
%EQUATE `WER_E_NOT_FOUND = &H80070490&
'#define WER_E_LENGTH_EXCEEDED (HRESULT_FROM_WIN32(ERROR_PARAMETER_QUOTA_EXCEEDED))
%EQUATE `WER_E_LENGTH_EXCEEDED = &H80070503&
'//
'// The API was called when it should not have been called. E.g trying to report the same
'// event twice when the first reportign is still going on
'#define WER_E_INVALID_STATE (HRESULT_FROM_WIN32(ERROR_INVALID_STATE))
%EQUATE `WER_E_INVALID_STATE = &H8007139F&
'// The store was disabled
'#define WER_E_STORE_DISABLED MAKE_HRESULT(SEVERITY_ERROR, FACILITY_WINDOWS, WER_ERROR_START + 3)
%EQUATE `WER_E_STORE_DISABLED = &H8008FF03&
'//
'// There were some params that were missing, i.e the coniditon index A < B < C and parameter at B is null
'// but parameters at A and C are not
'#define WER_E_MISSING_PARAM MAKE_HRESULT(SEVERITY_ERROR, FACILITY_WINDOWS, WER_ERROR_START + 5)
%EQUATE `WER_E_MISSING_PARAM = &H8008FF05&
'///////////////////////////////////////////////////////////////////////////////
'//
'// The enum that describes the indexes of the customizable UI strings
'//
' enum WER_REPORT_UI
%EQUATE `WerUIAdditionalDataDlgHeader = 1
%EQUATE `WerUIIconFilePath = 2
%EQUATE `WerUIConsentDlgHeader = 3
%EQUATE `WerUIConsentDlgBody = 4
%EQUATE `WerUIOnlineSolutionCheckText = 5
%EQUATE `WerUIOfflineSolutionCheckText = 6
%EQUATE `WerUICloseText = 7
%EQUATE `WerUICloseDlgHeader = 8
%EQUATE `WerUICloseDlgBody = 9
%EQUATE `WerUICloseDlgButtonText = 10
%EQUATE `WerUICustomActionButtonText = 11
%EQUATE `WerUIMax = 12
'//
'// The type of the registered files
'//
' enum WER_REGISTER_FILE_TYPE
%EQUATE `WerRegFileTypeUserDocument = 1
%EQUATE `WerRegFileTypeOther = 2
%EQUATE `WerRegFileTypeMax = 3
'//
'// The type of files that can be added to the report
'//
' enum WER_FILE_TYPE
%EQUATE `WerFileTypeMicrodump = 1
%EQUATE `WerFileTypeMinidump = 2
%EQUATE `WerFileTypeHeapdump = 3
%EQUATE `WerFileTypeUserDocument = 4
%EQUATE `WerFileTypeOther = 5
%EQUATE `WerFileTypeMax = 6
' enum WER_SUBMIT_RESULT
%EQUATE `WerReportQueued = 1
%EQUATE `WerReportUploaded = 2
%EQUATE `WerReportDebug = 3
%EQUATE `WerReportFailed = 4
%EQUATE `WerDisabled = 5
%EQUATE `WerReportCancelled = 6
%EQUATE `WerDisabledQueue = 7
%EQUATE `WerReportAsync = 8
%EQUATE `WerCustomAction = 9
'//
'// The type of the report
'//
' enum WER_REPORT_TYPE
%EQUATE `WerReportNonCritical = 0
%EQUATE `WerReportCritical = 1
%EQUATE `WerReportApplicationCrash = 2
%EQUATE `WerReportApplicationHang = 3
%EQUATE `WerReportKernel = 4
%EQUATE `WerReportInvalid = 5
'//
'// Flags that can be specified when adding a file to the report.
'//
'// NOTE: These should always occupy the lower 16 bits of the file flag dword.
'// The upper 16 bits are reserved for internal use and get cleared by WerAddFile.
'//
%EQUATE `WER_FILE_DELETE_WHEN_DONE = 1 ' // Delete the file once WER is done
%EQUATE `WER_FILE_ANONYMOUS_DATA = 2 ' // This file does not contain any PII
'//
'// Report submission flags.
'//
%EQUATE `WER_SUBMIT_HONOR_RECOVERY = 1 ' // show recovery option
%EQUATE `WER_SUBMIT_HONOR_RESTART = 2 ' // show application restart option
%EQUATE `WER_SUBMIT_QUEUE = 4 ' // report directly to queue
%EQUATE `WER_SUBMIT_SHOW_DEBUG = 8 ' // show the debug button
%EQUATE `WER_SUBMIT_ADD_REGISTERED_DATA = 16 ' // Add registered data to the WER report
%EQUATE `WER_SUBMIT_OUTOFPROCESS = 32 ' // Force the report to go out of process
%EQUATE `WER_SUBMIT_NO_CLOSE_UI = 64 ' // Do not show the close dialog for the critical report
%EQUATE `WER_SUBMIT_NO_QUEUE = 128 ' // Do not queue the report
%EQUATE `WER_SUBMIT_NO_ARCHIVE = 256 ' // Do not archive the report
%EQUATE `WER_SUBMIT_START_MINIMIZED = 512 ' // The initial reporting UI is minimized and will flash
%EQUATE `WER_SUBMIT_OUTOFPROCESS_ASYNC = 1024 ' // The initial reporting UI is minimized and will flash
%EQUATE `WER_SUBMIT_BYPASS_DATA_THROTTLING = 2048 ' // Bypass data throttling for the report
%EQUATE `WER_SUBMIT_ARCHIVE_PARAMETERS_ONLY = 4096 ' // Archive only the parameters; the cab is discarded
%EQUATE `WER_SUBMIT_REPORT_MACHINE_ID = 8192 ' // Always send the machine ID, regardless of the consent the report was submitted with
' // Size = 2196 bytes
TYPE WER_REPORT_INFORMATION DWORD
 dwSize AS DWORD
 hProcess AS DWORD
 wzConsentKey AS WSTRINGZ * 64 ' WCHAR[64]
 wzFriendlyEventName AS WSTRINGZ * 128 ' WCHAR[128]
 wzApplicationName AS WSTRINGZ * 128 ' WCHAR[128]
 wzApplicationPath AS WSTRINGZ * %MAX_PATH ' WCHAR[MAX_PATH]
 wzDescription AS WSTRINGZ * 512 ' WCHAR[512]
 hwndParent AS DWORD
END TYPE
' // Size = 552 bytes
TYPE WER_DUMP_CUSTOM_OPTIONS DWORD
 dwSize AS DWORD
 dwMask AS DWORD
 dwDumpFlags AS DWORD
 bOnlyThisThread AS LONG
 dwExceptionThreadFlags AS DWORD
 dwOtherThreadFlags AS DWORD
 dwExceptionThreadExFlags AS DWORD
 dwOtherThreadExFlags AS DWORD
 dwPreferredModuleFlags AS DWORD
 dwOtherModuleFlags AS DWORD
 wzPreferredModuleList AS STRING * %WER_MAX_PREFERRED_MODULES_BUFFER * 2 ' WCHAR
END TYPE
' // Size = 8 bytes
TYPE WER_EXCEPTION_INFORMATION DWORD
 pExceptionPointers AS EXCEPTION_POINTERS PTR ' PEXCEPTION_POINTERS
 bClientPointers AS LONG
END TYPE
' enum WER_CONSENT
%EQUATE `WerConsentNotAsked = 1
%EQUATE `WerConsentApproved = 2
%EQUATE `WerConsentDenied = 3
%EQUATE `WerConsentAlwaysPrompt = 4
%EQUATE `WerConsentMax = 5
DECLARE FUNCTION WerReportCreate LIB "wer.dll" ALIAS "WerReportCreate" ( BYREF pwzEventType AS WSTRINGZ , BYVAL repType AS LONG , BYREF pReportInformation AS WER_REPORT_INFORMATION , BYREF phReportHandle AS QUAD ) AS LONG
DECLARE FUNCTION WerReportSetParameter LIB "wer.dll" ALIAS "WerReportSetParameter" ( BYVAL hReportHandle AS QUAD
 , BYVAL dwparamID AS DWORD
 , BYREF pwzName AS WSTRINGZ
 , BYREF pwzValue AS WSTRINGZ
 ) AS LONG
DECLARE FUNCTION WerReportAddFile LIB "wer.dll" ALIAS "WerReportAddFile" ( BYVAL hReportHandle AS DWORD
 , BYREF pwzPath AS WSTRINGZ
 , BYVAL repFileType AS LONG
 , BYVAL dwFileFlags AS DWORD
 ) AS LONG
DECLARE FUNCTION WerReportSetUIOption LIB "wer.dll" ALIAS "WerReportSetUIOption" ( BYVAL hReportHandle AS DWORD
 , BYVAL repUITypeID AS LONG
 , BYREF pwzValue AS WSTRINGZ
 ) AS LONG
DECLARE FUNCTION WerReportSubmit LIB "wer.dll" ALIAS "WerReportSubmit" ( BYVAL hReportHandle AS DWORD
 , BYVAL consent AS LONG
 , BYVAL dwFlags AS DWORD
 , BYREF pSubmitResult AS LONG
 ) AS LONG
'//
'// Masks to be used for customizing the dump
'//
%EQUATE `WER_DUMP_MASK_START = 1 ' 1
%EQUATE `WER_DUMP_MASK_DUMPTYPE = &H1 ' (WER_DUMP_MASK_START << 0)
%EQUATE `WER_DUMP_MASK_ONLY_THISTHREAD = &H2 ' (WER_DUMP_MASK_START << 1)
%EQUATE `WER_DUMP_MASK_THREADFLAGS = &H4 ' (WER_DUMP_MASK_START << 2)
%EQUATE `WER_DUMP_MASK_THREADFLAGS_EX = &H8 ' (WER_DUMP_MASK_START << 3)
%EQUATE `WER_DUMP_MASK_OTHERTHREADFLAGS = &H10 ' (WER_DUMP_MASK_START << 4)
%EQUATE `WER_DUMP_MASK_OTHERTHREADFLAGS_EX = &H20 ' (WER_DUMP_MASK_START << 5)
%EQUATE `WER_DUMP_MASK_PREFERRED_MODULESFLAGS = &H40 ' (WER_DUMP_MASK_START << 6)
%EQUATE `WER_DUMP_MASK_OTHER_MODULESFLAGS = &H80 ' (WER_DUMP_MASK_START << 7)
%EQUATE `WER_DUMP_MASK_PREFERRED_MODULE_LIST = &H100 ' (WER_DUMP_MASK_START << 8)
'//
'// WER dump flags
'//
%EQUATE `WER_DUMP_NOHEAP_ONQUEUE = 1
' enum WER_DUMP_TYPE
%EQUATE `WerDumpTypeMicroDump = 1
%EQUATE `WerDumpTypeMiniDump = 2
%EQUATE `WerDumpTypeHeapDump = 3
%EQUATE `WerDumpTypeMax = 4
DECLARE FUNCTION WerReportAddDump LIB "wer.dll" ALIAS "WerReportAddDump" ( BYVAL hReportHandle AS QUAD , BYVAL hProcess AS QUAD , BYVAL hThread AS QUAD , BYVAL dumpType AS LONG , BYREF pExceptionParam AS WER_EXCEPTION_INFORMATION , BYREF WER_DUMP_CUSTOM_OPTIONS , BYVAL pDumpCustomOptions AS QUAD ) AS LONG
DECLARE FUNCTION WerReportCloseHandle LIB "wer.dll" ALIAS "WerReportCloseHandle" ( BYVAL hReportHandle AS QUAD
 ) AS LONG
'//
'// ++++++++++++++++++++++++++ Registration APIs ++++++++++++++++++++++++++++++++++++++
'//
%EQUATE `WER_MAX_REGISTERED_ENTRIES = 512
DECLARE FUNCTION WerRegisterFile LIB "kernel32.dll" ALIAS "WerRegisterFile" ( BYREF pwzFile AS WSTRINGZ , BYVAL regFileType AS LONG , BYVAL dwFlags AS QUAD ) AS LONG
DECLARE FUNCTION WerUnregisterFile LIB "kernel32.dll" ALIAS "WerUnregisterFile" ( BYREF pwzFilePath AS WSTRINGZ
 ) AS LONG
DECLARE FUNCTION WerRegisterMemoryBlock LIB "kernel32.dll" ALIAS "WerRegisterMemoryBlock" ( BYVAL pvAddress AS DWORD
 , BYVAL dwSize AS DWORD
 ) AS LONG
DECLARE FUNCTION WerUnregisterMemoryBlock LIB "kernel32.dll" ALIAS "WerUnregisterMemoryBlock" ( BYVAL pvAddress AS DWORD
 ) AS LONG
DECLARE FUNCTION WerSetFlags LIB "kernel32.dll" ALIAS "WerSetFlags" ( BYVAL dwFlags AS DWORD
 ) AS LONG
DECLARE FUNCTION WerGetFlags LIB "kernel32.dll" ALIAS "WerGetFlags" ( BYVAL hProcess AS DWORD
 , BYREF pdwFlags AS DWORD
 ) AS LONG
'//
'// ++++++++++++++++++++++++++ Application Setup APIs ++++++++++++++++++++++++++++++++++++++
'//
DECLARE FUNCTION WerAddExcludedApplication LIB "wer.dll" ALIAS "WerAddExcludedApplication" ( BYREF pwzExeName AS WSTRINGZ , BYVAL bAllUsers AS LONG ) AS LONG
DECLARE FUNCTION WerRemoveExcludedApplication LIB "wer.dll" ALIAS "WerRemoveExcludedApplication" ( BYREF pwzExeName AS WSTRINGZ
 , BYVAL bAllUsers AS LONG
 ) AS LONG
'//
'// ++++++++++++++++++++++++++ Run time handler APIs +++++++++++++++++++++++++++
'//
%EQUATE `WER_MAX_REGISTERED_RUNTIME_EXCEPTION_MODULES = 16
DECLARE FUNCTION WerRegisterRuntimeExceptionModule LIB "kernel32.dll" ALIAS "WerRegisterRuntimeExceptionModule" ( BYREF pwszOutOfProcessCallbackDll AS WSTRINGZ , BYVAL pContext AS QUAD ) AS LONG
DECLARE FUNCTION WerUnregisterRuntimeExceptionModule LIB "kernel32.dll" ALIAS "WerUnregisterRuntimeExceptionModule" ( BYREF pwszOutOfProcessCallbackDll AS WSTRINGZ
 , BYVAL pContext AS DWORD
 ) AS LONG
$WER_RUNTIME_EXCEPTION_EVENT_FUNCTION = "OutOfProcessExceptionEventCallback"
$WER_RUNTIME_EXCEPTION_EVENT_SIGNATURE_FUNCTION = "OutOfProcessExceptionEventSignatureCallback"
$WER_RUNTIME_EXCEPTION_DEBUGGER_LAUNCH = "OutOfProcessExceptionEventDebuggerLaunchCallback"
' // Size = 812 bytes
TYPE WER_RUNTIME_EXCEPTION_INFORMATION DWORD
 dwSize AS DWORD
 hProcess AS DWORD
 hThread AS DWORD
 exceptionRecord AS EXCEPTION_RECORD ' EXCEPTION_RECORD
 context AS CONTEXT ' CONTEXT
 pwszReportId AS WSTRINGZ PTR
END TYPE
'typedef
'(* PFN_WER_RUNTIME_EXCEPTION_EVENT)(
' );
'FUNCTION WER_RUNTIME_EXCEPTION_EVENT ( ' BYVAL pContext AS DWORD
' , BYREF pExceptionInformation AS WER_RUNTIME_EXCEPTION_INFORMATION
' , BYREF pbOwnershipClaimed AS LONG
' , BYREF pwszEventName AS WSTRINGZ
' , BYREF pchSize AS DWORD
' , BYREF pdwSignatureCount AS DWORD
' ) AS LONG
'typedef
'(* PFN_WER_RUNTIME_EXCEPTION_EVENT_SIGNATURE)(
' );
'FUNCTION WER_RUNTIME_EXCEPTION_EVENT_SIGNATURE ( ' BYVAL pContext AS DWORD
' , BYREF pExceptionInformation AS WER_RUNTIME_EXCEPTION_INFORMATION
' , BYVAL dwIndex AS DWORD
' , BYREF pwszName AS WSTRINGZ
' , BYREF pchName AS DWORD
' , BYREF pwszValue AS WSTRINGZ
' , BYREF pchValue AS DWORD
' ) AS LONG
'typedef
'(* PFN_WER_RUNTIME_EXCEPTION_DEBUGGER_LAUNCH)(
' );
'FUNCTION WER_RUNTIME_EXCEPTION_DEBUGGER_LAUNCH ( ' BYVAL pContext AS DWORD
' , BYREF pExceptionInformation AS WER_RUNTIME_EXCEPTION_INFORMATION
' , BYREF pbIsCustomDebugger AS LONG
' , BYREF pwszDebuggerLaunch AS WSTRINGZ
' , BYREF pchDebuggerLaunch AS DWORD
' , BYREF pbIsDebuggerAutolaunch AS LONG
' ) AS LONG
#ENDIF
