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_
9 // This file defines a cross-platform "NativeLibrary" type which represents
12 #include "base/base_export.h"
13 #include "build/build_config.h"
17 #elif defined(OS_MACOSX)
18 #import <CoreFoundation/CoreFoundation.h>
21 #include "base/string16.h"
23 // Macro useful for writing cross-platform function pointers.
24 #if defined(OS_WIN) && !defined(CDECL)
35 typedef HMODULE NativeLibrary
;
36 #elif defined(OS_MACOSX)
37 enum NativeLibraryType
{
41 struct NativeLibraryStruct
{
42 NativeLibraryType type
;
43 CFBundleRefNum bundle_resource_ref
;
49 typedef NativeLibraryStruct
* NativeLibrary
;
50 #elif defined(OS_POSIX)
51 typedef void* NativeLibrary
;
54 // Loads a native library from disk. Release it with UnloadNativeLibrary when
55 // you're done. Returns NULL on failure.
56 // If |err| is not NULL, it may be filled in with an error message on
58 BASE_EXPORT NativeLibrary
LoadNativeLibrary(const FilePath
& library_path
,
62 // Loads a native library from disk. Release it with UnloadNativeLibrary when
64 // This function retrieves the LoadLibrary function exported from kernel32.dll
65 // and calls it instead of directly calling the LoadLibrary function via the
67 BASE_EXPORT NativeLibrary
LoadNativeLibraryDynamically(
68 const FilePath
& library_path
);
71 // Unloads a native library.
72 BASE_EXPORT
void UnloadNativeLibrary(NativeLibrary library
);
74 // Gets a function pointer from a native library.
75 BASE_EXPORT
void* GetFunctionPointerFromNativeLibrary(NativeLibrary library
,
78 // Returns the full platform specific name for a native library.
80 // "mylib" returns "mylib.dll" on Windows, "libmylib.so" on Linux,
81 // "mylib.dylib" on Mac.
82 BASE_EXPORT string16
GetNativeLibraryName(const string16
& name
);
86 #endif // BASE_NATIVE_LIBRARY_H_