summaryrefslogtreecommitdiff
path: root/cpp/include/Ice/DynamicLibrary.h
blob: 1f870b2b4fc4d5a27f7664713809190cfd603706 (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
87
88
89
90
91
92
93
// **********************************************************************
//
// Copyright (c) 2002
// Mutable Realms, Inc.
// Huntsville, AL, USA
//
// All Rights Reserved
//
// **********************************************************************

#ifndef ICE_DYNAMIC_LIBRARY_H
#define ICE_DYNAMIC_LIBRARY_H

#include <Ice/DynamicLibraryF.h>
#include <IceUtil/Shared.h>

namespace IceInternal
{

class ICE_API DynamicLibrary : public ::IceUtil::Shared
{
public:

    DynamicLibrary();
    ~DynamicLibrary();

#ifdef _WIN32
    typedef FARPROC symbol_type;
#else
    typedef void* symbol_type;
#endif

    //
    // Load an entry point. This is really a convenience function
    // which combines calls to load() and getSymbol(). However,
    // it does add some value.
    //
    // An entry point has the following format:
    //
    // name[,version]:function
    //
    // The name of the library is constructed from the given
    // information. If no version is supplied, the Ice version
    // is used. For example, consider the following entry point:
    //  
    // foo:create 
    //
    // This would result in libfoo.so.0.0.1 (Unix) and foo001.dll (Windows),
    // where the Ice version is 0.0.1.
    //
    // Now consider this entry point:
    //
    // foo,1.1:create
    //
    // The library names in this case are libfoo.so.1.1 (Unix) and
    // foo11.dll (Windows).
    //
    // On Windows platforms, a 'd' is appended to the version for debug
    // builds.
    //
    // Returns 0 if a failure occurred.
    //
    symbol_type loadEntryPoint(const std::string&);

    //
    // Open a library with the given path.
    //
    bool load(const std::string&);

    //
    // Retrieve a symbol from the library. Returns 0 if no match is found.
    //
    symbol_type getSymbol(const std::string&);

    //
    // Get the error message for the last failure.
    //
    const std::string& getErrorMessage() const;

private:

#ifdef _WIN32
    HINSTANCE _hnd;
#else
    void* _hnd;
#endif

    std::string _err;
};

}

#endif