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