native_library.h revision 3345a6884c488ff3a535c2c9acdd33d74b37e311
1// Copyright (c) 2009 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. 4 5#ifndef BASE_NATIVE_LIBRARY_H_ 6#define BASE_NATIVE_LIBRARY_H_ 7#pragma once 8 9// This file defines a cross-platform "NativeLibrary" type which represents 10// a loadable module. 11 12#include "build/build_config.h" 13 14#if defined(OS_WIN) 15#include <windows.h> 16#elif defined(OS_MACOSX) 17#import <Carbon/Carbon.h> 18#endif // OS_* 19 20#include "base/string16.h" 21 22// Macro usefull for writing cross-platform function pointers. 23#if defined(OS_WIN) && !defined(CDECL) 24#define CDECL __cdecl 25#else 26#define CDECL 27#endif 28 29class FilePath; 30 31namespace base { 32 33#if defined(OS_WIN) 34typedef HMODULE NativeLibrary; 35#elif defined(OS_MACOSX) 36enum NativeLibraryType { 37 BUNDLE, 38 DYNAMIC_LIB 39}; 40struct NativeLibraryStruct { 41 NativeLibraryType type; 42 CFBundleRefNum bundle_resource_ref; 43 union { 44 CFBundleRef bundle; 45 void* dylib; 46 }; 47}; 48typedef NativeLibraryStruct* NativeLibrary; 49#elif defined(OS_POSIX) 50typedef void* NativeLibrary; 51#endif // OS_* 52 53// Loads a native library from disk. Release it with UnloadNativeLibrary when 54// you're done. 55NativeLibrary LoadNativeLibrary(const FilePath& library_path); 56 57// Unloads a native library. 58void UnloadNativeLibrary(NativeLibrary library); 59 60// Gets a function pointer from a native library. 61void* GetFunctionPointerFromNativeLibrary(NativeLibrary library, 62 const char* name); 63 64// Returns the full platform specific name for a native library. 65// For example: 66// "mylib" returns "mylib.dll" on Windows, "libmylib.so" on Linux, 67// "mylib.dylib" on Mac. 68string16 GetNativeLibraryName(const string16& name); 69 70} // namespace base 71 72#endif // BASE_NATIVE_LIBRARY_H_ 73