1 | // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 | // for details. All rights reserved. Use of this source code is governed by a |
3 | // BSD-style license that can be found in the LICENSE file. |
4 | |
5 | #include "platform/globals.h" |
6 | #if defined(HOST_OS_WINDOWS) |
7 | |
8 | #include "bin/extensions.h" |
9 | #include "bin/utils.h" |
10 | #include "bin/utils_win.h" |
11 | #include "platform/assert.h" |
12 | |
13 | namespace dart { |
14 | namespace bin { |
15 | |
16 | void* Extensions::LoadExtensionLibrary(const char* library_file) { |
17 | SetLastError(0); |
18 | |
19 | // Convert to wchar_t string. |
20 | int name_len = MultiByteToWideChar(CP_UTF8, 0, library_file, -1, NULL, 0); |
21 | wchar_t* name; |
22 | name = new wchar_t[name_len]; |
23 | MultiByteToWideChar(CP_UTF8, 0, library_file, -1, name, name_len); |
24 | |
25 | void* ext = LoadLibraryW(name); |
26 | delete[] name; |
27 | return ext; |
28 | } |
29 | |
30 | void* Extensions::ResolveSymbol(void* lib_handle, const char* symbol) { |
31 | SetLastError(0); |
32 | return reinterpret_cast<void*>( |
33 | GetProcAddress(reinterpret_cast<HMODULE>(lib_handle), symbol)); |
34 | } |
35 | |
36 | void Extensions::UnloadLibrary(void* lib_handle) { |
37 | SetLastError(0); |
38 | BOOL result = FreeLibrary(reinterpret_cast<HMODULE>(lib_handle)); |
39 | ASSERT(result); |
40 | } |
41 | |
42 | Dart_Handle Extensions::GetError() { |
43 | int last_error = GetLastError(); |
44 | if (last_error != 0) { |
45 | OSError err; |
46 | return Dart_NewApiError(err.message()); |
47 | } |
48 | return Dart_Null(); |
49 | } |
50 | |
51 | } // namespace bin |
52 | } // namespace dart |
53 | |
54 | #endif // defined(HOST_OS_WINDOWS) |
55 | |