blob: 37d72295d678509274ca81a7b384b8b220c23689 [file] [log] [blame]
[email protected]26fbf802011-03-25 18:48:031// Copyright (c) 2011 The Chromium Authors. All rights reserved.
[email protected]f38e25f2009-04-21 00:56:072// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef BASE_NATIVE_LIBRARY_H_
6#define BASE_NATIVE_LIBRARY_H_
7
8// This file defines a cross-platform "NativeLibrary" type which represents
9// a loadable module.
10
[email protected]0bea7252011-08-05 15:34:0011#include "base/base_export.h"
[email protected]f38e25f2009-04-21 00:56:0712#include "build/build_config.h"
13
14#if defined(OS_WIN)
15#include <windows.h>
16#elif defined(OS_MACOSX)
[email protected]6770f2a2010-11-15 21:22:5517#import <CoreFoundation/CoreFoundation.h>
[email protected]f38e25f2009-04-21 00:56:0718#endif // OS_*
19
[email protected]108c2a12009-06-05 22:18:0920#include "base/string16.h"
21
[email protected]be130682010-11-12 21:53:1622// Macro useful for writing cross-platform function pointers.
[email protected]108c2a12009-06-05 22:18:0923#if defined(OS_WIN) && !defined(CDECL)
24#define CDECL __cdecl
25#else
26#define CDECL
27#endif
28
[email protected]f38e25f2009-04-21 00:56:0729namespace base {
30
[email protected]a3ef4832013-02-02 05:12:3331class FilePath;
32
[email protected]f38e25f2009-04-21 00:56:0733#if defined(OS_WIN)
34typedef HMODULE NativeLibrary;
[email protected]f38e25f2009-04-21 00:56:0735#elif defined(OS_MACOSX)
[email protected]108c2a12009-06-05 22:18:0936enum NativeLibraryType {
37 BUNDLE,
38 DYNAMIC_LIB
39};
40struct NativeLibraryStruct {
41 NativeLibraryType type;
[email protected]d8921c432010-01-28 16:08:0942 CFBundleRefNum bundle_resource_ref;
[email protected]108c2a12009-06-05 22:18:0943 union {
44 CFBundleRef bundle;
45 void* dylib;
46 };
47};
48typedef NativeLibraryStruct* NativeLibrary;
[email protected]e43eddf12009-12-29 00:32:5249#elif defined(OS_POSIX)
[email protected]f38e25f2009-04-21 00:56:0750typedef void* NativeLibrary;
[email protected]f38e25f2009-04-21 00:56:0751#endif // OS_*
52
53// Loads a native library from disk. Release it with UnloadNativeLibrary when
[email protected]84479322011-04-18 22:06:2254// you're done. Returns NULL on failure.
55// If |err| is not NULL, it may be filled in with an error message on
56// error.
[email protected]0bea7252011-08-05 15:34:0057BASE_EXPORT NativeLibrary LoadNativeLibrary(const FilePath& library_path,
58 std::string* error);
[email protected]f38e25f2009-04-21 00:56:0759
[email protected]3e246222010-11-19 23:33:1360#if defined(OS_WIN)
61// Loads a native library from disk. Release it with UnloadNativeLibrary when
62// you're done.
63// This function retrieves the LoadLibrary function exported from kernel32.dll
64// and calls it instead of directly calling the LoadLibrary function via the
65// import table.
[email protected]0bea7252011-08-05 15:34:0066BASE_EXPORT NativeLibrary LoadNativeLibraryDynamically(
[email protected]26fbf802011-03-25 18:48:0367 const FilePath& library_path);
[email protected]3e246222010-11-19 23:33:1368#endif // OS_WIN
69
[email protected]f38e25f2009-04-21 00:56:0770// Unloads a native library.
[email protected]0bea7252011-08-05 15:34:0071BASE_EXPORT void UnloadNativeLibrary(NativeLibrary library);
[email protected]f38e25f2009-04-21 00:56:0772
73// Gets a function pointer from a native library.
[email protected]0bea7252011-08-05 15:34:0074BASE_EXPORT void* GetFunctionPointerFromNativeLibrary(NativeLibrary library,
75 const char* name);
[email protected]108c2a12009-06-05 22:18:0976
77// Returns the full platform specific name for a native library.
78// For example:
79// "mylib" returns "mylib.dll" on Windows, "libmylib.so" on Linux,
80// "mylib.dylib" on Mac.
[email protected]0bea7252011-08-05 15:34:0081BASE_EXPORT string16 GetNativeLibraryName(const string16& name);
[email protected]f38e25f2009-04-21 00:56:0782
83} // namespace base
84
85#endif // BASE_NATIVE_LIBRARY_H_