| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef BASE_NATIVE_LIBRARY_H_ | 5 #ifndef BASE_NATIVE_LIBRARY_H_ |
| 6 #define BASE_NATIVE_LIBRARY_H_ | 6 #define BASE_NATIVE_LIBRARY_H_ |
| 7 | 7 |
| 8 // This file defines a cross-platform "NativeLibrary" type which represents | 8 // This file defines a cross-platform "NativeLibrary" type which represents |
| 9 // a loadable module. | 9 // a loadable module. |
| 10 | 10 |
| 11 #include <string> |
| 12 |
| 11 #include "base/base_export.h" | 13 #include "base/base_export.h" |
| 12 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
| 15 #include "base/strings/string16.h" |
| 13 #include "build/build_config.h" | 16 #include "build/build_config.h" |
| 14 | 17 |
| 15 #if defined(OS_WIN) | 18 #if defined(OS_WIN) |
| 16 #include <windows.h> | 19 #include <windows.h> |
| 17 #elif defined(OS_MACOSX) | 20 #elif defined(OS_MACOSX) |
| 18 #import <CoreFoundation/CoreFoundation.h> | 21 #import <CoreFoundation/CoreFoundation.h> |
| 19 #endif // OS_* | 22 #endif // OS_* |
| 20 | 23 |
| 21 #include "base/strings/string16.h" | |
| 22 | |
| 23 namespace base { | 24 namespace base { |
| 24 | 25 |
| 25 class FilePath; | 26 class FilePath; |
| 26 | 27 |
| 27 #if defined(OS_WIN) | 28 #if defined(OS_WIN) |
| 28 typedef HMODULE NativeLibrary; | 29 typedef HMODULE NativeLibrary; |
| 29 #elif defined(OS_MACOSX) | 30 #elif defined(OS_MACOSX) |
| 30 enum NativeLibraryType { | 31 enum NativeLibraryType { |
| 31 BUNDLE, | 32 BUNDLE, |
| 32 DYNAMIC_LIB | 33 DYNAMIC_LIB |
| (...skipping 10 matching lines...) Expand all Loading... |
| 43 union { | 44 union { |
| 44 CFBundleRef bundle; | 45 CFBundleRef bundle; |
| 45 void* dylib; | 46 void* dylib; |
| 46 }; | 47 }; |
| 47 }; | 48 }; |
| 48 typedef NativeLibraryStruct* NativeLibrary; | 49 typedef NativeLibraryStruct* NativeLibrary; |
| 49 #elif defined(OS_POSIX) | 50 #elif defined(OS_POSIX) |
| 50 typedef void* NativeLibrary; | 51 typedef void* NativeLibrary; |
| 51 #endif // OS_* | 52 #endif // OS_* |
| 52 | 53 |
| 54 struct BASE_EXPORT NativeLibraryLoadError { |
| 55 #if defined(OS_WIN) |
| 56 NativeLibraryLoadError() : code(0) {} |
| 57 #endif // OS_WIN |
| 58 |
| 59 // Returns a string representation of the load error. |
| 60 std::string ToString() const; |
| 61 |
| 62 #if defined(OS_WIN) |
| 63 DWORD code; |
| 64 #else |
| 65 std::string message; |
| 66 #endif // OS_WIN |
| 67 }; |
| 68 |
| 53 // Loads a native library from disk. Release it with UnloadNativeLibrary when | 69 // Loads a native library from disk. Release it with UnloadNativeLibrary when |
| 54 // you're done. Returns NULL on failure. | 70 // you're done. Returns NULL on failure. |
| 55 // If |error| is not NULL, it may be filled in with an error message on error. | 71 // If |error| is not NULL, it may be filled in on load error. |
| 56 BASE_EXPORT NativeLibrary LoadNativeLibrary(const FilePath& library_path, | 72 BASE_EXPORT NativeLibrary LoadNativeLibrary(const FilePath& library_path, |
| 57 std::string* error); | 73 NativeLibraryLoadError* error); |
| 58 | 74 |
| 59 #if defined(OS_WIN) | 75 #if defined(OS_WIN) |
| 60 // Loads a native library from disk. Release it with UnloadNativeLibrary when | 76 // Loads a native library from disk. Release it with UnloadNativeLibrary when |
| 61 // you're done. | 77 // you're done. |
| 62 // This function retrieves the LoadLibrary function exported from kernel32.dll | 78 // This function retrieves the LoadLibrary function exported from kernel32.dll |
| 63 // and calls it instead of directly calling the LoadLibrary function via the | 79 // and calls it instead of directly calling the LoadLibrary function via the |
| 64 // import table. | 80 // import table. |
| 65 BASE_EXPORT NativeLibrary LoadNativeLibraryDynamically( | 81 BASE_EXPORT NativeLibrary LoadNativeLibraryDynamically( |
| 66 const FilePath& library_path); | 82 const FilePath& library_path); |
| 67 #endif // OS_WIN | 83 #endif // OS_WIN |
| 68 | 84 |
| 69 // Unloads a native library. | 85 // Unloads a native library. |
| 70 BASE_EXPORT void UnloadNativeLibrary(NativeLibrary library); | 86 BASE_EXPORT void UnloadNativeLibrary(NativeLibrary library); |
| 71 | 87 |
| 72 // Gets a function pointer from a native library. | 88 // Gets a function pointer from a native library. |
| 73 BASE_EXPORT void* GetFunctionPointerFromNativeLibrary(NativeLibrary library, | 89 BASE_EXPORT void* GetFunctionPointerFromNativeLibrary(NativeLibrary library, |
| 74 const char* name); | 90 const char* name); |
| 75 | 91 |
| 76 // Returns the full platform specific name for a native library. | 92 // Returns the full platform specific name for a native library. |
| 77 // For example: | 93 // For example: |
| 78 // "mylib" returns "mylib.dll" on Windows, "libmylib.so" on Linux, | 94 // "mylib" returns "mylib.dll" on Windows, "libmylib.so" on Linux, |
| 79 // "mylib.dylib" on Mac. | 95 // "mylib.dylib" on Mac. |
| 80 BASE_EXPORT string16 GetNativeLibraryName(const string16& name); | 96 BASE_EXPORT string16 GetNativeLibraryName(const string16& name); |
| 81 | 97 |
| 82 } // namespace base | 98 } // namespace base |
| 83 | 99 |
| 84 #endif // BASE_NATIVE_LIBRARY_H_ | 100 #endif // BASE_NATIVE_LIBRARY_H_ |
| OLD | NEW |