Bug 1500047 - change some Windows-only code to WCHAR. r=emk
authorJorg K <jorgk@jorgk.com>
Fri, 19 Oct 2018 09:41:03 +0200
changeset 33415 a8bb4bbd32e6ddd33c35a50d5d734cb592eaf6f6
parent 33414 952e3c43da389b749dfc7bfb84d5f6df84bbb699
child 33416 3a91ffa3617c611a043c9df09546a06d71831cd7
push id387
push userclokep@gmail.com
push dateMon, 10 Dec 2018 21:30:47 +0000
reviewersemk
bugs1500047
Bug 1500047 - change some Windows-only code to WCHAR. r=emk
mailnews/addrbook/src/nsWabAddressBook.cpp
mailnews/mapi/mapihook/src/Registry.cpp
--- a/mailnews/addrbook/src/nsWabAddressBook.cpp
+++ b/mailnews/addrbook/src/nsWabAddressBook.cpp
@@ -8,60 +8,60 @@
 #include "mozilla/Logging.h"
 #include "mozilla/DebugOnly.h"
 
 using namespace mozilla;
 
 static LazyLogModule gWabAddressBookLog("WABAddressBook");
 
 #define PRINTF(args) MOZ_LOG(gWabAddressBookLog, mozilla::LogLevel::Debug, args)
+#define WAB_DLL_NAMEW L"" WAB_DLL_NAME
 
 HMODULE nsWabAddressBook::mLibrary = NULL ;
 int32_t nsWabAddressBook::mLibUsage = 0 ;
 LPWABOPEN nsWabAddressBook::mWABOpen = NULL ;
 LPWABOBJECT nsWabAddressBook::mRootSession = NULL ;
 LPADRBOOK nsWabAddressBook::mRootBook = NULL ;
 
 BOOL nsWabAddressBook::LoadWabLibrary(void)
 {
     if (mLibrary) { ++ mLibUsage ; return TRUE ; }
+
     // We try to fetch the location of the WAB DLL from the registry
-    TCHAR wabDLLPath [MAX_PATH] ;
+    WCHAR wabDLLPath [MAX_PATH] ;
     DWORD keyType = 0 ;
     ULONG byteCount = sizeof(wabDLLPath) ;
     HKEY keyHandle = NULL ;
     wabDLLPath [MAX_PATH - 1] = 0 ;
     if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, WAB_DLL_PATH_KEY, 0, KEY_READ, &keyHandle) == ERROR_SUCCESS) {
-        RegQueryValueEx(keyHandle, "", NULL, &keyType, (LPBYTE) wabDLLPath, &byteCount) ;
+        RegQueryValueExW(keyHandle, L"", NULL, &keyType, (LPBYTE) wabDLLPath, &byteCount) ;
         if (keyType == REG_EXPAND_SZ) {
             // Expand the environment variables
-            DWORD bufferSize = ExpandEnvironmentStrings(wabDLLPath, NULL, 0);
+            DWORD bufferSize = ExpandEnvironmentStringsW(wabDLLPath, NULL, 0);
             if (bufferSize && bufferSize < MAX_PATH) {
-                TCHAR tmp[MAX_PATH];
-                ExpandEnvironmentStrings(wabDLLPath, tmp, bufferSize);
-                _tcscpy(wabDLLPath, tmp);
+                WCHAR tmp[MAX_PATH];
+                ExpandEnvironmentStringsW(wabDLLPath, tmp, bufferSize);
+                wcscpy(wabDLLPath, tmp);
             }
             else {
                 return FALSE;
             }
         }
     }
     else {
-        if (GetSystemDirectory(wabDLLPath, MAX_PATH)) {
-            _tcsncat(wabDLLPath, WAB_DLL_NAME,
-                     std::min(_tcslen(WAB_DLL_NAME), MAX_PATH - _tcslen(wabDLLPath) - 1));
+        if (GetSystemDirectoryW(wabDLLPath, MAX_PATH)) {
+            wcsncat(wabDLLPath, WAB_DLL_NAMEW,
+                     std::min(wcslen(WAB_DLL_NAMEW), MAX_PATH - wcslen(wabDLLPath) - 1));
         }
         else {
             return FALSE;
         }
     }
     if (keyHandle) { RegCloseKey(keyHandle) ; }
-    mLibrary = LoadLibraryW((lstrlen(wabDLLPath))
-      ? NS_ConvertASCIItoUTF16(wabDLLPath).get()
-      : NS_ConvertASCIItoUTF16(WAB_DLL_NAME).get());
+    mLibrary = LoadLibraryW((lstrlenW(wabDLLPath)) ? wabDLLPath : WAB_DLL_NAMEW);
     if (!mLibrary) { return FALSE ; }
     ++ mLibUsage ;
     mWABOpen = reinterpret_cast<LPWABOPEN>(GetProcAddress(mLibrary, "WABOpen")) ;
     if (!mWABOpen) { return FALSE ; }
     HRESULT retCode = mWABOpen(&mRootBook, &mRootSession, NULL, 0) ;
 
     if (HR_FAILED(retCode)) {
         PRINTF(("Cannot initialize WAB %08x.\n", retCode)) ; return FALSE ;
--- a/mailnews/mapi/mapihook/src/Registry.cpp
+++ b/mailnews/mapi/mapihook/src/Registry.cpp
@@ -4,17 +4,17 @@
 
 #undef _UNICODE
 #undef UNICODE
 
 #include <objbase.h>
 #include "nsString.h"
 #include "Registry.h"
 
-#define MAPI_PROXY_DLL_NAME   "MapiProxy.dll"
+#define MAPI_PROXY_DLL_NAME   u"MapiProxy.dll"
 #define MAPI_STARTUP_ARG      " /MAPIStartUp"
 #define MAX_SIZE              2048
 
 // Size of a CLSID as a string
 const int CLSID_STRING_SIZE = 39;
 
 // Proxy/Stub Dll Routines
 
@@ -116,71 +116,71 @@ LONG recursiveDeleteKey(HKEY hKeyParent,
     return RegDeleteKey(hKeyParent, lpszKeyChild) ;
 }
 
 void RegisterProxy()
 {
     HINSTANCE h = NULL;
     ProxyServer *RegisterFunc = NULL;
 
-    char szModule[MAX_SIZE];
-    char *pTemp = NULL;
+    WCHAR szModule[MAX_SIZE];
+    WCHAR *pTemp = NULL;
 
     HMODULE hModule = GetModuleHandle(NULL);
-    DWORD dwResult  = ::GetModuleFileName(hModule, szModule,
-                                          sizeof(szModule)/sizeof(char));
+    DWORD dwResult  = ::GetModuleFileNameW(hModule, szModule,
+                                           sizeof(szModule)/sizeof(WCHAR));
     if (dwResult == 0)
         return;
 
-    pTemp = strrchr(szModule, '\\');
+    pTemp = wcsrchr(szModule, L'\\');
     if (pTemp == NULL)
         return;
 
     *pTemp = '\0';
-    nsAutoCString proxyPath(szModule);
+    nsAutoString proxyPath(szModule);
 
-    proxyPath += "\\";
+    proxyPath += u"\\";
     proxyPath += MAPI_PROXY_DLL_NAME;
 
-    h = LoadLibraryW(NS_ConvertASCIItoUTF16(proxyPath).get());
+    h = LoadLibraryW(proxyPath.get());
     if (h == NULL)
         return;
 
     RegisterFunc = (ProxyServer *) GetProcAddress(h, "DllRegisterServer");
     if (RegisterFunc)
         RegisterFunc();
 
     FreeLibrary(h);
 }
 
 void UnRegisterProxy()
 {
     HINSTANCE h = NULL;
     ProxyServer *UnRegisterFunc = NULL;
 
-    char szModule[MAX_SIZE];
-    char *pTemp = NULL;
+    WCHAR szModule[MAX_SIZE];
+    WCHAR *pTemp = NULL;
 
     HMODULE hModule = GetModuleHandle(NULL);
-    DWORD dwResult  = ::GetModuleFileName(hModule, szModule,
-                                          sizeof(szModule)/sizeof(char));
+    DWORD dwResult  = ::GetModuleFileNameW(hModule, szModule,
+                                           sizeof(szModule)/sizeof(WCHAR));
     if (dwResult == 0)
         return;
 
-    pTemp = strrchr(szModule, '\\');
+    pTemp = wcsrchr(szModule, L'\\');
     if (pTemp == NULL)
         return;
 
     *pTemp = '\0';
-    nsAutoCString proxyPath(szModule);
+    nsAutoString proxyPath(szModule);
 
-    proxyPath += "\\";
+    proxyPath += u"\\";
     proxyPath += MAPI_PROXY_DLL_NAME;
 
-    h = LoadLibraryW(NS_ConvertASCIItoUTF16(proxyPath).get());
+    h = LoadLibraryW(proxyPath.get());
     if (h == NULL)
         return;
 
     UnRegisterFunc = (ProxyServer *) GetProcAddress(h, "DllUnregisterServer");
     if (UnRegisterFunc)
         UnRegisterFunc();
 
     FreeLibrary(h);