blob: 9809c987c864f3a82dc96e881f18241000300694 [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]26fbf802011-03-25 18:48:0312#include "base/base_api.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
55// you're done.
[email protected]26fbf802011-03-25 18:48:0356BASE_API NativeLibrary LoadNativeLibrary(const FilePath& library_path);
[email protected]f38e25f2009-04-21 00:56:0757
[email protected]3e246222010-11-19 23:33:1358#if defined(OS_WIN)
59// Loads a native library from disk. Release it with UnloadNativeLibrary when
60// you're done.
61// This function retrieves the LoadLibrary function exported from kernel32.dll
62// and calls it instead of directly calling the LoadLibrary function via the
63// import table.
[email protected]26fbf802011-03-25 18:48:0364BASE_API NativeLibrary LoadNativeLibraryDynamically(
65 const FilePath& library_path);
[email protected]3e246222010-11-19 23:33:1366#endif // OS_WIN
67
[email protected]f38e25f2009-04-21 00:56:0768// Unloads a native library.
[email protected]26fbf802011-03-25 18:48:0369BASE_API void UnloadNativeLibrary(NativeLibrary library);
[email protected]f38e25f2009-04-21 00:56:0770
71// Gets a function pointer from a native library.
[email protected]26fbf802011-03-25 18:48:0372BASE_API void* GetFunctionPointerFromNativeLibrary(NativeLibrary library,
73 const char* name);
[email protected]108c2a12009-06-05 22:18:0974
75// Returns the full platform specific name for a native library.
76// For example:
77// "mylib" returns "mylib.dll" on Windows, "libmylib.so" on Linux,
78// "mylib.dylib" on Mac.
[email protected]26fbf802011-03-25 18:48:0379BASE_API string16 GetNativeLibraryName(const string16& name);
[email protected]f38e25f2009-04-21 00:56:0780
81} // namespace base
82
83#endif // BASE_NATIVE_LIBRARY_H_