| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "platform/globals.h" | 5 #include "platform/globals.h" |
| 6 #if defined(TARGET_OS_WINDOWS) | 6 #if defined(TARGET_OS_WINDOWS) |
| 7 | 7 |
| 8 #include "bin/extensions.h" | 8 #include "bin/extensions.h" |
| 9 #include "bin/utils.h" | 9 #include "bin/utils.h" |
| 10 #include "bin/utils_win.h" | 10 #include "bin/utils_win.h" |
| 11 #include "platform/assert.h" |
| 11 | 12 |
| 12 namespace dart { | 13 namespace dart { |
| 13 namespace bin { | 14 namespace bin { |
| 14 | 15 |
| 15 const char* kVmSnapshotDataSymbolName = "_kDartVmSnapshotData"; | 16 const char* kVmSnapshotDataSymbolName = "_kDartVmSnapshotData"; |
| 16 const char* kVmSnapshotInstructionsSymbolName = "_kDartVmSnapshotInstructions"; | 17 const char* kVmSnapshotInstructionsSymbolName = "_kDartVmSnapshotInstructions"; |
| 17 const char* kIsolateSnapshotDataSymbolName = "_kDartIsolateSnapshotData"; | 18 const char* kIsolateSnapshotDataSymbolName = "_kDartIsolateSnapshotData"; |
| 18 const char* kIsolateSnapshotInstructionsSymbolName = | 19 const char* kIsolateSnapshotInstructionsSymbolName = |
| 19 "_kDartIsolateSnapshotInstructions"; | 20 "_kDartIsolateSnapshotInstructions"; |
| 20 | 21 |
| 21 void* Extensions::LoadExtensionLibrary(const char* library_file) { | 22 void* Extensions::LoadLibrary(const char* library_file) { |
| 22 SetLastError(0); | 23 SetLastError(0); |
| 23 | 24 |
| 24 // Convert to wchar_t string. | 25 // Convert to wchar_t string. |
| 25 int name_len = MultiByteToWideChar(CP_UTF8, 0, library_file, -1, NULL, 0); | 26 int name_len = MultiByteToWideChar(CP_UTF8, 0, library_file, -1, NULL, 0); |
| 26 wchar_t* name; | 27 wchar_t* name; |
| 27 name = new wchar_t[name_len]; | 28 name = new wchar_t[name_len]; |
| 28 MultiByteToWideChar(CP_UTF8, 0, library_file, -1, name, name_len); | 29 MultiByteToWideChar(CP_UTF8, 0, library_file, -1, name, name_len); |
| 29 | 30 |
| 30 void* ext = LoadLibraryW(name); | 31 void* ext = LoadLibraryW(name); |
| 31 delete[] name; | 32 delete[] name; |
| 32 return ext; | 33 return ext; |
| 33 } | 34 } |
| 34 | 35 |
| 36 |
| 35 void* Extensions::ResolveSymbol(void* lib_handle, const char* symbol) { | 37 void* Extensions::ResolveSymbol(void* lib_handle, const char* symbol) { |
| 36 SetLastError(0); | 38 SetLastError(0); |
| 37 return GetProcAddress(reinterpret_cast<HMODULE>(lib_handle), symbol); | 39 return GetProcAddress(reinterpret_cast<HMODULE>(lib_handle), symbol); |
| 38 } | 40 } |
| 39 | 41 |
| 42 |
| 43 void Extensions::UnloadLibrary(void* lib_handle) { |
| 44 SetLastError(0); |
| 45 BOOL result = FreeLibrary(reinterpret_cast<HMODULE>(lib_handle)); |
| 46 ASSERT(result); |
| 47 } |
| 48 |
| 49 |
| 40 Dart_Handle Extensions::GetError() { | 50 Dart_Handle Extensions::GetError() { |
| 41 int last_error = GetLastError(); | 51 int last_error = GetLastError(); |
| 42 if (last_error != 0) { | 52 if (last_error != 0) { |
| 43 OSError err; | 53 OSError err; |
| 44 return Dart_NewApiError(err.message()); | 54 return Dart_NewApiError(err.message()); |
| 45 } | 55 } |
| 46 return Dart_Null(); | 56 return Dart_Null(); |
| 47 } | 57 } |
| 48 | 58 |
| 49 } // namespace bin | 59 } // namespace bin |
| 50 } // namespace dart | 60 } // namespace dart |
| 51 | 61 |
| 52 #endif // defined(TARGET_OS_WINDOWS) | 62 #endif // defined(TARGET_OS_WINDOWS) |
| OLD | NEW |