2023-01-25 15:49:31 +08:00
|
|
|
#include "com.hpp"
|
|
|
|
|
#include "fastfetch.h"
|
|
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
|
|
//https://learn.microsoft.com/en-us/windows/win32/wmisdk/example--getting-wmi-data-from-the-local-computer
|
|
|
|
|
//https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/computer-system-hardware-classes
|
2023-06-24 10:59:53 +08:00
|
|
|
static void CoUninitializeWrap(void)
|
2023-01-25 15:49:31 +08:00
|
|
|
{
|
|
|
|
|
CoUninitialize();
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-30 14:19:25 +08:00
|
|
|
static const char* doInitCom()
|
2023-01-25 15:49:31 +08:00
|
|
|
{
|
|
|
|
|
// Initialize COM
|
|
|
|
|
if (FAILED(CoInitializeEx(NULL, COINIT_MULTITHREADED)))
|
2023-12-30 14:19:25 +08:00
|
|
|
return "CoInitializeEx() failed";
|
2023-01-25 15:49:31 +08:00
|
|
|
|
|
|
|
|
// Set general COM security levels
|
|
|
|
|
if (FAILED(CoInitializeSecurity(
|
|
|
|
|
NULL,
|
|
|
|
|
-1, // COM authentication
|
|
|
|
|
NULL, // Authentication services
|
|
|
|
|
NULL, // Reserved
|
|
|
|
|
RPC_C_AUTHN_LEVEL_DEFAULT, // Default authentication
|
|
|
|
|
RPC_C_IMP_LEVEL_IMPERSONATE, // Default Impersonation
|
|
|
|
|
NULL, // Authentication info
|
|
|
|
|
EOAC_NONE, // Additional capabilities
|
|
|
|
|
NULL // Reserved
|
|
|
|
|
)))
|
|
|
|
|
{
|
|
|
|
|
CoUninitialize();
|
2023-12-30 14:19:25 +08:00
|
|
|
return "CoInitializeSecurity() failed";
|
2023-01-25 15:49:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
atexit(CoUninitializeWrap);
|
2023-12-30 14:19:25 +08:00
|
|
|
return NULL;
|
2023-01-25 15:49:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const char* ffInitCom(void)
|
|
|
|
|
{
|
2023-12-30 14:19:25 +08:00
|
|
|
static const char* error = "";
|
|
|
|
|
if (error && error[0] == '\0')
|
|
|
|
|
error = doInitCom();
|
2023-01-25 15:49:31 +08:00
|
|
|
return error;
|
|
|
|
|
}
|