brainlilo/bootloader.cpp

85 lines
2.1 KiB
C++
Raw Normal View History

2020-09-28 03:19:37 +09:00
// This file is in public domain.
#include <algorithm>
#include <tchar.h>
2022-01-24 01:52:45 +09:00
#include <vector>
#include <windows.h>
2020-09-28 03:19:37 +09:00
#define MainWindowClassName L"SelectorMainWindowClass"
2022-01-24 01:52:45 +09:00
#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);
2020-09-28 03:19:37 +09:00
return;
}
2022-01-24 01:52:45 +09:00
2020-09-28 03:19:37 +09:00
wchar_t data[2048];
wcscpy(data, message);
2022-01-24 01:52:45 +09:00
data[wcslen(message)] = 0;
wcscpy(data + wcslen(message) + 1, title);
size_t dataLen = wcslen(message) + wcslen(title) + 1;
2020-09-28 03:19:37 +09:00
COPYDATASTRUCT info;
2022-01-24 01:52:45 +09:00
info.dwData = DataTypeAlertWarning;
info.cbData = dataLen * sizeof(wchar_t);
HGLOBAL global = GlobalAlloc(GPTR, info.cbData);
2020-09-28 03:19:37 +09:00
memcpy((LPVOID)global, data, info.cbData);
2022-01-24 01:52:45 +09:00
info.lpData = (LPVOID)global;
SendMessage(selectorMainWindow, WM_COPYDATA, NULL, (LPARAM)&info);
2020-09-28 03:19:37 +09:00
GlobalFree(global);
}
2022-01-24 01:52:45 +09:00
int APIENTRY WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPTSTR lpCmd, int nShow)
{
HINSTANCE lib = LoadLibrary(L"BrainLILO");
if (!lib)
{
wchar_t buf[256];
swprintf(buf,
L"Cannot perform a soft reset.\n"
L"BrainLILO was not loaded (0x%08x).",
GetLastError());
2020-09-28 03:19:37 +09:00
showAlertWarning(buf, L"Error");
return 1;
}
2022-01-24 01:52:45 +09:00
2020-09-28 03:19:37 +09:00
typedef BOOL (*RKDoSoftResetProc)();
2022-01-24 01:52:45 +09:00
RKDoSoftResetProc RKDoSoftReset = (RKDoSoftResetProc)GetProcAddress(lib, L"RKDoSoftReset");
if (!RKDoSoftReset)
{
2020-09-28 03:19:37 +09:00
wchar_t buf[256];
2022-01-24 01:52:45 +09:00
swprintf(buf,
L"Cannot perform a soft reset.\n"
2020-09-28 03:19:37 +09:00
L"RKDoSoftReset not found (0x%08x).",
GetLastError());
showAlertWarning(buf, L"Error");
return 1;
}
2022-01-24 01:52:45 +09:00
if (!RKDoSoftReset())
{
2020-09-28 03:19:37 +09:00
wchar_t buf[256];
2022-01-24 01:52:45 +09:00
swprintf(buf,
L"Cannot perform a soft reset.\n"
2020-09-28 03:19:37 +09:00
L"Operation failed (0x%08x).",
GetLastError());
showAlertWarning(buf, L"Error");
return 1;
}
return 0;
}