From RobiOneKenobi via https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=9297 :
authorPascal Quantin <pascal.quantin@gmail.com>
Sun, 20 Oct 2013 17:35:30 +0000 (17:35 -0000)
committerPascal Quantin <pascal.quantin@gmail.com>
Sun, 20 Oct 2013 17:35:30 +0000 (17:35 -0000)
Add support for MSVC2013

svn path=/trunk/; revision=52716

capture_win_ifnames.c
config.nmake
epan/dissectors/Makefile.nmake
epan/emem.c
ui/win32/file_dlg_win32.c

index a20945cc8080a6de1c7714b8a547d178a166a857..8dd8d860bf246fd032bb8664565d4e39d388aa52 100644 (file)
@@ -201,6 +201,21 @@ parse_as_guid(const char *guid_text, GUID *guid)
 /**********************************************************************************/
 gboolean IsWindowsVistaOrLater()
 {
+#if (_MSC_VER >= 1800)
+    /*
+     * On VS2103, GetVersionEx is deprecated. Microsoft recommend to
+     * use VerifyVersionInfo instead
+     */
+    OSVERSIONINFOEX osvi;
+    DWORDLONG dwlConditionMask = 0;
+    int op = VER_GREATER_EQUAL;
+
+    ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
+    osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
+    osvi.dwMajorVersion = 6;
+    VER_SET_CONDITION(dwlConditionMask, VER_MAJORVERSION, op);
+    return VerifyVersionInfo(&osvi, VER_MAJORVERSION, dwlConditionMask);
+#else
     OSVERSIONINFO osvi;
 
     SecureZeroMemory(&osvi, sizeof(OSVERSIONINFO));
@@ -210,6 +225,7 @@ gboolean IsWindowsVistaOrLater()
         return osvi.dwMajorVersion >= 6;
     }
     return FALSE;
+#endif
 }
 
 /**********************************************************************************/
index b4f7acc5f378b2c1d55519fdc97c8b317ab5069d..0017c959034868a0999bf5f1fc7577e5dad600c0 100644 (file)
@@ -145,6 +145,14 @@ PROCESSOR_ARCHITECTURE=amd64
 # Visual C++ 11.0, _MSC_VER 1700, msvcr110.dll
 #MSVC_VARIANT=MSVC2012
 
+# "Microsoft Visual Studio 2013"
+# Visual C++ 12.0, _MSC_VER 1800, msvcr120.dll
+#MSVC_VARIANT=MSVC2013
+
+# "Microsoft Visual Studio 2013 Express Edition"
+# Visual C++ 12.0, _MSC_VER 1800, msvcr120.dll
+#MSVC_VARIANT=MSVC2013EE
+
 # The default if we haven't set a system environment variable or
 # uncommented an entry above.  We default to the version recommended
 # in the Developer's Guide, namely MSVC++ 2010 Express Edition.
@@ -864,6 +872,8 @@ MSC_VER_REQUIRED=1500
 MSC_VER_REQUIRED=1600
 !ELSEIF "$(MSVC_VARIANT)" == "MSVC2012" ||  "$(MSVC_VARIANT)" == "MSVC2012EE"
 MSC_VER_REQUIRED=1700
+!ELSEIF "$(MSVC_VARIANT)" == "MSVC2013" ||  "$(MSVC_VARIANT)" == "MSVC2013EE"
+MSC_VER_REQUIRED=1800
 !ELSE
 !ERROR MSVC_VARIANT unknown
 !ENDIF
@@ -921,7 +931,9 @@ APPVER=5.02
         "$(MSVC_VARIANT)" == "MSVC2010"   || \
         "$(MSVC_VARIANT)" == "MSVC2010EE" || \
         "$(MSVC_VARIANT)" == "MSVC2012"   || \
-        "$(MSVC_VARIANT)" == "MSVC2012EE"
+        "$(MSVC_VARIANT)" == "MSVC2012EE" || \
+        "$(MSVC_VARIANT)" == "MSVC2013"   || \
+        "$(MSVC_VARIANT)" == "MSVC2013EE"
 LOCAL_CFLAGS=/Zi /W3 /MD /DWIN32_LEAN_AND_MEAN /DMSC_VER_REQUIRED=$(MSC_VER_REQUIRED) \
             /D_CRT_SECURE_NO_DEPRECATE /D_CRT_NONSTDC_NO_DEPRECATE -DPSAPI_VERSION=1
 
@@ -956,7 +968,9 @@ WARNINGS_CFLAGS=/w34295
         "$(MSVC_VARIANT)" == "MSVC2010"   || \
         "$(MSVC_VARIANT)" == "MSVC2010EE" || \
         "$(MSVC_VARIANT)" == "MSVC2012"   || \
-        "$(MSVC_VARIANT)" == "MSVC2012EE"
+        "$(MSVC_VARIANT)" == "MSVC2012EE" || \
+        "$(MSVC_VARIANT)" == "MSVC2013"   || \
+        "$(MSVC_VARIANT)" == "MSVC2013EE"
 LOCAL_CFLAGS= $(LOCAL_CFLAGS) /MP
 !ENDIF
 
@@ -1138,7 +1152,23 @@ MSVCR_DLL=$(PROGRAM_FILES)\Microsoft Visual Studio 10.0\VC\redist\$(TARGET_MACHI
 # with Visual Studio 2010.
 #
 MSVCR_DLL=$(PROGRAM_FILES)\Microsoft Visual Studio 11.0\VC\redist\$(TARGET_MACHINE)\Microsoft.VC110.CRT\*.*
-
+!ELSEIF "$(MSVC_VARIANT)" == "MSVC2013" || "$(MSVC_VARIANT)" == "MSVC2013EE"
+#
+# EE version added as per bug https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=9227
+#
+# For MSVC 2013, we "Install a particular Visual C++
+# assembly as a private assembly for the application", by copying
+# the contents of the Microsoft.VC120.CRT folder to the target directory.
+# This is done to reduce the size of the installer; it also makes
+# a portable version work, as the C runtime doesn't have to be
+# installed on the target machine.
+#
+# Note: for what it's worth, Microsoft recommends "Using the Visual C++
+# Redistributable Package", rather than "Installing a particular Visual
+# C++ assembly as a private assembly for the application", starting
+# with Visual Studio 2010.
+#
+MSVCR_DLL=$(PROGRAM_FILES)\Microsoft Visual Studio 12.0\VC\redist\$(TARGET_MACHINE)\Microsoft.VC120.CRT\*.*
 !ELSE
 !ERROR MSVC_VARIANT unknown
 !ENDIF
index b62c81a20b4076f79845534659da90c18bfa5e73..6e4df3adf9a64cf2fd47cedb80d6436aaa2784cf 100644 (file)
@@ -36,7 +36,9 @@ dissectors.lib: register.obj packet-ncp2222.c $(GENERATED_HEADER_FILES) ../../co
        "$(MSVC_VARIANT)" != "MSVC2010"   && \
        "$(MSVC_VARIANT)" != "MSVC2010EE" && \
        "$(MSVC_VARIANT)" != "MSVC2012"   && \
-       "$(MSVC_VARIANT)" != "MSVC2012EE"
+       "$(MSVC_VARIANT)" != "MSVC2012EE" && \
+       "$(MSVC_VARIANT)" != "MSVC2013"   && \
+       "$(MSVC_VARIANT)" != "MSVC2013EE"
 # Disable debug for large dissectors
 packet-rrc.obj : packet-rrc.c
        $(CC) $(CFLAGS) /Zd /Fd.\ -c $?
index 15624e657165a72594e00518aa50c2a01fdfe3f8..d1de44565f24445aaaf764711e20c2e099a8b12c 100644 (file)
@@ -174,7 +174,7 @@ static gboolean debug_use_memory_scrubber = FALSE;
 
 #if defined (_WIN32)
 static SYSTEM_INFO sysinfo;
-static OSVERSIONINFO versinfo;
+static gboolean iswindowsplatform;
 static int pagesize;
 #elif defined(USE_GUARD_PAGES)
 static intptr_t pagesize;
@@ -389,6 +389,23 @@ emem_init(void)
        GetSystemInfo(&sysinfo);
        pagesize = sysinfo.dwPageSize;
 
+#if (_MSC_VER >= 1800)
+       /*
+        * On VS2103, GetVersionEx is deprecated. Microsoft recommend to
+        * use VerifyVersionInfo instead
+        */
+       {
+               OSVERSIONINFOEX osvi;
+               DWORDLONG dwlConditionMask = 0;
+               int op = VER_EQUAL;
+
+               ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
+               osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
+               osvi.dwPlatformId = VER_PLATFORM_WIN32_WINDOWS;
+               VER_SET_CONDITION(dwlConditionMask, VER_PLATFORMID, op);
+               iswindowsplatform = VerifyVersionInfo(&osvi, VER_PLATFORMID, dwlConditionMask);
+       }
+#else
        /* calling GetVersionEx using the OSVERSIONINFO structure.
         * OSVERSIONINFOEX requires Win NT4 with SP6 or newer NT Versions.
         * OSVERSIONINFOEX will fail on Win9x and older NT Versions.
@@ -397,8 +414,15 @@ emem_init(void)
         * http://msdn.microsoft.com/library/en-us/sysinfo/base/osversioninfo_str.asp
         * http://msdn.microsoft.com/library/en-us/sysinfo/base/osversioninfoex_str.asp
         */
-       versinfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
-       GetVersionEx(&versinfo);
+       {
+               OSVERSIONINFO versinfo;
+
+               ZeroMemory(&versinfo, sizeof(OSVERSIONINFO));
+               versinfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
+               GetVersionEx(&versinfo);
+               iswindowsplatform = (versinfo.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS);
+       }
+#endif
 
 #elif defined(USE_GUARD_PAGES)
        pagesize = sysconf(_SC_PAGESIZE);
@@ -734,9 +758,9 @@ emem_create_chunk_gp(size_t size)
        prot2 = (char *) ((((intptr_t) buf_end - (1 * pagesize)) / pagesize) * pagesize);
 
        ret = VirtualProtect(prot1, pagesize, PAGE_NOACCESS, &oldprot);
-       g_assert(ret != 0 || versinfo.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS);
+       g_assert(ret != 0 || iswindowsplatform);
        ret = VirtualProtect(prot2, pagesize, PAGE_NOACCESS, &oldprot);
-       g_assert(ret != 0 || versinfo.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS);
+       g_assert(ret != 0 || iswindowsplatform);
 
        npc->amount_free_init = (unsigned int) (prot2 - prot1 - pagesize);
        npc->free_offset_init = (unsigned int) (prot1 - npc->buf) + pagesize;
index b2d8d2912836bf09ad70db7872bf326e11eb070d..110754fed9b6d1a5f06a7768fba364282feed1ef 100644 (file)
@@ -127,6 +127,65 @@ static print_args_t    print_args;
 static HWND  g_sf_hwnd = NULL;
 static char *g_dfilter_str = NULL;
 
+static int
+win32_get_ofnsize()
+{
+    gboolean bVerGE5 = FALSE;
+    int ofnsize;
+    /* Remarks on OPENFILENAME_SIZE_VERSION_400:
+    *
+    * MSDN states that OPENFILENAME_SIZE_VERSION_400 should be used with
+    * WINVER and _WIN32_WINNT >= 0x0500.
+    * Unfortunately all these are compiler constants, while the underlying is a
+    * problem based is a length check of the runtime version used.
+    *
+    * Instead of using OPENFILENAME_SIZE_VERSION_400, just malloc
+    * the OPENFILENAME size plus 12 bytes.
+    * These 12 bytes are the difference between the two versions of this struct.
+    *
+    * Interestingly this fixes a bug, so the places bar e.g. "My Documents"
+    * is displayed - which wasn't the case with the former implementation.
+    *
+    * XXX - It's unclear if this length+12 works on all supported platforms,
+    * NT4 is the question here. However, even if it fails, we must calculate
+    * the length based on the runtime, not the compiler version anyway ...
+    */
+    /* This assumption does not work when compiling with MSVC2008EE as
+    * the open dialog window does not appear.
+    * Instead detect Windows version at runtime and choose size accordingly */
+#if (_MSC_VER >= 1500)
+    /*
+    * On VS2103, GetVersionEx is deprecated. Microsoft recommend to
+    * use VerifyVersionInfo instead
+    */
+#if (_MSC_VER >= 1800)
+    OSVERSIONINFOEX osvi;
+    DWORDLONG dwlConditionMask = 0;
+    int op = VER_GREATER_EQUAL;
+    /* Initialize the OSVERSIONINFOEX structure. */
+    SecureZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
+    osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
+    osvi.dwMajorVersion = 5;
+    /* Initialize the condition mask. */
+    VER_SET_CONDITION(dwlConditionMask, VER_MAJORVERSION, op);
+    /* Perform the test. */
+    bVerGE5=VerifyVersionInfo(
+        &osvi,
+        VER_MAJORVERSION,
+        dwlConditionMask);
+#else
+    OSVERSIONINFO osvi;
+    SecureZeroMemory(&osvi, sizeof(OSVERSIONINFO));
+    osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
+    GetVersionEx(&osvi);
+    bVerGE5 = (osvi.dwMajorVersion >= 5);
+#endif /* _MSC_VER >= 1800 */
+    ofnsize = (bVerGE5)?sizeof(OPENFILENAME):OPENFILENAME_SIZE_VERSION_400;
+#else
+    ofnsize = sizeof(OPENFILENAME)+12;
+#endif /* _MSC_VER >= 1500 */
+    return ofnsize;
+}
 /*
  * According to http://msdn.microsoft.com/en-us/library/bb776913.aspx
  * we should use IFileOpenDialog and IFileSaveDialog on Windows Vista
@@ -139,9 +198,6 @@ win32_open_file (HWND h_wnd, GString *file_name, GString *display_filter) {
     TCHAR file_name16[MAX_PATH] = _T("");
     int ofnsize;
     gboolean gofn_ok;
-#if (_MSC_VER >= 1500)
-    OSVERSIONINFO osvi;
-#endif
 
     if (!file_name || !display_filter)
         return FALSE;
@@ -156,40 +212,7 @@ win32_open_file (HWND h_wnd, GString *file_name, GString *display_filter) {
         g_free(g_dfilter_str);
         g_dfilter_str = NULL;
     }
-
-    /* Remarks on OPENFILENAME_SIZE_VERSION_400:
-     *
-     * MSDN states that OPENFILENAME_SIZE_VERSION_400 should be used with
-     * WINVER and _WIN32_WINNT >= 0x0500.
-     * Unfortunately all these are compiler constants, while the underlying is a
-     * problem based is a length check of the runtime version used.
-     *
-     * Instead of using OPENFILENAME_SIZE_VERSION_400, just malloc
-     * the OPENFILENAME size plus 12 bytes.
-     * These 12 bytes are the difference between the two versions of this struct.
-     *
-     * Interestingly this fixes a bug, so the places bar e.g. "My Documents"
-     * is displayed - which wasn't the case with the former implementation.
-     *
-     * XXX - It's unclear if this length+12 works on all supported platforms,
-     * NT4 is the question here. However, even if it fails, we must calculate
-     * the length based on the runtime, not the compiler version anyway ...
-     */
-    /* This assumption does not work when compiling with MSVC2008EE as
-     * the open dialog window does not appear.
-     * Instead detect Windows version at runtime and choose size accordingly */
-#if (_MSC_VER >= 1500)
-    SecureZeroMemory(&osvi, sizeof(OSVERSIONINFO));
-    osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
-    GetVersionEx(&osvi);
-    if (osvi.dwMajorVersion >= 5) {
-        ofnsize = sizeof(OPENFILENAME);
-    } else {
-        ofnsize = OPENFILENAME_SIZE_VERSION_400;
-    }
-#else
-    ofnsize = sizeof(OPENFILENAME) + 12;
-#endif
+    ofnsize = win32_get_ofnsize();
     ofn = g_malloc0(ofnsize);
 
     ofn->lStructSize = ofnsize;
@@ -331,9 +354,6 @@ win32_save_as_file(HWND h_wnd, capture_file *cf, GString *file_name, int *file_t
     TCHAR  file_name16[MAX_PATH] = _T("");
     int    ofnsize;
     gboolean gsfn_ok;
-#if (_MSC_VER >= 1500)
-    OSVERSIONINFO osvi;
-#endif
     gboolean discard_comments = FALSE;
 
     if (!file_name || !file_type || !compressed)
@@ -355,19 +375,7 @@ win32_save_as_file(HWND h_wnd, capture_file *cf, GString *file_name, int *file_t
         return FALSE;  /* shouldn't happen - the "Save As..." item should be disabled if we can't save the file */
     g_compressed = FALSE;
 
-    /* see OPENFILENAME comment in win32_open_file */
-#if (_MSC_VER >= 1500)
-    SecureZeroMemory(&osvi, sizeof(OSVERSIONINFO));
-    osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
-    GetVersionEx(&osvi);
-    if (osvi.dwMajorVersion >= 5) {
-        ofnsize = sizeof(OPENFILENAME);
-    } else {
-        ofnsize = OPENFILENAME_SIZE_VERSION_400;
-    }
-#else
-    ofnsize = sizeof(OPENFILENAME) + 12;
-#endif
+    ofnsize = win32_get_ofnsize();
     ofn = g_malloc0(ofnsize);
 
     ofn->lStructSize = ofnsize;
@@ -428,9 +436,6 @@ win32_export_specified_packets_file(HWND h_wnd, capture_file *cf,
     TCHAR  file_name16[MAX_PATH] = _T("");
     int    ofnsize;
     gboolean gsfn_ok;
-#if (_MSC_VER >= 1500)
-    OSVERSIONINFO osvi;
-#endif
 
     if (!file_name || !file_type || !compressed || !range)
         return FALSE;
@@ -448,19 +453,7 @@ win32_export_specified_packets_file(HWND h_wnd, capture_file *cf,
     g_cf = cf;
     g_compressed = FALSE;
 
-    /* see OPENFILENAME comment in win32_open_file */
-#if (_MSC_VER >= 1500)
-    SecureZeroMemory(&osvi, sizeof(OSVERSIONINFO));
-    osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
-    GetVersionEx(&osvi);
-    if (osvi.dwMajorVersion >= 5) {
-        ofnsize = sizeof(OPENFILENAME);
-    } else {
-        ofnsize = OPENFILENAME_SIZE_VERSION_400;
-    }
-#else
-    ofnsize = sizeof(OPENFILENAME) + 12;
-#endif
+    ofnsize = win32_get_ofnsize();
     ofn = g_malloc0(ofnsize);
 
     ofn->lStructSize = ofnsize;
@@ -518,9 +511,6 @@ win32_merge_file (HWND h_wnd, GString *file_name, GString *display_filter, int *
     TCHAR         file_name16[MAX_PATH] = _T("");
     int           ofnsize;
     gboolean gofn_ok;
-#if (_MSC_VER >= 1500)
-    OSVERSIONINFO osvi;
-#endif
 
     if (!file_name || !display_filter || !merge_type)
         return FALSE;
@@ -536,19 +526,7 @@ win32_merge_file (HWND h_wnd, GString *file_name, GString *display_filter, int *
         g_dfilter_str = NULL;
     }
 
-    /* see OPENFILENAME comment in win32_open_file */
-#if (_MSC_VER >= 1500)
-    SecureZeroMemory(&osvi, sizeof(OSVERSIONINFO));
-    osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
-    GetVersionEx(&osvi);
-    if (osvi.dwMajorVersion >= 5) {
-        ofnsize = sizeof(OPENFILENAME);
-    } else {
-        ofnsize = OPENFILENAME_SIZE_VERSION_400;
-    }
-#else
-    ofnsize = sizeof(OPENFILENAME) + 12;
-#endif
+    ofnsize = win32_get_ofnsize();
     ofn = g_malloc0(ofnsize);
 
     ofn->lStructSize = ofnsize;
@@ -610,25 +588,10 @@ win32_export_file(HWND h_wnd, capture_file *cf, export_type_e export_type) {
     char             *dirname;
     cf_print_status_t status;
     int               ofnsize;
-#if (_MSC_VER >= 1500)
-    OSVERSIONINFO osvi;
-#endif
 
     g_cf = cf;
 
-    /* see OPENFILENAME comment in win32_open_file */
-#if (_MSC_VER >= 1500)
-    SecureZeroMemory(&osvi, sizeof(OSVERSIONINFO));
-    osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
-    GetVersionEx(&osvi);
-    if (osvi.dwMajorVersion >= 5) {
-        ofnsize = sizeof(OPENFILENAME);
-    } else {
-        ofnsize = OPENFILENAME_SIZE_VERSION_400;
-    }
-#else
-    ofnsize = sizeof(OPENFILENAME) + 12;
-#endif
+    ofnsize = win32_get_ofnsize();
     ofn = g_malloc0(ofnsize);
 
     ofn->lStructSize = ofnsize;
@@ -729,9 +692,6 @@ win32_export_raw_file(HWND h_wnd, capture_file *cf) {
     char         *file_name8;
     int           fd;
     int           ofnsize;
-#if (_MSC_VER >= 1500)
-    OSVERSIONINFO osvi;
-#endif
 
     if (!cf->finfo_selected) {
         /* This shouldn't happen */
@@ -739,19 +699,7 @@ win32_export_raw_file(HWND h_wnd, capture_file *cf) {
         return;
     }
 
-    /* see OPENFILENAME comment in win32_open_file */
-#if (_MSC_VER >= 1500)
-    SecureZeroMemory(&osvi, sizeof(OSVERSIONINFO));
-    osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
-    GetVersionEx(&osvi);
-    if (osvi.dwMajorVersion >= 5) {
-        ofnsize = sizeof(OPENFILENAME);
-    } else {
-        ofnsize = OPENFILENAME_SIZE_VERSION_400;
-    }
-#else
-    ofnsize = sizeof(OPENFILENAME) + 12;
-#endif
+    ofnsize = win32_get_ofnsize();
     ofn = g_malloc0(ofnsize);
 
     ofn->lStructSize = ofnsize;
@@ -818,9 +766,6 @@ win32_export_sslkeys_file(HWND h_wnd) {
     int           fd;
     int           ofnsize;
     int           keylist_size;
-#if (_MSC_VER >= 1500)
-    OSVERSIONINFO osvi;
-#endif
 
     keylist_size = ssl_session_key_count();
     if (keylist_size==0) {
@@ -829,19 +774,7 @@ win32_export_sslkeys_file(HWND h_wnd) {
         return;
     }
 
-    /* see OPENFILENAME comment in win32_open_file */
-#if (_MSC_VER >= 1500)
-    SecureZeroMemory(&osvi, sizeof(OSVERSIONINFO));
-    osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
-    GetVersionEx(&osvi);
-    if (osvi.dwMajorVersion >= 5) {
-        ofnsize = sizeof(OPENFILENAME);
-    } else {
-        ofnsize = OPENFILENAME_SIZE_VERSION_400;
-    }
-#else
-    ofnsize = sizeof(OPENFILENAME) + 12;
-#endif
+    ofnsize = win32_get_ofnsize();
     ofn = g_malloc0(ofnsize);
 
     ofn->lStructSize = ofnsize;
@@ -906,23 +839,8 @@ win32_export_color_file(HWND h_wnd, capture_file *cf, gpointer filter_list) {
     TCHAR  file_name[MAX_PATH] = _T("");
     gchar *dirname;
     int    ofnsize;
-#if (_MSC_VER >= 1500)
-    OSVERSIONINFO osvi;
-#endif
 
-    /* see OPENFILENAME comment in win32_open_file */
-#if (_MSC_VER >= 1500)
-    SecureZeroMemory(&osvi, sizeof(OSVERSIONINFO));
-    osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
-    GetVersionEx(&osvi);
-    if (osvi.dwMajorVersion >= 5) {
-        ofnsize = sizeof(OPENFILENAME);
-    } else {
-        ofnsize = OPENFILENAME_SIZE_VERSION_400;
-    }
-#else
-    ofnsize = sizeof(OPENFILENAME) + 12;
-#endif
+    ofnsize = win32_get_ofnsize();
     ofn = g_malloc0(ofnsize);
 
     ofn->lStructSize = ofnsize;
@@ -967,23 +885,8 @@ win32_import_color_file(HWND h_wnd, gpointer color_filters) {
     TCHAR  file_name[MAX_PATH] = _T("");
     gchar *dirname;
     int    ofnsize;
-#if (_MSC_VER >= 1500)
-    OSVERSIONINFO osvi;
-#endif
 
-    /* see OPENFILENAME comment in win32_open_file */
-#if (_MSC_VER >= 1500)
-    SecureZeroMemory(&osvi, sizeof(OSVERSIONINFO));
-    osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
-    GetVersionEx(&osvi);
-    if (osvi.dwMajorVersion >= 5) {
-        ofnsize = sizeof(OPENFILENAME);
-    } else {
-        ofnsize = OPENFILENAME_SIZE_VERSION_400;
-    }
-#else
-    ofnsize = sizeof(OPENFILENAME) + 12;
-#endif
+    ofnsize = win32_get_ofnsize();
     ofn = g_malloc0(ofnsize);
 
     ofn->lStructSize = ofnsize;