File: FXDLL.h

package info (click to toggle)
gogglesmm 1.2.5-6
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 16,812 kB
  • sloc: cpp: 231,960; ansic: 893; xml: 222; makefile: 33
file content (100 lines) | stat: -rw-r--r-- 3,389 bytes parent folder | download | duplicates (2)
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
94
95
96
97
98
99
100
/********************************************************************************
*                                                                               *
*             D y n a m i c   L i n k   L i b r a r y   S u p p o r t           *
*                                                                               *
*********************************************************************************
* Copyright (C) 2002,2022 by Jeroen van der Zijp.   All Rights Reserved.        *
*********************************************************************************
* This library is free software; you can redistribute it and/or modify          *
* it under the terms of the GNU Lesser General Public License as published by   *
* the Free Software Foundation; either version 3 of the License, or             *
* (at your option) any later version.                                           *
*                                                                               *
* This library is distributed in the hope that it will be useful,               *
* but WITHOUT ANY WARRANTY; without even the implied warranty of                *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                 *
* GNU Lesser General Public License for more details.                           *
*                                                                               *
* You should have received a copy of the GNU Lesser General Public License      *
* along with this program.  If not, see <http://www.gnu.org/licenses/>          *
********************************************************************************/
#ifndef FXDLL_H
#define FXDLL_H

namespace FX {


/**
* Wrap library module handle to allow various operations
* on libraries to be performed.
*/
class FXAPI FXDLL {
private:
  void *hnd;
public:

  /// Construct with no handle
  FXDLL():hnd(nullptr){}

  /// Construct with existing handle
  FXDLL(void *h):hnd(h){}

  /// Construct copy from original
  FXDLL(const FXDLL& org):hnd(org.hnd){}

  /// Return the name of the library module
  FXString name() const;

  /// Return library module handle
  void* handle() const { return hnd; }

  /// True if library was loaded
  FXbool loaded() const { return hnd!=nullptr; }

  /// Load the library module from the name
  FXbool load(const FXString& nm);

  /// Unload the library module
  void unload();

  /// Return the address of the symbol in this library module
  void* address(const FXchar* sym) const;
  void* address(const FXString& sym) const;

  /// Return the symbol name of the given address
  static FXString symbol(void *addr);

  /// Return the name of the library module containing the address
  static FXString name(void *addr);

  /// Find DLL containing symbol
  static FXDLL dll(void* addr);

  /// Find DLL of ourselves
  static FXDLL dll();

  /// Return error message if error occurred loading the library module
  static FXString error();
  };


/**
* Auto DLL wraps a library module handle but also owns it; thus, the library
* module will automatically be unloaded when auto-dll is destroyed.
*/
class FXAPI FXAUTODLL : public FXDLL {
private:
  FXAUTODLL(const FXAUTODLL&);
  FXAUTODLL &operator=(const FXAUTODLL&);
public:

  /// Initialize by loading given library name
  FXAUTODLL(const FXString& nm);

  /// Unload library if we have one
  ~FXAUTODLL();
  };

}

#endif