bug 487174 - Modify nsXULStub to launch from GRE folder on WinCE r=bsmedberg
authorHiroyuki Ikezoe <ikezoe@clear-code.com>
Mon, 13 Apr 2009 22:49:06 -0400
changeset 27286 6032ec47e686beb66d4f1edfb273e39d903135e7
parent 27285 6a945f2fd6f024870f59c985e99552408f25346c
child 27287 6ffb78941637af2eb2ef82b4a8dcdfa1224d0b43
push idunknown
push userunknown
push dateunknown
reviewersbsmedberg
bugs487174
milestone1.9.2a1pre
bug 487174 - Modify nsXULStub to launch from GRE folder on WinCE r=bsmedberg
xpcom/glue/standalone/nsGlueLinkingWin.cpp
xulrunner/stub/nsXULStub.cpp
--- a/xpcom/glue/standalone/nsGlueLinkingWin.cpp
+++ b/xpcom/glue/standalone/nsGlueLinkingWin.cpp
@@ -40,16 +40,22 @@
 #include "nsXPCOMGlue.h"
 
 #include "nsStringAPI.h"
 #include <windows.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <tchar.h>
 
+#ifdef WINCE
+#define MOZ_LOADLIBRARY_FLAGS 0
+#else
+#define MOZ_LOADLIBRARY_FLAGS LOAD_WITH_ALTERED_SEARCH_PATH
+#endif
+
 struct DependentLib
 {
     HINSTANCE     libHandle;
     DependentLib *next;
 };
 
 static DependentLib *sTop;
 HINSTANCE sXULLibrary;
@@ -65,22 +71,26 @@ AppendDependentLib(HINSTANCE libHandle)
     d->libHandle = libHandle;
 
     sTop = d;
 }
 
 static void
 ReadDependentCB(const char *aDependentLib)
 {
-    
+    wchar_t wideDependentLib[MAX_PATH];
+    MultiByteToWideChar(CP_ACP, 0, aDependentLib, -1, wideDependentLib, MAX_PATH);
+
     HINSTANCE h =
-        LoadLibraryExW(NS_ConvertUTF8toUTF16(aDependentLib).get(), NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
-    if (!h)
+        LoadLibraryExW(wideDependentLib, NULL, MOZ_LOADLIBRARY_FLAGS);
+
+    if (!h) {
+        wprintf(L"Error loading %s\n", wideDependentLib);
         return;
-
+    }
     AppendDependentLib(h);
 }
 
 // like strpbrk but finds the *last* char, not the first
 static char*
 ns_strrpbrk(char *string, const char *strCharSet)
 {
     char *found = NULL;
@@ -155,58 +165,57 @@ XPCOMGlueLoad(const char *aXpcomFile)
             char xpcomDir_narrow[MAXPATHLEN];
             WideCharToMultiByte(CP_ACP, 0, xpcomDir,-1,
                                 xpcomDir_narrow, MAX_PATH, NULL, NULL);
 
             XPCOMGlueLoadDependentLibs(xpcomDir_narrow, ReadDependentCB);
             
             _snwprintf(lastSlash, MAXPATHLEN - wcslen(xpcomDir), L"\\" LXUL_DLL);
             sXULLibrary =
-                LoadLibraryExW(xpcomDir, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
+                LoadLibraryExW(xpcomDir, NULL, MOZ_LOADLIBRARY_FLAGS);
 
 #ifdef DEBUG
             if (!sXULLibrary) 
             {
                 LPVOID lpMsgBuf;
                 FormatMessage(
                               FORMAT_MESSAGE_ALLOCATE_BUFFER |
                               FORMAT_MESSAGE_FROM_SYSTEM |
                               FORMAT_MESSAGE_IGNORE_INSERTS,
                               NULL,
                               GetLastError(),
                               MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
                               (LPTSTR) &lpMsgBuf,
                               0,
                               NULL
                               );
-                wprintf(L"Error loading xul.dll: %s\n", lpMsgBuf);
+                wprintf(L"Error loading %s: %s\n", xpcomDir, lpMsgBuf);
             }
 #endif //DEBUG                
         }
     }
     HINSTANCE h =
-        LoadLibraryExW(xpcomFile, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
-
+        LoadLibraryExW(xpcomFile, NULL, MOZ_LOADLIBRARY_FLAGS);
 
     if (!h) 
     {
 #ifdef DEBUG
         LPVOID lpMsgBuf;
         FormatMessage(
                       FORMAT_MESSAGE_ALLOCATE_BUFFER |
                       FORMAT_MESSAGE_FROM_SYSTEM |
                       FORMAT_MESSAGE_IGNORE_INSERTS,
                       NULL,
                       GetLastError(),
                       MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
                       (LPTSTR) &lpMsgBuf,
                       0,
                       NULL
                       );
-        wprintf(L"Error loading xpcom.dll: %s\n", lpMsgBuf);
+        wprintf(L"Error loading %s: %s\n", xpcomFile, lpMsgBuf);
 #endif        
         return nsnull;
     }
 
     AppendDependentLib(h);
 
     GetFrozenFunctionsFunc sym =
         (GetFrozenFunctionsFunc) GetProcAddress(h, "NS_GetFrozenFunctions");
--- a/xulrunner/stub/nsXULStub.cpp
+++ b/xulrunner/stub/nsXULStub.cpp
@@ -326,17 +326,16 @@ main(int argc, char **argv)
   strcpy(tmpPath, greDir);
   lastSlash = strrchr(tmpPath, PATH_SEPARATOR_CHAR);
   if (lastSlash) {
     *lastSlash = '\0';
   }
   DosSetExtLIBPATH(tmpPath, BEGIN_LIBPATH);
 #endif
 
-#ifndef WINCE
   rv = XPCOMGlueStartup(greDir);
   if (NS_FAILED(rv)) {
     Output(PR_TRUE, "Couldn't load XPCOM.\n");
     return 1;
   }
 
   static const nsDynamicFunctionLoad kXULFuncs[] = {
     { "XRE_CreateAppData", (NSFuncPtr*) &XRE_CreateAppData },
@@ -383,40 +382,11 @@ main(int argc, char **argv)
     }
 
     retval = XRE_main(argc, argv, appData);
   }
 
   NS_LogTerm();
 
   XPCOMGlueShutdown();
-#else
-  // LoadLibraryExW doesn't take the LOAD_WITH_ALTERED_SEARCH_PATH flag, caling
-  // xulrunner.exe from the gre dir sets the library search path correctly.
-  STARTUPINFO si;
-  PROCESS_INFORMATION pi;
-  ZeroMemory(&si, sizeof(si));
-  ZeroMemory(&pi, sizeof(si));
-  si.cb = sizeof(si);
-  wchar_t xrPath[MAX_PATH];
-  MultiByteToWideChar(CP_ACP, 0, greDir, -1, xrPath, MAX_PATH);
-  wchar_t* wLastSlash = wcsrchr(xrPath, PATH_SEPARATOR_CHAR);
-  if (wLastSlash) {
-    *wLastSlash = L'\0';
-  }
-  wcscat(xrPath, L"\\xulrunner.exe");
-  
-  wchar_t wideIniPath[MAX_PATH+2];
-  swprintf(wideIniPath, L"\"%S\"", iniPath);
-  
-  CreateProcessW(xrPath, wideIniPath, NULL, NULL, FALSE, 0, NULL, NULL, 
-                 &si, &pi); 
-  WaitForSingleObject(pi.hProcess, INFINITE);
-  DWORD retval = 0;
-  if (!GetExitCodeProcess(pi.hProcess, &retval))
-    printf("failed to get exit code, error = %d\n", retval = GetLastError());
-  
-  // Close process and thread handles.
-  CloseHandle(pi.hProcess);
-  CloseHandle(pi.hThread);
-#endif
+
   return retval;
 }