-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsettings.cpp
More file actions
486 lines (424 loc) · 20.1 KB
/
Copy pathsettings.cpp
File metadata and controls
486 lines (424 loc) · 20.1 KB
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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
#include "settings.hpp"
#include <windows.h>
#include "resource.h"
#include "utils.hpp"
#include <iostream>
#include <string>
// Define the registry path and entry names
#define REGISTRY_PARENT_PATH L"SOFTWARE\\Simon Safar"
#define REGISTRY_PATH L"SOFTWARE\\Simon Safar\\OpenAI Keys"
#define REGISTRY_TOKEN_VALUE L"token"
#define REGISTRY_API_TYPE_VALUE L"api_type"
#define REGISTRY_ENDPOINT_VALUE L"endpoint"
#define REGISTRY_PROMPT_VALUE L"prompt"
#define REGISTRY_POSTPROCESS_ENABLED_VALUE L"postprocess_enabled"
#define REGISTRY_POSTPROCESS_ENDPOINT_VALUE L"postprocess_endpoint"
#define REGISTRY_POSTPROCESS_MODEL_VALUE L"postprocess_model"
#define REGISTRY_POSTPROCESS_PROMPT_VALUE L"postprocess_prompt"
// Global variables to hold settings
char g_OpenAIToken[256] = { 0 };
char g_Endpoint[256] = { 0 };
char g_PromptText[1024] = { 0 };
APIType g_APIType = API_OPENAI;
bool g_PostProcessEnabled = false;
char g_PostProcessEndpoint[256] = { 0 };
char g_PostProcessModel[128] = { 0 };
char g_PostProcessPrompt[4096] = { 0 };
// Add debugging variables
DWORD g_LastRegError = 0;
BOOL g_KeyOpened = FALSE;
BOOL g_TokenLoaded = FALSE;
BOOL g_TypeLoaded = FALSE;
BOOL g_EndpointLoaded = FALSE;
BOOL g_PromptLoaded = FALSE;
char* GetOpenAIToken() { return g_OpenAIToken; }
char* GetCustomEndpoint() { return g_Endpoint; }
APIType GetAPIType() { return g_APIType; }
char* GetPromptText() { return g_PromptText; }
bool GetPostProcessEnabled() { return g_PostProcessEnabled; }
char* GetPostProcessEndpoint() { return g_PostProcessEndpoint; }
char* GetPostProcessModel() { return g_PostProcessModel; }
char* GetPostProcessPrompt() { return g_PostProcessPrompt; }
void SetPostProcessEnabled(bool enabled) { g_PostProcessEnabled = enabled; }
static const char kDefaultPostProcessEndpoint[] = "http://inference.ltn.simonsafar.com/api/generate";
static const char kDefaultPostProcessModel[] = "zephyr:latest";
static const char kDefaultPostProcessPrompt[] =
"<instructions>You are a post-processor for speech-to-text transcriptions. The user speaks words out loud, which are transcribed by a speech-to-text service. Your job is to convert the transcribed spoken words into properly formatted written text.\n"
"\n"
"When users dictate URLs, email addresses, or other formatted text, they speak the punctuation and formatting characters as words (like \"dot\", \"slash\", \"at\", \"colon\"). You need to convert these spoken words into the actual punctuation marks.</instructions>\n"
"\n"
"<examples>\n"
"<example>\n"
"<input>http colon slash slash example dot com</input>\n"
"<explanation>The user is speaking a URL. Converting spoken punctuation: \"colon\" becomes \":\", \"slash slash\" becomes \"//\", and \"dot\" becomes \".\"</explanation>\n"
"<output>http://example.com</output>\n"
"</example>\n"
"\n"
"<example>\n"
"<input>visit w w w dot github dot com</input>\n"
"<explanation>The user is speaking a website address. The \"w w w\" represents the three letters without spaces, and \"dot\" becomes \".\" for proper domain formatting.</explanation>\n"
"<output>visit www.github.com</output>\n"
"</example>\n"
"</examples>\n"
"\n"
"<input>{{transcript}}</input>\n";
// Function to load settings from the registry
void LoadSettingsFromRegistry()
{
HKEY hKey;
DWORD dataSize;
// Reset debugging variables
g_LastRegError = 0;
g_KeyOpened = FALSE;
g_TokenLoaded = FALSE;
g_TypeLoaded = FALSE;
g_EndpointLoaded = FALSE;
g_PromptLoaded = FALSE;
g_PostProcessEnabled = false;
strncpy_s(g_PostProcessEndpoint, sizeof(g_PostProcessEndpoint), kDefaultPostProcessEndpoint, _TRUNCATE);
strncpy_s(g_PostProcessModel, sizeof(g_PostProcessModel), kDefaultPostProcessModel, _TRUNCATE);
strncpy_s(g_PostProcessPrompt, sizeof(g_PostProcessPrompt), kDefaultPostProcessPrompt, _TRUNCATE);
// Open the registry key - store error code for debugging
g_LastRegError = RegOpenKeyExW(HKEY_CURRENT_USER, REGISTRY_PATH, 0, KEY_READ, &hKey);
if (g_LastRegError == ERROR_SUCCESS)
{
g_KeyOpened = TRUE;
// Load OpenAI token - Unicode to ASCII conversion needed
wchar_t wideToken[256] = { 0 };
dataSize = sizeof(wideToken);
g_LastRegError = RegQueryValueExW(
hKey, REGISTRY_TOKEN_VALUE, NULL, NULL, (LPBYTE)wideToken, &dataSize);
if (g_LastRegError == ERROR_SUCCESS)
{
// Convert wide string to ASCII
WideCharToMultiByte(CP_ACP, 0, wideToken, -1, g_OpenAIToken, sizeof(g_OpenAIToken), NULL, NULL);
g_TokenLoaded = TRUE;
}
else
{
g_OpenAIToken[0] = '\0';
}
// Load API type
DWORD apiType = API_OPENAI;
dataSize = sizeof(apiType);
g_LastRegError = RegQueryValueExW(
hKey, REGISTRY_API_TYPE_VALUE, NULL, NULL, (LPBYTE)&apiType, &dataSize);
if (g_LastRegError == ERROR_SUCCESS)
{
g_APIType = static_cast<APIType>(apiType);
g_TypeLoaded = TRUE;
}
// Load endpoint - Unicode to ASCII conversion needed
wchar_t wideEndpoint[256] = { 0 };
dataSize = sizeof(wideEndpoint);
g_LastRegError = RegQueryValueExW(
hKey, REGISTRY_ENDPOINT_VALUE, NULL, NULL, (LPBYTE)wideEndpoint, &dataSize);
if (g_LastRegError == ERROR_SUCCESS)
{
// Convert wide string to ASCII
WideCharToMultiByte(CP_ACP, 0, wideEndpoint, -1, g_Endpoint, sizeof(g_Endpoint), NULL, NULL);
g_EndpointLoaded = TRUE;
}
else
{
g_Endpoint[0] = '\0';
}
// Load prompt text - Unicode to ASCII conversion needed
wchar_t widePrompt[1024] = { 0 };
dataSize = sizeof(widePrompt);
g_LastRegError = RegQueryValueExW(
hKey, REGISTRY_PROMPT_VALUE, NULL, NULL, (LPBYTE)widePrompt, &dataSize);
if (g_LastRegError == ERROR_SUCCESS)
{
// Convert wide string to ASCII
WideCharToMultiByte(CP_ACP, 0, widePrompt, -1, g_PromptText, sizeof(g_PromptText), NULL, NULL);
g_PromptLoaded = TRUE;
}
else
{
g_PromptText[0] = '\0';
}
// Load post-process enabled
DWORD postProcessEnabled = 0;
dataSize = sizeof(postProcessEnabled);
g_LastRegError = RegQueryValueExW(
hKey, REGISTRY_POSTPROCESS_ENABLED_VALUE, NULL, NULL, (LPBYTE)&postProcessEnabled, &dataSize);
if (g_LastRegError == ERROR_SUCCESS)
{
g_PostProcessEnabled = (postProcessEnabled != 0);
}
// Load post-process endpoint
wchar_t widePostProcessEndpoint[256] = { 0 };
dataSize = sizeof(widePostProcessEndpoint);
g_LastRegError = RegQueryValueExW(
hKey, REGISTRY_POSTPROCESS_ENDPOINT_VALUE, NULL, NULL, (LPBYTE)widePostProcessEndpoint, &dataSize);
if (g_LastRegError == ERROR_SUCCESS)
{
WideCharToMultiByte(CP_ACP, 0, widePostProcessEndpoint, -1, g_PostProcessEndpoint, sizeof(g_PostProcessEndpoint), NULL, NULL);
}
// Load post-process model
wchar_t widePostProcessModel[128] = { 0 };
dataSize = sizeof(widePostProcessModel);
g_LastRegError = RegQueryValueExW(
hKey, REGISTRY_POSTPROCESS_MODEL_VALUE, NULL, NULL, (LPBYTE)widePostProcessModel, &dataSize);
if (g_LastRegError == ERROR_SUCCESS)
{
WideCharToMultiByte(CP_ACP, 0, widePostProcessModel, -1, g_PostProcessModel, sizeof(g_PostProcessModel), NULL, NULL);
}
// Load post-process prompt
wchar_t widePostProcessPrompt[4096] = { 0 };
dataSize = sizeof(widePostProcessPrompt);
g_LastRegError = RegQueryValueExW(
hKey, REGISTRY_POSTPROCESS_PROMPT_VALUE, NULL, NULL, (LPBYTE)widePostProcessPrompt, &dataSize);
if (g_LastRegError == ERROR_SUCCESS)
{
WideCharToMultiByte(CP_ACP, 0, widePostProcessPrompt, -1, g_PostProcessPrompt, sizeof(g_PostProcessPrompt), NULL, NULL);
}
RegCloseKey(hKey);
}
else
{
// If the key doesn't exist, initialize default values
g_OpenAIToken[0] = '\0';
g_APIType = API_OPENAI;
g_Endpoint[0] = '\0';
g_PromptText[0] = '\0';
}
}
// Function to save settings to the registry
void SaveSettingsToRegistry()
{
HKEY hKey;
DWORD disposition;
DWORD lastError = 0;
// Create the parent path first if needed
lastError = RegCreateKeyExW(HKEY_CURRENT_USER,
REGISTRY_PARENT_PATH,
0,
NULL,
0,
KEY_WRITE,
NULL,
&hKey,
&disposition);
if (lastError == ERROR_SUCCESS)
{
RegCloseKey(hKey);
}
// Create or open the registry key
lastError = RegCreateKeyExW(
HKEY_CURRENT_USER, REGISTRY_PATH, 0, NULL, 0, KEY_WRITE, NULL, &hKey, &disposition);
if (lastError == ERROR_SUCCESS)
{
// Convert ASCII strings to wide strings for storage
wchar_t wideToken[256] = {0};
MultiByteToWideChar(CP_ACP, 0, g_OpenAIToken, -1, wideToken, 256);
// Save OpenAI token
lastError = RegSetValueExW(hKey,
REGISTRY_TOKEN_VALUE,
0,
REG_SZ,
(const BYTE*)wideToken,
(wcslen(wideToken) + 1) * sizeof(wchar_t));
// Save API type
DWORD apiType = static_cast<DWORD>(g_APIType);
lastError = RegSetValueExW(
hKey, REGISTRY_API_TYPE_VALUE, 0, REG_DWORD, (const BYTE*)&apiType, sizeof(apiType));
// Convert endpoint string to wide
wchar_t wideEndpoint[256] = {0};
MultiByteToWideChar(CP_ACP, 0, g_Endpoint, -1, wideEndpoint, 256);
// Save endpoint
lastError = RegSetValueExW(hKey,
REGISTRY_ENDPOINT_VALUE,
0,
REG_SZ,
(const BYTE*)wideEndpoint,
(wcslen(wideEndpoint) + 1) * sizeof(wchar_t));
// Convert prompt text to wide string
wchar_t widePrompt[1024] = {0};
MultiByteToWideChar(CP_ACP, 0, g_PromptText, -1, widePrompt, 1024);
// Save prompt text
lastError = RegSetValueExW(hKey,
REGISTRY_PROMPT_VALUE,
0,
REG_SZ,
(const BYTE*)widePrompt,
(wcslen(widePrompt) + 1) * sizeof(wchar_t));
// Save post-process enabled
DWORD postProcessEnabled = g_PostProcessEnabled ? 1 : 0;
lastError = RegSetValueExW(
hKey, REGISTRY_POSTPROCESS_ENABLED_VALUE, 0, REG_DWORD, (const BYTE*)&postProcessEnabled, sizeof(postProcessEnabled));
// Convert post-process endpoint to wide
wchar_t widePostProcessEndpoint[256] = {0};
MultiByteToWideChar(CP_ACP, 0, g_PostProcessEndpoint, -1, widePostProcessEndpoint, 256);
lastError = RegSetValueExW(hKey,
REGISTRY_POSTPROCESS_ENDPOINT_VALUE,
0,
REG_SZ,
(const BYTE*)widePostProcessEndpoint,
(wcslen(widePostProcessEndpoint) + 1) * sizeof(wchar_t));
// Convert post-process model to wide
wchar_t widePostProcessModel[128] = {0};
MultiByteToWideChar(CP_ACP, 0, g_PostProcessModel, -1, widePostProcessModel, 128);
lastError = RegSetValueExW(hKey,
REGISTRY_POSTPROCESS_MODEL_VALUE,
0,
REG_SZ,
(const BYTE*)widePostProcessModel,
(wcslen(widePostProcessModel) + 1) * sizeof(wchar_t));
// Convert post-process prompt to wide
wchar_t widePostProcessPrompt[4096] = {0};
MultiByteToWideChar(CP_ACP, 0, g_PostProcessPrompt, -1, widePostProcessPrompt, 4096);
lastError = RegSetValueExW(hKey,
REGISTRY_POSTPROCESS_PROMPT_VALUE,
0,
REG_SZ,
(const BYTE*)widePostProcessPrompt,
(wcslen(widePostProcessPrompt) + 1) * sizeof(wchar_t));
RegCloseKey(hKey);
}
}
// Function to update control states based on selected API type
void UpdateControlStates(HWND hDlg)
{
BOOL isOpenAI = (IsDlgButtonChecked(hDlg, IDC_RADIO_OPENAI) == BST_CHECKED);
// Enable/disable token field based on OpenAI selection
EnableWindow(GetDlgItem(hDlg, IDC_OPENAI_TOKEN), isOpenAI);
// Enable/disable endpoint field based on Custom server selection
EnableWindow(GetDlgItem(hDlg, IDC_ENDPOINT), !isOpenAI);
}
// Dialog procedure to handle messages
INT_PTR CALLBACK SettingsDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_INITDIALOG:
{
// Load settings from the registry and set them in the dialog
LoadSettingsFromRegistry();
// Use wide string versions for the dialog
wchar_t wideToken[256] = {0};
wchar_t wideEndpoint[256] = {0};
wchar_t widePrompt[1024] = {0};
wchar_t widePostProcessEndpoint[256] = {0};
wchar_t widePostProcessModel[128] = {0};
wchar_t widePostProcessPrompt[4096] = {0};
// Convert from ASCII to wide strings
MultiByteToWideChar(CP_ACP, 0, g_OpenAIToken, -1, wideToken, 256);
MultiByteToWideChar(CP_ACP, 0, g_Endpoint, -1, wideEndpoint, 256);
MultiByteToWideChar(CP_ACP, 0, g_PromptText, -1, widePrompt, 1024);
MultiByteToWideChar(CP_ACP, 0, g_PostProcessEndpoint, -1, widePostProcessEndpoint, 256);
MultiByteToWideChar(CP_ACP, 0, g_PostProcessModel, -1, widePostProcessModel, 128);
MultiByteToWideChar(CP_ACP, 0, g_PostProcessPrompt, -1, widePostProcessPrompt, 4096);
SetDlgItemTextW(hDlg, IDC_OPENAI_TOKEN, wideToken);
SetDlgItemTextW(hDlg, IDC_ENDPOINT, wideEndpoint);
SetDlgItemTextW(hDlg, IDC_PROMPT, widePrompt);
SetDlgItemTextW(hDlg, IDC_POSTPROCESS_ENDPOINT, widePostProcessEndpoint);
SetDlgItemTextW(hDlg, IDC_POSTPROCESS_MODEL, widePostProcessModel);
SetDlgItemTextW(hDlg, IDC_POSTPROCESS_PROMPT, widePostProcessPrompt);
// Set radio button based on the saved API type
CheckRadioButton(hDlg,
IDC_RADIO_OPENAI,
IDC_RADIO_CUSTOM,
g_APIType == API_OPENAI ? IDC_RADIO_OPENAI : IDC_RADIO_CUSTOM);
// Initialize control states
UpdateControlStates(hDlg);
return TRUE;
}
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDC_RADIO_OPENAI:
case IDC_RADIO_CUSTOM:
// Update control states when radio buttons change
UpdateControlStates(hDlg);
break;
case IDOK: // OK Button pressed
{
// Get the entered OpenAI token and endpoint using wide character functions
wchar_t wideToken[256] = {0};
wchar_t wideEndpoint[256] = {0};
wchar_t widePrompt[1024] = {0};
wchar_t widePostProcessEndpoint[256] = {0};
wchar_t widePostProcessModel[128] = {0};
wchar_t widePostProcessPrompt[4096] = {0};
GetDlgItemTextW(hDlg, IDC_OPENAI_TOKEN, wideToken, 256);
GetDlgItemTextW(hDlg, IDC_ENDPOINT, wideEndpoint, 256);
GetDlgItemTextW(hDlg, IDC_PROMPT, widePrompt, 1024);
GetDlgItemTextW(hDlg, IDC_POSTPROCESS_ENDPOINT, widePostProcessEndpoint, 256);
GetDlgItemTextW(hDlg, IDC_POSTPROCESS_MODEL, widePostProcessModel, 128);
GetDlgItemTextW(hDlg, IDC_POSTPROCESS_PROMPT, widePostProcessPrompt, 4096);
// Convert wide to ASCII for our global variables
WideCharToMultiByte(CP_ACP, 0, wideToken, -1, g_OpenAIToken, sizeof(g_OpenAIToken), NULL, NULL);
WideCharToMultiByte(CP_ACP, 0, wideEndpoint, -1, g_Endpoint, sizeof(g_Endpoint), NULL, NULL);
WideCharToMultiByte(CP_ACP, 0, widePrompt, -1, g_PromptText, sizeof(g_PromptText), NULL, NULL);
WideCharToMultiByte(CP_ACP, 0, widePostProcessEndpoint, -1, g_PostProcessEndpoint, sizeof(g_PostProcessEndpoint), NULL, NULL);
WideCharToMultiByte(CP_ACP, 0, widePostProcessModel, -1, g_PostProcessModel, sizeof(g_PostProcessModel), NULL, NULL);
WideCharToMultiByte(CP_ACP, 0, widePostProcessPrompt, -1, g_PostProcessPrompt, sizeof(g_PostProcessPrompt), NULL, NULL);
// Get the selected API type
g_APIType = (IsDlgButtonChecked(hDlg, IDC_RADIO_OPENAI) == BST_CHECKED) ? API_OPENAI
: API_CUSTOM;
// Save settings to the registry
SaveSettingsToRegistry();
EndDialog(hDlg, IDOK);
return TRUE;
}
case IDCANCEL: // Cancel Button pressed
EndDialog(hDlg, IDCANCEL);
return TRUE;
case IDAPPLY: // Apply Button pressed
{
// Get the entered OpenAI token and endpoint using wide character functions
wchar_t wideToken[256] = {0};
wchar_t wideEndpoint[256] = {0};
wchar_t widePrompt[1024] = {0};
wchar_t widePostProcessEndpoint[256] = {0};
wchar_t widePostProcessModel[128] = {0};
wchar_t widePostProcessPrompt[4096] = {0};
GetDlgItemTextW(hDlg, IDC_OPENAI_TOKEN, wideToken, 256);
GetDlgItemTextW(hDlg, IDC_ENDPOINT, wideEndpoint, 256);
GetDlgItemTextW(hDlg, IDC_PROMPT, widePrompt, 1024);
GetDlgItemTextW(hDlg, IDC_POSTPROCESS_ENDPOINT, widePostProcessEndpoint, 256);
GetDlgItemTextW(hDlg, IDC_POSTPROCESS_MODEL, widePostProcessModel, 128);
GetDlgItemTextW(hDlg, IDC_POSTPROCESS_PROMPT, widePostProcessPrompt, 4096);
// Convert wide to ASCII for our global variables
WideCharToMultiByte(CP_ACP, 0, wideToken, -1, g_OpenAIToken, sizeof(g_OpenAIToken), NULL, NULL);
WideCharToMultiByte(CP_ACP, 0, wideEndpoint, -1, g_Endpoint, sizeof(g_Endpoint), NULL, NULL);
WideCharToMultiByte(CP_ACP, 0, widePrompt, -1, g_PromptText, sizeof(g_PromptText), NULL, NULL);
WideCharToMultiByte(CP_ACP, 0, widePostProcessEndpoint, -1, g_PostProcessEndpoint, sizeof(g_PostProcessEndpoint), NULL, NULL);
WideCharToMultiByte(CP_ACP, 0, widePostProcessModel, -1, g_PostProcessModel, sizeof(g_PostProcessModel), NULL, NULL);
WideCharToMultiByte(CP_ACP, 0, widePostProcessPrompt, -1, g_PostProcessPrompt, sizeof(g_PostProcessPrompt), NULL, NULL);
// Get the selected API type
g_APIType = (IsDlgButtonChecked(hDlg, IDC_RADIO_OPENAI) == BST_CHECKED) ? API_OPENAI
: API_CUSTOM;
// Save settings to the registry without closing the dialog
SaveSettingsToRegistry();
MessageBoxW(hDlg, L"Changes Applied", L"Info", MB_OK | MB_ICONINFORMATION);
return TRUE;
}
}
}
return FALSE;
}
// Function to show the settings dialog in a blocking way
void ShowSettingsDialog(HWND hwndParent)
{
INT_PTR result = DialogBox(
GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_SETTINGS), hwndParent, SettingsDlgProc);
if (result == -1)
{
DWORD dwError = GetLastError();
LPVOID lpMsgBuf;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
dwError,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR)&lpMsgBuf,
0,
NULL);
MessageBox(NULL, (LPCTSTR)lpMsgBuf, TEXT("Error"), MB_OK | MB_ICONERROR);
LocalFree(lpMsgBuf);
}
std::cout << "res: " << result;
}