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
3 // found in the LICENSE file.
5 #ifndef BASE_NATIVE_LIBRARY_H_
6 #define BASE_NATIVE_LIBRARY_H_
8 // This file defines a cross-platform "NativeLibrary" type which represents
13 #include "base/base_export.h"
14 #include "base/compiler_specific.h"
15 #include "base/strings/string16.h"
16 #include "build/build_config.h"
20 #elif defined(OS_MACOSX)
21 #import <CoreFoundation/CoreFoundation.h>
29 typedef HMODULE NativeLibrary
;
30 #elif defined(OS_MACOSX)
31 enum NativeLibraryType
{
35 enum NativeLibraryObjCStatus
{
40 struct NativeLibraryStruct
{
41 NativeLibraryType type
;
42 CFBundleRefNum bundle_resource_ref
;
43 NativeLibraryObjCStatus objc_status
;
49 typedef NativeLibraryStruct
* NativeLibrary
;
50 #elif defined(OS_POSIX)
51 typedef void* NativeLibrary
;
54 struct BASE_EXPORT NativeLibraryLoadError
{
56 NativeLibraryLoadError() : code(0) {}
59 // Returns a string representation of the load error.
60 std::string
ToString() const;
69 // Loads a native library from disk. Release it with UnloadNativeLibrary when
70 // you're done. Returns NULL on failure.
71 // If |error| is not NULL, it may be filled in on load error.
72 BASE_EXPORT NativeLibrary
LoadNativeLibrary(const FilePath
& library_path
,
73 NativeLibraryLoadError
* error
);
76 // Loads a native library from disk. Release it with UnloadNativeLibrary when
78 // This function retrieves the LoadLibrary function exported from kernel32.dll
79 // and calls it instead of directly calling the LoadLibrary function via the
81 BASE_EXPORT NativeLibrary
LoadNativeLibraryDynamically(
82 const FilePath
& library_path
);
85 // Unloads a native library.
86 BASE_EXPORT
void UnloadNativeLibrary(NativeLibrary library
);
88 // Gets a function pointer from a native library.
89 BASE_EXPORT
void* GetFunctionPointerFromNativeLibrary(NativeLibrary library
,
92 // Returns the full platform specific name for a native library.
94 // "mylib" returns "mylib.dll" on Windows, "libmylib.so" on Linux,
95 // "mylib.dylib" on Mac.
96 BASE_EXPORT string16
GetNativeLibraryName(const string16
& name
);
100 #endif // BASE_NATIVE_LIBRARY_H_