#ifdef _WIN32 #include "SystemCalls.h" #include #include #include #include #include int System::getCountCPU() { DWORD len = 0; GetLogicalProcessorInformation(nullptr, &len); if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) { throw std::runtime_error(std::to_string(GetLastError()).c_str()); } std::vector buffer(len); if (!GetLogicalProcessorInformation(buffer.data(), &len)) { throw std::runtime_error(std::to_string(GetLastError()).c_str()); } DWORD count = len / sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION); int physicalCoreCount = 0; for (DWORD i = 0; i < count; ++i) { if (buffer[i].Relationship == RelationProcessorCore) { physicalCoreCount++; } } return physicalCoreCount; } unsigned long long System::getMemorySize() { MEMORYSTATUSEX memStatus{}; memStatus.dwLength = sizeof(memStatus); GlobalMemoryStatusEx(&memStatus); return memStatus.ullTotalPhys; } void* System::InitModule(const char* ModuleName, CoreInstance& core) { std::string fileName = ModuleName; fileName += ".dll"; HMODULE hModule = LoadLibraryA(fileName.c_str()); if(hModule == nullptr) throw std::runtime_error(std::to_string(GetLastError()).c_str()); void(*load)(CoreInstance&) = reinterpret_cast(GetProcAddress(hModule, "InitModule")); if(load == nullptr) { throw std::runtime_error(std::to_string(GetLastError()).c_str()); } load(core); return hModule; } void System::StartModule(void* handler) { void(*start)() = reinterpret_cast(GetProcAddress(static_cast(handler), "StartModule")); if(start == nullptr) { throw std::runtime_error(std::to_string(GetLastError()).c_str()); } start(); } void System::StopModule(void* handler) { void(*stop)() = reinterpret_cast(GetProcAddress(static_cast(handler), "StopModule")); if(stop == nullptr) { throw std::runtime_error(std::to_string(GetLastError()).c_str()); } stop(); FreeLibrary(static_cast(handler)); } void System::QuitModule(void* handler) { void(*quit)() = reinterpret_cast(GetProcAddress(static_cast(handler), "QuitModule")); if(quit == nullptr) { throw std::runtime_error(std::to_string(GetLastError()).c_str()); } quit(); FreeLibrary(static_cast(handler)); } #endif