Windows: Replace deprecated SHGetFolderPathW
authormano-wii <germano.costa@ig.com.br>
Fri, 1 Nov 2019 17:23:00 +0000 (14:23 -0300)
committermano-wii <germano.costa@ig.com.br>
Fri, 1 Nov 2019 17:23:32 +0000 (14:23 -0300)
No functional change.

Differential Revision: https://developer.blender.org/D6172

intern/ghost/intern/GHOST_DisplayManagerWin32.cpp
intern/ghost/intern/GHOST_SystemPathsWin32.cpp
intern/ghost/intern/GHOST_SystemPathsWin32.h
intern/ghost/intern/GHOST_TaskbarWin32.h

index 3b28f0551913cb7e7bc6b90eb41aae012531083b..aabaffc77324265dd3e3f2325b257631eed8367f 100644 (file)
@@ -24,8 +24,6 @@
 #include "GHOST_DisplayManagerWin32.h"
 #include "GHOST_Debug.h"
 
-#undef _WIN32_WINNT
-#define _WIN32_WINNT 0x501  // require Windows XP or newer
 #define WIN32_LEAN_AND_MEAN
 #include <windows.h>
 
index bdc403b947ebd2c695c7af02a9f0e586b479fddc..63a6b7224b52c33f87b823d5101057f7af45dd53 100644 (file)
@@ -39,15 +39,16 @@ GHOST_SystemPathsWin32::~GHOST_SystemPathsWin32()
 
 const GHOST_TUns8 *GHOST_SystemPathsWin32::getSystemDir(int, const char *versionstr) const
 {
-  static char knownpath[MAX_PATH * 3 + 128] = {
-      0}; /* 1 utf-16 might translante into 3 utf-8. 2 utf-16 translates into 4 utf-8*/
-  wchar_t knownpath_16[MAX_PATH];
+  /* 1 utf-16 might translante into 3 utf-8. 2 utf-16 translates into 4 utf-8*/
+  static char knownpath[MAX_PATH * 3 + 128] = {0};
+  PWSTR knownpath_16 = NULL;
 
-  HRESULT hResult = SHGetFolderPathW(
-      NULL, CSIDL_COMMON_APPDATA, NULL, SHGFP_TYPE_CURRENT, knownpath_16);
+  HRESULT hResult = SHGetKnownFolderPath(
+      FOLDERID_ProgramData, KF_FLAG_DEFAULT, NULL, &knownpath_16);
 
   if (hResult == S_OK) {
     conv_utf_16_to_8(knownpath_16, knownpath, MAX_PATH * 3);
+    CoTaskMemFree(knownpath_16);
     strcat(knownpath, "\\Blender Foundation\\Blender\\");
     strcat(knownpath, versionstr);
     return (GHOST_TUns8 *)knownpath;
@@ -59,12 +60,14 @@ const GHOST_TUns8 *GHOST_SystemPathsWin32::getSystemDir(int, const char *version
 const GHOST_TUns8 *GHOST_SystemPathsWin32::getUserDir(int, const char *versionstr) const
 {
   static char knownpath[MAX_PATH * 3 + 128] = {0};
-  wchar_t knownpath_16[MAX_PATH];
+  PWSTR knownpath_16 = NULL;
 
-  HRESULT hResult = SHGetFolderPathW(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, knownpath_16);
+  HRESULT hResult = SHGetKnownFolderPath(
+      FOLDERID_RoamingAppData, KF_FLAG_DEFAULT, NULL, &knownpath_16);
 
   if (hResult == S_OK) {
     conv_utf_16_to_8(knownpath_16, knownpath, MAX_PATH * 3);
+    CoTaskMemFree(knownpath_16);
     strcat(knownpath, "\\Blender Foundation\\Blender\\");
     strcat(knownpath, versionstr);
     return (GHOST_TUns8 *)knownpath;
index 49d241df633f5edb4e09f1fe7b60e7cb9070f22b..f1924ea51bc6ff0f77ed35ecfa3b0db62b875f40 100644 (file)
@@ -28,8 +28,6 @@
 #  error WIN32 only!
 #endif  // WIN32
 
-#undef _WIN32_WINNT
-#define _WIN32_WINNT 0x501  // require Windows XP or newer
 #define WIN32_LEAN_AND_MEAN
 #include <windows.h>
 
index b1b81337494d3d616143cbb8728098624c3ddec9..abf1172cea84a351e4320e1ffaca07b4295abcce 100644 (file)
 #  error WIN32 only!
 #endif  // WIN32
 
-/* require Windows XP or newer */
-#undef _WIN32_WINNT
-#define _WIN32_WINNT 0x501
-
 #define WIN32_LEAN_AND_MEAN
 #include <windows.h>
 #include <shlobj.h>