mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-10-30 17:41:41 +01:00
Windows: get rid of InitOnceExecuteOnce
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
#include "fastfetch.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <synchapi.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
|
||||
@@ -11,14 +10,11 @@ static void CoUninitializeWrap(void)
|
||||
CoUninitialize();
|
||||
}
|
||||
|
||||
static BOOL CALLBACK InitHandleFunction(FF_MAYBE_UNUSED PINIT_ONCE lpInitOnce, FF_MAYBE_UNUSED PVOID lpParameter, PVOID* lpContext)
|
||||
static const char* doInitCom()
|
||||
{
|
||||
// Initialize COM
|
||||
if (FAILED(CoInitializeEx(NULL, COINIT_MULTITHREADED)))
|
||||
{
|
||||
*lpContext = (PVOID) "CoInitializeEx() failed";
|
||||
return FALSE;
|
||||
}
|
||||
return "CoInitializeEx() failed";
|
||||
|
||||
// Set general COM security levels
|
||||
if (FAILED(CoInitializeSecurity(
|
||||
@@ -34,18 +30,17 @@ static BOOL CALLBACK InitHandleFunction(FF_MAYBE_UNUSED PINIT_ONCE lpInitOnce, F
|
||||
)))
|
||||
{
|
||||
CoUninitialize();
|
||||
*lpContext = (PVOID) "CoInitializeSecurity() failed";
|
||||
return FALSE;
|
||||
return "CoInitializeSecurity() failed";
|
||||
}
|
||||
|
||||
atexit(CoUninitializeWrap);
|
||||
return TRUE;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char* ffInitCom(void)
|
||||
{
|
||||
const char* error = NULL;
|
||||
static INIT_ONCE s_InitOnce;
|
||||
InitOnceExecuteOnce(&s_InitOnce, &InitHandleFunction, NULL, (void**)&error);
|
||||
static const char* error = "";
|
||||
if (error && error[0] == '\0')
|
||||
error = doInitCom();
|
||||
return error;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user