From c3851d42e62aa5c5d066a23fbd3fcf394da72c1e Mon Sep 17 00:00:00 2001
From: twinaphex <libretro@gmail.com>
Date: Wed, 9 Aug 2017 13:39:14 +0200
Subject: [PATCH] Convert win32_common.cpp to C - gets rid of all the extern
 "C" references as well. Note to bparker - DragAcceptFiles has a minimum
 dependency for WinXP, might have to go through a function pointer there or
 have a compilation-time ifdef

---
 .../{win32_common.cpp => win32_common.c}      | 46 ++++++++-----------
 gfx/common/win32_common.h                     | 26 +++++------
 griffin/griffin.c                             |  7 +++
 griffin/griffin_cpp.cpp                       |  2 -
 4 files changed, 37 insertions(+), 44 deletions(-)
 rename gfx/common/{win32_common.cpp => win32_common.c} (97%)

diff --git a/gfx/common/win32_common.cpp b/gfx/common/win32_common.c
similarity index 97%
rename from gfx/common/win32_common.cpp
rename to gfx/common/win32_common.c
index c51fc96660..5a338b3441 100644
--- a/gfx/common/win32_common.cpp
+++ b/gfx/common/win32_common.c
@@ -50,20 +50,12 @@
 #include "../../menu/menu_driver.h"
 #endif
 
-#ifndef _MSC_VER
-extern "C" {
-#endif
-
 #include <encodings/utf.h>
 
-LRESULT win32_menu_loop(HWND owner, WPARAM wparam);
-
-#ifndef _MSC_VER
-}
-#endif
+extern LRESULT win32_menu_loop(HWND owner, WPARAM wparam);
 
 #ifdef HAVE_D3D9
-extern "C" bool dinput_handle_message(void *dinput, UINT message,
+extern bool dinput_handle_message(void *dinput, UINT message,
       WPARAM wParam, LPARAM lParam);
 extern void *dinput_gdi;
 extern void *dinput_wgl;
@@ -128,18 +120,15 @@ static HMONITOR win32_monitor_last;
 static HMONITOR win32_monitor_all[MAX_MONITORS];
 static unsigned win32_monitor_count              = 0;
 
-extern "C"
+bool doubleclick_on_titlebar_pressed(void)
 {
-   bool doubleclick_on_titlebar_pressed(void)
-   {
-      return doubleclick_on_titlebar;
-   }
+   return doubleclick_on_titlebar;
+}
 
-   void unset_doubleclick_on_titlebar(void)
-   {
-      doubleclick_on_titlebar = false;
-   }
-};
+void unset_doubleclick_on_titlebar(void)
+{
+   doubleclick_on_titlebar = false;
+}
 
 INT_PTR CALLBACK PickCoreProc(HWND hDlg, UINT message, 
         WPARAM wParam, LPARAM lParam)
@@ -232,7 +221,7 @@ void win32_monitor_get_info(void)
    memset(&current_mon, 0, sizeof(current_mon));
    current_mon.cbSize = sizeof(MONITORINFOEX);
 
-   GetMonitorInfo(win32_monitor_last, (MONITORINFOEX*)&current_mon);
+   GetMonitorInfo(win32_monitor_last, (LPMONITORINFO)&current_mon);
    ChangeDisplaySettingsEx(current_mon.szDevice, NULL, NULL, 0, NULL);
 }
 
@@ -270,7 +259,7 @@ void win32_monitor_info(void *data, void *hm_data, unsigned *mon_id)
 
    memset(mon, 0, sizeof(*mon));
    mon->cbSize = sizeof(MONITORINFOEX);
-   GetMonitorInfo(*hm_to_use, (MONITORINFOEX*)mon);
+   GetMonitorInfo(*hm_to_use, (LPMONITORINFO)mon);
 }
 
 /* Get the count of the files dropped */
@@ -498,7 +487,10 @@ static LRESULT CALLBACK WndProcCommon(bool *quit, HWND hwnd, UINT message,
    return 0;
 }
 
-extern void ui_window_win32_set_droppable(void *data, bool droppable);
+static void win32_set_droppable(ui_window_win32_t *window, bool droppable)
+{
+   DragAcceptFiles(window->hwnd, droppable);
+}
 
 #ifdef HAVE_D3D9
 LRESULT CALLBACK WndProcD3D(HWND hwnd, UINT message,
@@ -536,7 +528,7 @@ LRESULT CALLBACK WndProcD3D(HWND hwnd, UINT message,
             
             win32_window.hwnd     = hwnd;
 
-            ui_window_win32_set_droppable(&win32_window, true);
+            win32_set_droppable(&win32_window, true);
          }
          return 0;
    }
@@ -584,7 +576,7 @@ LRESULT CALLBACK WndProcGL(HWND hwnd, UINT message,
 
             create_graphics_context(hwnd, &g_quit);
 
-            ui_window_win32_set_droppable(&win32_window, true);
+            win32_set_droppable(&win32_window, true);
          }
          return 0;
    }
@@ -670,7 +662,7 @@ LRESULT CALLBACK WndProcGDI(HWND hwnd, UINT message,
 
             create_gdi_context(hwnd, &g_quit);
 
-            ui_window_win32_set_droppable(&win32_window, true);
+            win32_set_droppable(&win32_window, true);
          }
          return 0;
    }
@@ -895,7 +887,7 @@ void win32_set_style(MONITORINFOEX *current_mon, HMONITOR *hm_to_use,
           {}
 
          /* Display settings might have changed, get new coordinates. */
-         GetMonitorInfo(*hm_to_use, (MONITORINFOEX*)current_mon);
+         GetMonitorInfo(*hm_to_use, (LPMONITORINFO)current_mon);
          *mon_rect = current_mon->rcMonitor;
       }
    }
diff --git a/gfx/common/win32_common.h b/gfx/common/win32_common.h
index 10c5f91d5a..975eb5caf8 100644
--- a/gfx/common/win32_common.h
+++ b/gfx/common/win32_common.h
@@ -31,12 +31,16 @@
 
 #ifdef _XBOX
 #include "../../defines/xdk_defines.h"
+#else
+#include "../../ui/drivers/ui_win32_resource.h"
+#include "../../ui/drivers/ui_win32.h"
+#endif
+
+#ifdef __cplusplus
+extern "C" {
 #endif
 
 #ifndef _XBOX
-#include "../../ui/drivers/ui_win32_resource.h"
-#include "../../ui/drivers/ui_win32.h"
-
 extern unsigned g_resize_width;
 extern unsigned g_resize_height;
 extern bool g_inited;
@@ -51,13 +55,7 @@ void create_graphics_context(HWND hwnd, bool *quit);
 
 void create_gdi_context(HWND hwnd, bool *quit);
 
-#ifdef __cplusplus
-extern "C" {
-#endif
 bool gdi_has_menu_frame(void);
-#ifdef __cplusplus
-}
-#endif
 
 bool win32_shader_dlg_init(void);
 void shader_dlg_show(HWND parent_hwnd);
@@ -91,13 +89,7 @@ bool win32_get_metrics(void *data,
 
 void win32_show_cursor(bool state);
 
-#ifdef __cplusplus
-extern "C" {
-#endif
 HWND win32_get_window(void);
-#ifdef __cplusplus
-}
-#endif
 
 bool win32_has_focus(void);
 
@@ -143,4 +135,8 @@ LRESULT CALLBACK WndProcGDI(HWND hwnd, UINT message,
 BOOL IsIconic(HWND hwnd);
 #endif
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif
diff --git a/griffin/griffin.c b/griffin/griffin.c
index 77570f40f9..23d9421dd9 100644
--- a/griffin/griffin.c
+++ b/griffin/griffin.c
@@ -153,6 +153,13 @@ CHEATS
 #include "../managers/cheat_manager.c"
 #include "../libretro-common/hash/rhash.c"
 
+/*============================================================
+UI COMMON CONTEXT
+============================================================ */
+#if defined(_WIN32) && !defined(_XBOX)
+#include "../gfx/common/win32_common.c"
+#endif
+
 /*============================================================
 VIDEO CONTEXT
 ============================================================ */
diff --git a/griffin/griffin_cpp.cpp b/griffin/griffin_cpp.cpp
index 2a5a6c8733..d77594cf55 100644
--- a/griffin/griffin_cpp.cpp
+++ b/griffin/griffin_cpp.cpp
@@ -101,8 +101,6 @@ AUDIO
 UI COMMON CONTEXT
 ============================================================ */
 #if defined(_WIN32) && !defined(_XBOX)
-#include "../gfx/common/win32_common.cpp"
-
 #if defined(HAVE_OPENGL) || defined(HAVE_VULKAN)
 #include "../gfx/drivers_context/wgl_ctx.cpp"
 #endif