Sdl12-compat: MSVC specific DLL entry

From 461e3b56e7b92daaccc639ba5727ec321c0b2ba2 Mon Sep 17 00:00:00 2001
From: Ozkan Sezer <[EMAIL REDACTED]>
Date: Sun, 21 Feb 2021 00:11:32 +0300
Subject: [PATCH] MSVC specific DLL entry.

---
 src/SDL12_compat.c | 26 +++++++++++++++++++++++---
 1 file changed, 23 insertions(+), 3 deletions(-)

diff --git a/src/SDL12_compat.c b/src/SDL12_compat.c
index 6db6ad3..9e3588d 100644
--- a/src/SDL12_compat.c
+++ b/src/SDL12_compat.c
@@ -868,14 +868,33 @@ static void dllinit(void)
         abort();
     }
 }
-
 static void dllquit(void) __attribute__((destructor));
 static void dllquit(void)
 {
     UnloadSDL20();
 }
+
 #elif defined(_MSC_VER) && defined(_WIN32)
-    #error Write me
+BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD reason, LPVOID reserved)
+{
+    switch (reason) {
+    case DLL_PROCESS_DETACH:
+        UnloadSDL20();
+        break;
+
+    case DLL_PROCESS_ATTACH: /* init once for each new process */
+        if (!LoadSDL20()) {
+            return FALSE;
+        }
+        break;
+
+    case DLL_THREAD_ATTACH: /* thread-specific init. */
+    case DLL_THREAD_DETACH: /* thread-specific cleanup */
+        break;
+    }
+    return TRUE;
+}
+
 #elif defined(__WATCOMC__) && defined(__OS2__)
 unsigned _System LibMain(unsigned hmod, unsigned termination)
 {
@@ -889,8 +908,9 @@ unsigned _System LibMain(unsigned hmod, unsigned termination)
     }
     return 1;
 }
+
 #else
-    #error Please define your platform.
+    #error Please define your platform
 #endif
 
 DECLSPEC const SDL_version * SDLCALL