blob: 1e0dfcd357915c888434e59fd9ffda9f824c3cc9 [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_
[email protected]32b76ef2010-07-26 23:08:247#pragma once
[email protected]f38e25f2009-04-21 00:56:078
9// This file defines a cross-platform "NativeLibrary" type which represents
10// a loadable module.
11
[email protected]0bea7252011-08-05 15:34:0012#include "base/base_export.h"
[email protected]f38e25f2009-04-21 00:56:0713#include "build/build_config.h"
14
15#if defined(OS_WIN)
16#include <windows.h>
17#elif defined(OS_MACOSX)
[email protected]6770f2a2010-11-15 21:22:5518#import <CoreFoundation/CoreFoundation.h>
[email protected]f38e25f2009-04-21 00:56:0719#endif // OS_*
20
[email protected]108c2a12009-06-05 22:18:0921#include "base/string16.h"
22
[email protected]be130682010-11-12 21:53:1623// Macro useful for writing cross-platform function pointers.
[email protected]108c2a12009-06-05 22:18:0924#if defined(OS_WIN) && !defined(CDECL)
25#define CDECL __cdecl
26#else
27#define CDECL
28#endif
29
[email protected]f38e25f2009-04-21 00:56:0730class FilePath;
31
32namespace base {
33
34#if defined(OS_WIN)
35typedef HMODULE NativeLibrary;
[email protected]f38e25f2009-04-21 00:56:0736#elif defined(OS_MACOSX)
[email protected]108c2a12009-06-05 22:18:0937enum NativeLibraryType {
38 BUNDLE,
39 DYNAMIC_LIB
40};
41struct NativeLibraryStruct {
42 NativeLibraryType type;
[email protected]d8921c432010-01-28 16:08:0943 CFBundleRefNum bundle_resource_ref;
[email protected]108c2a12009-06-05 22:18:0944 union {
45 CFBundleRef bundle;
46 void* dylib;
47 };
48};
49typedef NativeLibraryStruct* NativeLibrary;
[email protected]e43eddf12009-12-29 00:32:5250#elif defined(OS_POSIX)
[email protected]f38e25f2009-04-21 00:56:0751typedef void* NativeLibrary;
[email protected]f38e25f2009-04-21 00:56:0752#endif // OS_*
53
54// Loads a native library from disk. Release it with UnloadNativeLibrary when
[email protected]84479322011-04-18 22:06:2255// you're done. Returns NULL on failure.
56// If |err| is not NULL, it may be filled in with an error message on
57// error.
[email protected]0bea7252011-08-05 15:34:0058BASE_EXPORT NativeLibrary LoadNativeLibrary(const FilePath& library_path,
59 std::string* error);
[email protected]f38e25f2009-04-21 00:56:0760
[email protected]3e246222010-11-19 23:33:1361#if defined(OS_WIN)
62// Loads a native library from disk. Release it with UnloadNativeLibrary when
63// you're done.
64// This function retrieves the LoadLibrary function exported from kernel32.dll
65// and calls it instead of directly calling the LoadLibrary function via the
66// import table.
[email protected]0bea7252011-08-05 15:34:0067BASE_EXPORT NativeLibrary LoadNativeLibraryDynamically(
[email protected]26fbf802011-03-25 18:48:0368 const FilePath& library_path);
[email protected]3e246222010-11-19 23:33:1369#endif // OS_WIN
70
[email protected]f38e25f2009-04-21 00:56:0771// Unloads a native library.
[email protected]0bea7252011-08-05 15:34:0072BASE_EXPORT void UnloadNativeLibrary(NativeLibrary library);
[email protected]f38e25f2009-04-21 00:56:0773
74// Gets a function pointer from a native library.
[email protected]0bea7252011-08-05 15:34:0075BASE_EXPORT void* GetFunctionPointerFromNativeLibrary(NativeLibrary library,
76 const char* name);
[email protected]108c2a12009-06-05 22:18:0977
78// Returns the full platform specific name for a native library.
79// For example:
80// "mylib" returns "mylib.dll" on Windows, "libmylib.so" on Linux,
81// "mylib.dylib" on Mac.
[email protected]0bea7252011-08-05 15:34:0082BASE_EXPORT string16 GetNativeLibraryName(const string16& name);
[email protected]f38e25f2009-04-21 00:56:0783
84} // namespace base
85
86#endif // BASE_NATIVE_LIBRARY_H_