Bug 1331171 - Part 1: Remove StartupSpecialSystemDirectory() workaround for Windows XP. r?jimm
SHGetKnownFolderPath() is available on Windows Vista+ so we no longer need to GetProcAddress("SHGetKnownFolderPath"). We can set _WIN32_WINNT 0x0600 to expose the SHGetKnownFolderPath function declaration in shlobj.h and call it directly.
Also remove a redundant #include <shlobj.h>.
MozReview-Commit-ID: AoAlrfvQ5AB
--- a/xpcom/build/XPCOMInit.cpp
+++ b/xpcom/build/XPCOMInit.cpp
@@ -578,18 +578,16 @@ NS_InitXPCOM2(nsIServiceManager** aResul
#endif
#if defined(XP_UNIX)
NS_StartupNativeCharsetUtils();
#endif
NS_StartupLocalFile();
- StartupSpecialSystemDirectory();
-
nsDirectoryService::RealInit();
bool value;
if (aBinDirectory) {
rv = aBinDirectory->IsDirectory(&value);
if (NS_SUCCEEDED(rv) && value) {
--- a/xpcom/io/SpecialSystemDirectory.cpp
+++ b/xpcom/io/SpecialSystemDirectory.cpp
@@ -6,18 +6,22 @@
#include "SpecialSystemDirectory.h"
#include "nsString.h"
#include "nsDependentString.h"
#include "nsAutoPtr.h"
#if defined(XP_WIN)
+#ifdef _WIN32_WINNT
+#undef _WIN32_WINNT
+#endif
+#define _WIN32_WINNT 0x0600
+
#include <windows.h>
-#include <shlobj.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <direct.h>
#include <shlobj.h>
#include <knownfolders.h>
#include <guiddef.h>
#include "mozilla/WindowsVersion.h"
@@ -43,50 +47,27 @@ using mozilla::IsWin7OrLater;
#define MAXPATHLEN _MAX_PATH
#elif defined(CCHMAXPATH)
#define MAXPATHLEN CCHMAXPATH
#else
#define MAXPATHLEN 1024
#endif
#endif
-#ifdef XP_WIN
-typedef HRESULT (WINAPI* nsGetKnownFolderPath)(GUID& rfid,
- DWORD dwFlags,
- HANDLE hToken,
- PWSTR* ppszPath);
-
-static nsGetKnownFolderPath gGetKnownFolderPath = nullptr;
-#endif
-
-void
-StartupSpecialSystemDirectory()
-{
-#if defined (XP_WIN)
- // SHGetKnownFolderPath is only available on Windows Vista
- // so that we need to use GetProcAddress to get the pointer.
- HMODULE hShell32DLLInst = GetModuleHandleW(L"shell32.dll");
- if (hShell32DLLInst) {
- gGetKnownFolderPath = (nsGetKnownFolderPath)
- GetProcAddress(hShell32DLLInst, "SHGetKnownFolderPath");
- }
-#endif
-}
-
#if defined (XP_WIN)
static nsresult
GetKnownFolder(GUID* aGuid, nsIFile** aFile)
{
- if (!aGuid || !gGetKnownFolderPath) {
+ if (!aGuid) {
return NS_ERROR_FAILURE;
}
PWSTR path = nullptr;
- gGetKnownFolderPath(*aGuid, 0, nullptr, &path);
+ SHGetKnownFolderPath(*aGuid, 0, nullptr, &path);
if (!path) {
return NS_ERROR_FAILURE;
}
nsresult rv = NS_NewLocalFile(nsDependentString(path),
true,
aFile);
--- a/xpcom/io/SpecialSystemDirectory.h
+++ b/xpcom/io/SpecialSystemDirectory.h
@@ -11,19 +11,16 @@
#include "nsIFile.h"
#ifdef MOZ_WIDGET_COCOA
#include <Carbon/Carbon.h>
#include "nsILocalFileMac.h"
#include "prenv.h"
#endif
-extern void StartupSpecialSystemDirectory();
-
-
enum SystemDirectories {
OS_DriveDirectory = 1,
OS_TemporaryDirectory = 2,
OS_CurrentProcessDirectory = 3,
OS_CurrentWorkingDirectory = 4,
XPCOM_CurrentProcessComponentDirectory = 5,
XPCOM_CurrentProcessComponentRegistry = 6,