Bug 1082576 - Fix the XPCOM library loading error reporting code; r=froydnj
We build without UNICODE, so we end up calling the ANSI version
of the function, and then we would attempt to interpret the
resulting narrow char buffer as a wide char buffer.
--- a/xpcom/glue/standalone/nsXPCOMGlue.cpp
+++ b/xpcom/glue/standalone/nsXPCOMGlue.cpp
@@ -45,35 +45,35 @@ static bool do_preload = false;
typedef HINSTANCE LibHandleType;
static LibHandleType
GetLibHandle(pathstr_t aDependentLib)
{
LibHandleType libHandle =
LoadLibraryExW(aDependentLib, nullptr, LOAD_WITH_ALTERED_SEARCH_PATH);
+#ifdef DEBUG
if (!libHandle) {
DWORD err = GetLastError();
-#ifdef DEBUG
LPVOID lpMsgBuf;
- FormatMessage(
+ FormatMessageW(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
nullptr,
err,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
- (LPTSTR)&lpMsgBuf,
+ (LPWSTR)&lpMsgBuf,
0,
nullptr
);
wprintf(L"Error loading %ls: %s\n", aDependentLib, lpMsgBuf);
LocalFree(lpMsgBuf);
+ }
#endif
- }
return libHandle;
}
static NSFuncPtr
GetSymbol(LibHandleType aLibHandle, const char* aSymbol)
{
return (NSFuncPtr)GetProcAddress(aLibHandle, aSymbol);