blob: 289616344b41527f606cfefbbfa1716d73938ec6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef BASE_NATIVE_LIBRARY_H_
#define BASE_NATIVE_LIBRARY_H_
#pragma once
// This file defines a cross-platform "NativeLibrary" type which represents
// a loadable module.
#include "base/base_api.h"
#include "build/build_config.h"
#if defined(OS_WIN)
#include <windows.h>
#elif defined(OS_MACOSX)
#import <CoreFoundation/CoreFoundation.h>
#endif // OS_*
#include "base/string16.h"
// Macro useful for writing cross-platform function pointers.
#if defined(OS_WIN) && !defined(CDECL)
#define CDECL __cdecl
#else
#define CDECL
#endif
class FilePath;
namespace base {
#if defined(OS_WIN)
typedef HMODULE NativeLibrary;
#elif defined(OS_MACOSX)
enum NativeLibraryType {
BUNDLE,
DYNAMIC_LIB
};
struct NativeLibraryStruct {
NativeLibraryType type;
CFBundleRefNum bundle_resource_ref;
union {
CFBundleRef bundle;
void* dylib;
};
};
typedef NativeLibraryStruct* NativeLibrary;
#elif defined(OS_POSIX)
typedef void* NativeLibrary;
#endif // OS_*
// Loads a native library from disk. Release it with UnloadNativeLibrary when
// you're done. Returns NULL on failure.
// If |err| is not NULL, it may be filled in with an error message on
// error.
BASE_API NativeLibrary LoadNativeLibrary(const FilePath& library_path,
std::string* error);
#if defined(OS_WIN)
// Loads a native library from disk. Release it with UnloadNativeLibrary when
// you're done.
// This function retrieves the LoadLibrary function exported from kernel32.dll
// and calls it instead of directly calling the LoadLibrary function via the
// import table.
BASE_API NativeLibrary LoadNativeLibraryDynamically(
const FilePath& library_path);
#endif // OS_WIN
// Unloads a native library.
BASE_API void UnloadNativeLibrary(NativeLibrary library);
// Gets a function pointer from a native library.
BASE_API void* GetFunctionPointerFromNativeLibrary(NativeLibrary library,
const char* name);
// Returns the full platform specific name for a native library.
// For example:
// "mylib" returns "mylib.dll" on Windows, "libmylib.so" on Linux,
// "mylib.dylib" on Mac.
BASE_API string16 GetNativeLibraryName(const string16& name);
} // namespace base
#endif // BASE_NATIVE_LIBRARY_H_
|