gecko/toolkit/mozapps/update/updater/loaddlls.cpp
2012-05-05 09:21:53 -04:00

44 lines
1.7 KiB
C++

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#include <windows.h>
// Delayed load libraries are loaded when the first symbol is used.
// The following ensures that we load the delayed loaded libraries from the
// system directory.
struct AutoLoadSystemDependencies
{
AutoLoadSystemDependencies()
{
static LPCWSTR delayDLLs[] = { L"wsock32.dll", L"crypt32.dll" };
WCHAR systemDirectory[MAX_PATH + 1] = { L'\0' };
// If GetSystemDirectory fails we accept that we'll load the DLLs from the
// normal search path.
GetSystemDirectory(systemDirectory, MAX_PATH + 1);
size_t systemDirLen = wcslen(systemDirectory);
// Make the system directory path terminate with a slash
if (systemDirectory[systemDirLen - 1] != L'\\' && systemDirLen) {
systemDirectory[systemDirLen] = L'\\';
++systemDirLen;
// No need to re-NULL terminate
}
// For each known DLL ensure it is loaded from the system32 directory
for (size_t i = 0; i < sizeof(delayDLLs) / sizeof(delayDLLs[0]); ++i) {
size_t fileLen = wcslen(delayDLLs[i]);
wcsncpy(systemDirectory + systemDirLen, delayDLLs[i],
MAX_PATH - systemDirLen);
if (systemDirLen + fileLen <= MAX_PATH) {
systemDirectory[systemDirLen + fileLen] = L'\0';
} else {
systemDirectory[MAX_PATH] = L'\0';
}
LPCWSTR fullModulePath = systemDirectory; // just for code readability
LoadLibraryW(fullModulePath);
}
}
} loadDLLs;