diff --git a/mozilla/xpcom/glue/standalone/nsXPCOMGlue.cpp b/mozilla/xpcom/glue/standalone/nsXPCOMGlue.cpp index 44a139ec3c0..7af2ed2f69c 100644 --- a/mozilla/xpcom/glue/standalone/nsXPCOMGlue.cpp +++ b/mozilla/xpcom/glue/standalone/nsXPCOMGlue.cpp @@ -49,6 +49,7 @@ #if XP_WIN32 #include +#include #endif void GRE_AddGREToEnvironment(); @@ -109,8 +110,28 @@ nsresult XPCOMGlueStartup(const char* xpcomFile) libSpec.type = PR_LibSpec_Pathname; if (!xpcomFile) libSpec.value.pathname = XPCOM_DLL; - else + else { libSpec.value.pathname = xpcomFile; +#ifdef XP_WIN32 + // Add directory containing xpcomFile to the DLL search path. This + // is done so that the OS knows where to find xpcom_core.dll and + // any other dependent libs. + const char *lastSlash = + (const char *) _mbsrchr((const unsigned char *) xpcomFile, '\\'); + if (lastSlash) { + char path[32767]; + DWORD pathLen = GetEnvironmentVariable("PATH", path, sizeof(path)); + if (pathLen != 0) + path[pathLen++] = ';'; + DWORD dirLen = lastSlash - xpcomFile; + if (sizeof(path) - pathLen > dirLen) { + memcpy(&path[pathLen], xpcomFile, dirLen); + path[pathLen + dirLen] = '\0'; + SetEnvironmentVariable("PATH", path); + } + } +#endif + } xpcomLib = PR_LoadLibraryWithFlags(libSpec, PR_LD_LAZY|PR_LD_GLOBAL); if (!xpcomLib)