Add partial pre-read functionality to browser startup (Windows).
[chromium-blink-merge.git] / base / native_library.h
blob1e0dfcd357915c888434e59fd9ffda9f824c3cc9
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_
7 #pragma once
9 // This file defines a cross-platform "NativeLibrary" type which represents
10 // a loadable module.
12 #include "base/base_export.h"
13 #include "build/build_config.h"
15 #if defined(OS_WIN)
16 #include <windows.h>
17 #elif defined(OS_MACOSX)
18 #import <CoreFoundation/CoreFoundation.h>
19 #endif // OS_*
21 #include "base/string16.h"
23 // Macro useful for writing cross-platform function pointers.
24 #if defined(OS_WIN) && !defined(CDECL)
25 #define CDECL __cdecl
26 #else
27 #define CDECL
28 #endif
30 class FilePath;
32 namespace base {
34 #if defined(OS_WIN)
35 typedef HMODULE NativeLibrary;
36 #elif defined(OS_MACOSX)
37 enum NativeLibraryType {
38 BUNDLE,
39 DYNAMIC_LIB
41 struct NativeLibraryStruct {
42 NativeLibraryType type;
43 CFBundleRefNum bundle_resource_ref;
44 union {
45 CFBundleRef bundle;
46 void* dylib;
49 typedef NativeLibraryStruct* NativeLibrary;
50 #elif defined(OS_POSIX)
51 typedef void* NativeLibrary;
52 #endif // OS_*
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
57 // error.
58 BASE_EXPORT NativeLibrary LoadNativeLibrary(const FilePath& library_path,
59 std::string* error);
61 #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.
67 BASE_EXPORT NativeLibrary LoadNativeLibraryDynamically(
68 const FilePath& library_path);
69 #endif // OS_WIN
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,
76 const char* name);
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.
82 BASE_EXPORT string16 GetNativeLibraryName(const string16& name);
84 } // namespace base
86 #endif // BASE_NATIVE_LIBRARY_H_