Get system arch using 'GetNativeSystemInfo'

This commit is contained in:
Glavo 2022-02-04 12:50:05 +08:00 committed by Yuhui Huang
parent 2b21f5f48f
commit 98e0a92745
3 changed files with 7 additions and 35 deletions

View File

@ -48,11 +48,14 @@ int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
// TODO: check whether the bundled JRE is valid.
// First try the Java packaged together.
bool is64Bit = false;
GetArch(is64Bit); // if failed to determine architecture of operating system,
// consider 32-bit.
bool isX64 = false;
if (is64Bit) {
SYSTEM_INFO systemInfo;
GetNativeSystemInfo(&systemInfo);
isX64 = (systemInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64);
if (isX64) {
RawLaunchJVM(L"jre-x64\\bin\\javaw.exe", workdir, exeName);
} else {
RawLaunchJVM(L"jre-x86\\bin\\javaw.exe", workdir, exeName);

View File

@ -71,35 +71,6 @@ bool FindFirstFileExists(LPCWSTR lpPath, DWORD dwFilter) {
return ret;
}
bool GetArch(bool &is64Bit) {
#if _WIN64
is64Bit = true;
return true;
#elif _WIN32
typedef BOOL(WINAPI * LPFN_ISWOW64PROCESS)(HANDLE, PBOOL);
BOOL isWow64 = FALSE;
// IsWow64Process is not available on all supported versions of Windows.
// Use GetModuleHandle to get a handle to the DLL that contains the function
// and GetProcAddress to get a pointer to the function if available.
LPFN_ISWOW64PROCESS fnIsWow64Process = (LPFN_ISWOW64PROCESS)GetProcAddress(
GetModuleHandle(TEXT("kernel32")), "IsWow64Process");
if (fnIsWow64Process) {
if (!fnIsWow64Process(GetCurrentProcess(), &isWow64)) return false;
is64Bit = isWow64;
return true;
} else // IsWow64Process is not supported, fail to detect.
return false;
#else
#error _WIN64 and _WIN32 are both undefined.
#endif
}
bool MyGetFileVersionInfo(const std::wstring &filePath, Version &version) {
DWORD verHandle = 0;
UINT size = 0;

View File

@ -24,6 +24,4 @@ bool MyCreateProcess(const std::wstring &command, const std::wstring &workdir);
// Check if file lpPath exists.
bool FindFirstFileExists(LPCWSTR lpPath, DWORD dwFilter);
bool GetArch(bool &is64Bit);
bool MyGetFileVersionInfo(const std::wstring &filePath, Version &version);