-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSoftReset.cpp
99 lines (82 loc) · 2.39 KB
/
SoftReset.cpp
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
#include <algorithm>
#include <tchar.h>
#include <vector>
#include <windows.h>
#define MainWindowClassName L"SelectorMainWindowClass"
#define DataTypeAlertError 0x1000
#define DataTypeAlertInformation 0x1001
#define DataTypeAlertWarning 0x1002
static void showAlertWarning(LPCWSTR message, LPCWSTR title) {
HWND selectorMainWindow = FindWindow(MainWindowClassName, NULL);
if (!selectorMainWindow) {
MessageBox(NULL, message, title, MB_ICONWARNING);
return;
}
wchar_t data[2048];
wcscpy(data, message);
data[wcslen(message)] = 0;
wcscpy(data + wcslen(message) + 1, title);
size_t dataLen = wcslen(message) + wcslen(title) + 1;
COPYDATASTRUCT info;
info.dwData = DataTypeAlertWarning;
info.cbData = dataLen * sizeof(wchar_t);
HGLOBAL global = GlobalAlloc(GPTR, info.cbData);
memcpy((LPVOID)global, data, info.cbData);
info.lpData = (LPVOID)global;
SendMessage(selectorMainWindow, WM_COPYDATA, (WPARAM)NULL, (LPARAM)&info);
GlobalFree(global);
}
int APIENTRY WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPTSTR lpCmd, int nShow) {
HINSTANCE lib = LoadLibrary(L"ResetKit");
if (!lib) {
wchar_t buf[256];
swprintf(buf,
L"Cannot perform a soft reset.\n"
L"ResetKit was not loaded (0x%08x).",
GetLastError());
showAlertWarning(buf, L"Error");
return 1;
}
typedef BOOL (*RKCanSoftResetProc)();
RKCanSoftResetProc RKCanSoftReset =
(RKCanSoftResetProc)GetProcAddress(lib, L"RKCanSoftReset");
if (!RKCanSoftReset) {
wchar_t buf[256];
swprintf(buf,
L"Cannot perform a soft reset.\n"
L"RKCanSoftReset not found (0x%08x).",
GetLastError());
showAlertWarning(buf, L"Error");
return 1;
}
if (!RKCanSoftReset()) {
wchar_t buf[256];
swprintf(buf,
L"Cannot perform a soft reset.\n"
L"This device doesn't support the soft reset (0x%08x).",
GetLastError());
showAlertWarning(buf, L"Error");
return 1;
}
typedef BOOL (*RKDoSoftResetProc)();
RKDoSoftResetProc RKDoSoftReset = (RKDoSoftResetProc)GetProcAddress(lib, L"RKDoSoftReset");
if (!RKDoSoftReset) {
wchar_t buf[256];
swprintf(buf,
L"Cannot perform a soft reset.\n"
L"RKDoSoftReset not found (0x%08x).",
GetLastError());
showAlertWarning(buf, L"Error");
return 1;
}
if (!RKDoSoftReset()) {
wchar_t buf[256];
swprintf(buf,
L"Cannot perform a soft reset.\n"
L"Operation failed (0x%08x).",
GetLastError());
showAlertWarning(buf, L"Error");
return 1;
}
return 0;
}