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
#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
static void CoUninitializeWrap(void)
{
CoUninitialize();
}
static const char* doInitCom()
{
// Initialize COM
if (FAILED(CoInitializeEx(NULL, COINIT_MULTITHREADED)))
return "CoInitializeEx() failed";
// 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();
return "CoInitializeSecurity() failed";
}
atexit(CoUninitializeWrap);
return NULL;
}
const char* ffInitCom(void)
{
static const char* error = "";
if (error && error[0] == '\0')
error = doInitCom();
return error;
}