aboutsummaryrefslogtreecommitdiff
path: root/Src/nde/win/nde_init.cpp
diff options
context:
space:
mode:
authorJef <jef@targetspot.com>2024-09-24 08:54:57 -0400
committerJef <jef@targetspot.com>2024-09-24 08:54:57 -0400
commit20d28e80a5c861a9d5f449ea911ab75b4f37ad0d (patch)
tree12f17f78986871dd2cfb0a56e5e93b545c1ae0d0 /Src/nde/win/nde_init.cpp
parent537bcbc86291b32fc04ae4133ce4d7cac8ebe9a7 (diff)
downloadwinamp-20d28e80a5c861a9d5f449ea911ab75b4f37ad0d.tar.gz
Initial community commit
Diffstat (limited to 'Src/nde/win/nde_init.cpp')
-rw-r--r--Src/nde/win/nde_init.cpp36
1 files changed, 36 insertions, 0 deletions
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 <atomic>
+
+extern "C" void NDE_HeapInit();
+extern "C" void NDE_HeapQuit();
+static volatile std::atomic<std::size_t> _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