summaryrefslogtreecommitdiffstats
path: root/base/native_library_win.cc
diff options
context:
space:
mode:
authorxhwang@chromium.org <xhwang@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-20 06:07:26 +0000
committerxhwang@chromium.org <xhwang@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-20 06:07:26 +0000
commitf4e911459762048780f642b80e46f04c43c573e1 (patch)
treef3523cd5e5d6be43a5957225c5afb730ac235d16 /base/native_library_win.cc
parent18053f969a4b7013de27db386ad8ea67bae4c470 (diff)
downloadchromium_src-f4e911459762048780f642b80e46f04c43c573e1.zip
chromium_src-f4e911459762048780f642b80e46f04c43c573e1.tar.gz
chromium_src-f4e911459762048780f642b80e46f04c43c573e1.tar.bz2
Set error in LoadNativeLibrary() on Windows.
If the native library fails to load, call GetLastError() immediately and set error with the last system error code. The list of Windows system error codes can be found at: http://msdn.microsoft.com/en-us/library/windows/desktop/ms681381.aspx BUG=353771 TBR=evan@chromium.org Review URL: https://codereview.chromium.org/199413026 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@258214 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/native_library_win.cc')
-rw-r--r--base/native_library_win.cc14
1 files changed, 11 insertions, 3 deletions
diff --git a/base/native_library_win.cc b/base/native_library_win.cc
index 3d2af62..bcea485 100644
--- a/base/native_library_win.cc
+++ b/base/native_library_win.cc
@@ -7,6 +7,7 @@
#include <windows.h>
#include "base/file_util.h"
+#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/threading/thread_restrictions.h"
@@ -15,7 +16,8 @@ namespace base {
typedef HMODULE (WINAPI* LoadLibraryFunction)(const wchar_t* file_name);
NativeLibrary LoadNativeLibraryHelper(const FilePath& library_path,
- LoadLibraryFunction load_library_api) {
+ LoadLibraryFunction load_library_api,
+ std::string* error) {
// LoadLibrary() opens the file off disk.
ThreadRestrictions::AssertIOAllowed();
@@ -32,6 +34,12 @@ NativeLibrary LoadNativeLibraryHelper(const FilePath& library_path,
}
HMODULE module = (*load_library_api)(library_path.value().c_str());
+ if (!module && error) {
+ // GetLastError() needs to be called immediately after |load_library_api|.
+ DWORD last_error = GetLastError();
+ *error = StringPrintf("%u", last_error);
+ }
+
if (restore_directory)
SetCurrentDirectory(current_directory);
@@ -41,7 +49,7 @@ NativeLibrary LoadNativeLibraryHelper(const FilePath& library_path,
// static
NativeLibrary LoadNativeLibrary(const FilePath& library_path,
std::string* error) {
- return LoadNativeLibraryHelper(library_path, LoadLibraryW);
+ return LoadNativeLibraryHelper(library_path, LoadLibraryW, error);
}
NativeLibrary LoadNativeLibraryDynamically(const FilePath& library_path) {
@@ -51,7 +59,7 @@ NativeLibrary LoadNativeLibraryDynamically(const FilePath& library_path) {
load_library = reinterpret_cast<LoadLibraryFunction>(
GetProcAddress(GetModuleHandle(L"kernel32.dll"), "LoadLibraryW"));
- return LoadNativeLibraryHelper(library_path, load_library);
+ return LoadNativeLibraryHelper(library_path, load_library, NULL);
}
// static