diff options
Diffstat (limited to 'BPQWinAPP.c')
| -rw-r--r-- | BPQWinAPP.c | 178 |
1 files changed, 144 insertions, 34 deletions
diff --git a/BPQWinAPP.c b/BPQWinAPP.c index f262d08..d70ef68 100644 --- a/BPQWinAPP.c +++ b/BPQWinAPP.c @@ -11,6 +11,11 @@ // Add try/except round main loop
+// Version 2.0.1.2 July 2026
+
+// Call RunBPQ32Background() every 10mS
+
+
#define _CRT_SECURE_NO_DEPRECATE
#include <windows.h>
@@ -21,9 +26,10 @@ #include <memory.h>
#include <time.h>
#include "DbgHelp.h"
+#include "winstdint.h"
//#define DYNLOADBPQ // Dynamically Load BPQ32.dll
-#include "..\Include\bpq32.h"
+#include "bpq32.h"
VOID APIENTRY SetFrameWnd(HWND hWnd);
@@ -45,19 +51,6 @@ LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM); HWND FrameWnd;
int TimerHandle = 0;
-
-VOID __cdecl Debugprintf(const char * format, ...)
-{
- char Mess[8192];
- va_list(arglist);int Len;
-
- va_start(arglist, format);
- Len = vsprintf_s(Mess, sizeof(Mess), format, arglist);
- strcat_s(Mess, 999, "\r\n");
- OutputDebugString(Mess);
- return;
-}
-
VOID WriteMiniDump()
{
#ifdef WIN32
@@ -88,6 +81,114 @@ VOID WriteMiniDump() }
+HANDLE process;
+
+void printStack()
+{
+ unsigned int i, n;
+ void * stack[ 100 ];
+ unsigned short frames;
+
+ DWORD dwDisplacement;
+ IMAGEHLP_LINE64 line;
+ char * fptr;
+
+ char buffer[sizeof(SYMBOL_INFO) + MAX_SYM_NAME * sizeof(TCHAR)];
+ PSYMBOL_INFO symbol = (PSYMBOL_INFO)buffer;
+
+ symbol->SizeOfStruct = sizeof(SYMBOL_INFO);
+ symbol->MaxNameLen = MAX_SYM_NAME;
+
+ Debugprintf("Stack Backtrace\r\n");
+
+ process = GetCurrentProcess();
+
+ SymSetOptions(SYMOPT_LOAD_LINES);
+ SymInitialize( process, NULL, TRUE );
+
+ frames = RtlCaptureStackBackTrace(0, 60, stack, NULL );
+
+ for( i = 0; i < frames; i++ )
+ {
+ n = SymGetLineFromAddr64(process, (DWORD64)stack[i], &dwDisplacement, &line);
+ n = SymFromAddr( process, ( DWORD64 )( stack[ i ] ), 0, symbol );
+
+ if (line.FileName)
+ {
+ fptr = line.FileName + (int)strlen(line.FileName); // remove path
+ while (*fptr != '\\' && *fptr != '/')
+ fptr--;
+
+ fptr++;
+
+ Debugprintf("%i: %s - %s Line %d Addr %p", frames - i - 1, symbol->Name, fptr, line.LineNumber, symbol->Address );
+ }
+ }
+}
+
+
+int inErrorhandling = 0;
+
+LONG WINAPI UnhandledExcepFilter(PEXCEPTION_POINTERS pExcepPointers)
+{
+ DWORD dwDisplacement;
+ IMAGEHLP_LINE64 line;
+ char * fptr;
+
+
+ time_t T;
+ struct tm * tm;
+
+ char buffer[sizeof(SYMBOL_INFO) + MAX_SYM_NAME * sizeof(TCHAR)];
+ PSYMBOL_INFO symbol = (PSYMBOL_INFO)buffer;
+
+ symbol->SizeOfStruct = sizeof(SYMBOL_INFO);
+ symbol->MaxNameLen = MAX_SYM_NAME;
+
+
+ T = time(NULL);
+ tm = gmtime(&T);
+
+ if (inErrorhandling)
+ {
+ MessageBox(NULL,"Program Error in error handler - program closing. See Debug Log for details","BPQ32",MB_ICONSTOP);
+
+ exit(0);
+ }
+
+ inErrorhandling = 1;
+
+ if(pExcepPointers->ExceptionRecord->ExceptionCode == DBG_PRINTEXCEPTION_C)
+ return EXCEPTION_CONTINUE_EXECUTION;
+
+ SymFromAddr( process, ((DWORD)pExcepPointers->ExceptionRecord->ExceptionAddress), 0, symbol );
+
+ Debugprintf("\r\n\r\nProgram error trapped at %02d:%02d:%02d\r\n", tm->tm_hour, tm->tm_min, tm->tm_sec);
+
+ SymGetLineFromAddr64(process, (DWORD)pExcepPointers->ExceptionRecord->ExceptionAddress, &dwDisplacement, &line);
+
+ if (line.FileName)
+ {
+ fptr = line.FileName + (int)strlen(line.FileName); // remove path
+ while (*fptr != '\\' && *fptr != '/')
+ fptr--;
+
+ fptr++;
+
+ Debugprintf("In Procedure %s - %s Line %d Addr %p\r\n", symbol->Name, fptr, line.LineNumber, symbol->Address );
+ }
+
+ printStack();
+
+ CloseDebugLog();
+
+
+ MessageBox(NULL,"Program Error - program closing. See Debug Log for details","BPQ32",MB_ICONSTOP);
+ RealCloseAllPrograms();
+ Sleep(1000);
+
+ exit(0);
+}
//
// FUNCTION: WinMain(HANDLE, HANDLE, LPSTR, int)
@@ -102,11 +203,17 @@ VOID WriteMiniDump() int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
MSG msg;
- BOOL bRet;
- struct _EXCEPTION_POINTERS exinfo;
+ int Running = 1;
Debugprintf("BPQ32.exe %s Entered", lpCmdLine);
+ process = GetCurrentProcess();
+
+ SymSetOptions(SYMOPT_LOAD_LINES);
+ SymInitialize( process, NULL, TRUE );
+
+ AddVectoredExceptionHandler(1, UnhandledExcepFilter);
+
if (_stricmp(lpCmdLine, "Wait") == 0) // If AutoRestart then Delay 5 Secs
Sleep(5000);
@@ -115,37 +222,40 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi if (!InitInstance(hInstance, nCmdShow))
return (FALSE);
+ RunBPQ32Background();
+
// Main message loop:
- __try
+// __try
{
-
- while( (bRet = GetMessage( &msg, NULL, 0, 0 )) != 0)
- {
- if (bRet == -1)
- {
- Debugprintf("GetMessage Returned -1 %d", GetLastError());
- break;
- }
- else
+ while(Running)
{
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- }
+ Sleep(10);
+
+ while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
+ {
+ TranslateMessage(&msg);
+ DispatchMessage(&msg);
+
+ if (msg.message == WM_QUIT)
+ Running = 0;
+ }
+ RunBPQ32Background();
+ }
}
- #define EXCEPTMSG "BPQ32.exe Main Loop"
- #include "StdExcept.c"
- }
+// #define EXCEPTMSG "BPQ32.exe Main Loop"
+// #include "StdExcept.c"
+// }
Debugprintf("BPQ32.exe exiting %d", msg.message);
KillTimer(NULL,TimerHandle);
CloseBPQ32(); // Close Ext Drivers if last bpq32 process
-
+ CloseDebugLog();
+
return (msg.wParam);
}
|
