forked from g8bpq/linbpq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BPQWinAPP.c
246 lines (175 loc) · 5.48 KB
/
BPQWinAPP.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
// Version 1. 0. 2. 1 October 2010
// Add Delay on start option, and dynamically load bpq32
// Version 1. 0. 3. 1 October 2011
// Call CloseBPQ32 on exit
// Version 2.0.1.1 July 2002
// Add try/except round main loop
#define _CRT_SECURE_NO_DEPRECATE
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
#include <malloc.h>
#include <memory.h>
#include <time.h>
#include "DbgHelp.h"
//#define DYNLOADBPQ // Dynamically Load BPQ32.dll
#include "..\Include\bpq32.h"
VOID APIENTRY SetFrameWnd(HWND hWnd);
#define BPQICON 400
HINSTANCE hInst;
char AppName[] = "BPQ32";
char Title[80] = "Program to hold BPQ32.dll in memory";
// Foward declarations of functions included in this code module:
ATOM MyRegisterClass(CONST WNDCLASS*);
BOOL InitApplication(HINSTANCE);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK FrameWndProc(HWND, UINT, WPARAM, LPARAM);
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
HANDLE hFile;
BOOL ret;
char FN[256];
sprintf(FN, "%s/Logs/MiniDump%x.dmp", GetBPQDirectory(), time(NULL));
hFile = CreateFile(FN, GENERIC_READ | GENERIC_WRITE,
0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if((hFile != NULL) && (hFile != INVALID_HANDLE_VALUE))
{
// Create the minidump
ret = MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(),
hFile, MiniDumpNormal, 0, 0, 0 );
if(!ret)
Debugprintf("MiniDumpWriteDump failed. Error: %u", GetLastError());
else
Debugprintf("Minidump %s created.", FN);
CloseHandle(hFile);
}
#endif
}
//
// FUNCTION: WinMain(HANDLE, HANDLE, LPSTR, int)
//
// PURPOSE: Entry point for the application.
//
// COMMENTS:
//
// This function initializes the application and processes the
// message loop.
//
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
MSG msg;
BOOL bRet;
struct _EXCEPTION_POINTERS exinfo;
Debugprintf("BPQ32.exe %s Entered", lpCmdLine);
if (_stricmp(lpCmdLine, "Wait") == 0) // If AutoRestart then Delay 5 Secs
Sleep(5000);
// GetAPI();
if (!InitInstance(hInstance, nCmdShow))
return (FALSE);
// Main message loop:
__try
{
while( (bRet = GetMessage( &msg, NULL, 0, 0 )) != 0)
{
if (bRet == -1)
{
Debugprintf("GetMessage Returned -1 %d", GetLastError());
break;
}
else
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
}
#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
return (msg.wParam);
}
//
//
// FUNCTION: InitInstance(HANDLE, int)
//
// PURPOSE: Saves instance handle and creates main window
//
// COMMENTS:
//
// In this function, we save the instance handle in a global variable and
// create and display the main program window.
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
WNDCLASSEX wndclassMainFrame;
hInst = hInstance; // Store instance handle in our global variable
wndclassMainFrame.cbSize = sizeof(WNDCLASSEX);
wndclassMainFrame.style = CS_HREDRAW | CS_VREDRAW;
wndclassMainFrame.lpfnWndProc = FrameWndProc;
wndclassMainFrame.cbClsExtra = 0;
wndclassMainFrame.cbWndExtra = 0;
wndclassMainFrame.hInstance = hInstance;
wndclassMainFrame.hIcon = LoadIcon( hInstance, MAKEINTRESOURCE(BPQICON));
wndclassMainFrame.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclassMainFrame.hbrBackground = (HBRUSH) GetStockObject(GRAY_BRUSH);
wndclassMainFrame.lpszMenuName = NULL;
wndclassMainFrame.lpszClassName = AppName;
wndclassMainFrame.hIconSm = NULL;
if(!RegisterClassEx(&wndclassMainFrame))
{
Debugprintf("BPQ32.exe RC failed %d", GetLastError());
return 0;
}
FrameWnd = CreateWindow(AppName,
"BPQ32",
WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
CW_USEDEFAULT, // allows system choose an x position
CW_USEDEFAULT, // allows system choose a y position
CW_USEDEFAULT, // width, CW_USEDEFAULT allows system to choose height and width
CW_USEDEFAULT, // height, CW_USEDEFAULT ignores heights as this is set by setting
// CW_USEDEFAULT in width above.
HWND_MESSAGE, // Message only Window
NULL, // handle to menu
hInstance, // handle to the instance of module
NULL); // Long pointer to a value to be passed to the window through the
// CREATESTRUCT structure passed in the lParam parameter the WM_CREATE message
TimerHandle=SetTimer(FrameWnd,WM_TIMER,5000,NULL);
CheckTimer();
return (TRUE);
}
//
// FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
//
// PURPOSE: Processes messages for the main window.
//
LRESULT CALLBACK FrameWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message) {
case WM_TIMER:
CheckTimer();
return 0;
case WM_CLOSE:
PostQuitMessage(0);
break;
default:
return (DefWindowProc(hWnd, message, wParam, lParam));
}
return (0);
}