From 20d28e80a5c861a9d5f449ea911ab75b4f37ad0d Mon Sep 17 00:00:00 2001 From: Jef Date: Tue, 24 Sep 2024 14:54:57 +0200 Subject: Initial community commit --- Src/nde/win/nde_init.cpp | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 Src/nde/win/nde_init.cpp (limited to 'Src/nde/win/nde_init.cpp') diff --git a/Src/nde/win/nde_init.cpp b/Src/nde/win/nde_init.cpp new file mode 100644 index 00000000..9dfc31ee --- /dev/null +++ b/Src/nde/win/nde_init.cpp @@ -0,0 +1,36 @@ +#include "../nde_c.h" +#include "../DBUtils.h" + +#include + +extern "C" void NDE_HeapInit(); +extern "C" void NDE_HeapQuit(); +static volatile std::atomic _init_count = 0; + +/* NDE_Init isn't thread safe, be aware +best to call on the main thread during initialization +*/ +void NDE_Init() +{ + if ( _init_count.load() == 0 ) + { + NDE_HeapInit(); + HMODULE klib = LoadLibraryW( L"Kernel32.dll" ); + if ( klib ) + { + void *nls = GetProcAddress( klib, "FindNLSString" ); + if ( nls ) + *( (void **)&findNLSString ) = nls; + } + + FreeModule( klib ); + } + + _init_count.fetch_add( 1 ); +} + +void NDE_Quit() +{ + if ( _init_count.fetch_sub( 1 ) == 0 ) + NDE_HeapQuit(); +} \ No newline at end of file -- cgit