]> git.saurik.com Git - wxWidgets.git/blame - interface/wx/dynlib.h
Try native method first in LoadFile() and SaveFile()
[wxWidgets.git] / interface / wx / dynlib.h
CommitLineData
23324ae1
FM
1/////////////////////////////////////////////////////////////////////////////
2// Name: dynlib.h
0c1fe6e9 3// Purpose: interface of wxDynamicLibrary and wxDynamicLibraryDetails
23324ae1 4// Author: wxWidgets team
526954c5 5// Licence: wxWindows licence
23324ae1
FM
6/////////////////////////////////////////////////////////////////////////////
7
8/**
9 @class wxDynamicLibraryDetails
7c913512 10
0c1fe6e9
BP
11 This class is used for the objects returned by the
12 wxDynamicLibrary::ListLoaded() method and contains the information about a
13 single module loaded into the address space of the current process. A
14 module in this context may be either a dynamic library or the main program
15 itself.
7c913512 16
23324ae1 17 @library{wxbase}
0c1fe6e9 18 @category{appmanagement}
23324ae1 19*/
7c913512 20class wxDynamicLibraryDetails
23324ae1
FM
21{
22public:
23 /**
24 Retrieves the load address and the size of this module.
3c4f71cc 25
7c913512 26 @param addr
0c1fe6e9
BP
27 The pointer to the location to return load address in, may be
28 @NULL.
7c913512 29 @param len
0c1fe6e9
BP
30 Pointer to the location to return the size of this module in
31 memory in, may be @NULL.
3c4f71cc 32
d29a9a8a 33 @return @true if the load address and module size were retrieved,
0c1fe6e9 34 @false if this information is not available.
23324ae1 35 */
b91c4601 36 bool GetAddress(void* addr, size_t* len) const;
23324ae1
FM
37
38 /**
0824e369 39 Returns the base name of this module, e.g.\ @c "kernel32.dll" or
0c1fe6e9 40 @c "libc-2.3.2.so".
23324ae1 41 */
328f5751 42 wxString GetName() const;
23324ae1
FM
43
44 /**
0824e369
VZ
45 Returns the full path of this module if available, e.g.\ @c "c:\windows\system32\kernel32.dll"
46 or @c "/lib/libc-2.3.2.so".
23324ae1 47 */
328f5751 48 wxString GetPath() const;
23324ae1
FM
49
50 /**
0824e369 51 Returns the version of this module, e.g.\ @c "5.2.3790.0" or @c "2.3.2".
0c1fe6e9 52 The returned string is empty if the version information is not
23324ae1
FM
53 available.
54 */
328f5751 55 wxString GetVersion() const;
23324ae1
FM
56};
57
58
e54c96f1 59
23324ae1 60/**
0c1fe6e9 61 Dynamic library category used with wxDynamicLibrary::CanonicalizeName().
23324ae1 62*/
0c1fe6e9 63enum wxDynamicLibraryCategory
23324ae1 64{
0c1fe6e9
BP
65 wxDL_LIBRARY, ///< Standard library.
66 wxDL_MODULE ///< Loadable module/plugin.
23324ae1
FM
67};
68
0c1fe6e9
BP
69/**
70 Dynamic library plugin category used with
71 wxDynamicLibrary::CanonicalizePluginName().
72*/
73enum wxPluginCategory
74{
75 wxDL_PLUGIN_GUI, ///< Plugin that uses GUI classes.
76 wxDL_PLUGIN_BASE ///< wxBase-only plugin.
77};
e54c96f1 78
23324ae1
FM
79/**
80 @class wxDynamicLibrary
7c913512 81
23324ae1 82 wxDynamicLibrary is a class representing dynamically loadable library
6b6663be 83 (Windows DLL, shared library under Unix etc). Just create an object of
0c1fe6e9
BP
84 this class to load a library and don't worry about unloading it -- it will
85 be done in the objects destructor automatically.
86
87 The following flags can be used with wxDynamicLibrary() or Load():
88
89 @beginStyleTable
90 @style{wxDL_LAZY}
91 Equivalent of RTLD_LAZY under Unix, ignored elsewhere.
92 @style{wxDL_NOW}
93 Equivalent of RTLD_NOW under Unix, ignored elsewhere.
94 @style{wxDL_GLOBAL}
95 Equivalent of RTLD_GLOBAL under Unix, ignored elsewhere.
96 @style{wxDL_VERBATIM}
97 Don't try to append the appropriate extension to the library name
98 (this is done by default).
99 @style{wxDL_DEFAULT}
100 Default flags, same as wxDL_NOW currently.
101 @style{wxDL_QUIET}
102 Don't log an error message if the library couldn't be loaded.
103 @endStyleTable
7c913512 104
23324ae1 105 @library{wxbase}
0c1fe6e9 106 @category{appmanagement}
23324ae1 107*/
7c913512 108class wxDynamicLibrary
23324ae1
FM
109{
110public:
23324ae1 111 /**
0c1fe6e9 112 Default constructor.
23324ae1
FM
113 */
114 wxDynamicLibrary();
23324ae1 115 /**
0c1fe6e9
BP
116 Constructor. Calls Load() with the given @a name.
117 */
118 wxDynamicLibrary(const wxString& name, int flags = wxDL_DEFAULT);
3c4f71cc 119
0c1fe6e9
BP
120 /**
121 Returns the platform-specific full name for the library called @a name.
122 E.g. it adds a @c ".dll" extension under Windows and @c "lib" prefix
123 and @c ".so", @c ".sl" or @c ".dylib" extension under Unix.
3c4f71cc 124
4cc4bfaf 125 @see CanonicalizePluginName()
23324ae1
FM
126 */
127 static wxString CanonicalizeName(const wxString& name,
128 wxDynamicLibraryCategory cat = wxDL_LIBRARY);
129
130 /**
0c1fe6e9
BP
131 This function does the same thing as CanonicalizeName() but for
132 wxWidgets plugins. The only difference is that compiler and version
133 information are added to the name to ensure that the plugin which is
134 going to be loaded will be compatible with the main program.
23324ae1
FM
135 */
136 static wxString CanonicalizePluginName(const wxString& name,
137 wxPluginCategory cat = wxDL_PLUGIN_GUI);
138
139 /**
0824e369 140 Detaches this object from its library handle, i.e.\ the object will not
0c1fe6e9
BP
141 unload the library any longer in its destructor but it is now the
142 callers responsibility to do this using Unload().
23324ae1
FM
143 */
144 wxDllType Detach();
145
146 /**
147 Return a valid handle for the main program itself or @NULL if symbols
148 from the main program can't be loaded on this platform.
149 */
150 static wxDllType GetProgramHandle();
151
152 /**
0c1fe6e9
BP
153 Returns pointer to symbol @a name in the library or @NULL if the
154 library contains no such symbol.
3c4f71cc 155
e54c96f1 156 @see wxDYNLIB_FUNCTION()
23324ae1 157 */
b91c4601 158 void* GetSymbol(const wxString& name, bool* success = 0) const;
23324ae1
FM
159
160 /**
161 This function is available only under Windows as it is only useful when
0c1fe6e9
BP
162 dynamically loading symbols from standard Windows DLLs. Such functions
163 have either @c 'A' (in ANSI build) or @c 'W' (in Unicode, or wide
164 character build) suffix if they take string parameters. Using this
165 function, you can use just the base name of the function and the
166 correct suffix is appended automatically depending on the current
167 build. Otherwise, this method is identical to GetSymbol().
4ccf0566
FM
168
169 @onlyfor{wxmsw}
23324ae1 170 */
328f5751 171 void* GetSymbolAorW(const wxString& name) const;
23324ae1
FM
172
173 /**
0c1fe6e9
BP
174 Returns @true if the symbol with the given @a name is present in the
175 dynamic library, @false otherwise. Unlike GetSymbol(), this function
176 doesn't log an error message if the symbol is not found.
3c4f71cc 177
1e24c2af 178 @since 2.5.4
23324ae1 179 */
328f5751 180 bool HasSymbol(const wxString& name) const;
23324ae1
FM
181
182 /**
183 Returns @true if the library was successfully loaded, @false otherwise.
184 */
328f5751 185 bool IsLoaded() const;
23324ae1
FM
186
187 /**
0c1fe6e9
BP
188 This static method returns a wxArray containing the details of all
189 modules loaded into the address space of the current project. The array
190 elements are objects of the type: wxDynamicLibraryDetails. The array
191 will be empty if an error occurred.
192
193 This method is currently implemented only under Win32 and Linux and is
194 useful mostly for diagnostics purposes.
23324ae1
FM
195 */
196 static wxDynamicLibraryDetailsArray ListLoaded();
197
198 /**
4cc4bfaf 199 Loads DLL with the given @a name into memory. The @a flags argument can
0c1fe6e9 200 be a combination of the styles outlined in the class description.
3c4f71cc 201
23324ae1
FM
202 Returns @true if the library was successfully loaded, @false otherwise.
203 */
204 bool Load(const wxString& name, int flags = wxDL_DEFAULT);
205
23324ae1 206 /**
0c1fe6e9
BP
207 Unloads the library from memory. wxDynamicLibrary object automatically
208 calls this method from its destructor if it had been successfully
209 loaded.
23324ae1
FM
210 */
211 void Unload();
0c1fe6e9
BP
212 /**
213 Unloads the library from memory. wxDynamicLibrary object automatically
214 calls this method from its destructor if it had been successfully
215 loaded.
216
217 This version of Unload() is only used if you need to keep the library
218 in memory during a longer period of time than the scope of the
219 wxDynamicLibrary object. In this case you may call Detach() and store
220 the handle somewhere and call this static method later to unload it.
221 */
7c913512 222 static void Unload(wxDllType handle);
23324ae1
FM
223};
224
225
e54c96f1 226
23324ae1
FM
227// ============================================================================
228// Global functions/macros
229// ============================================================================
230
b21126db 231/** @addtogroup group_funcmacro_misc */
7fa7088e
BP
232//@{
233
23324ae1
FM
234/**
235 When loading a function from a DLL you always have to cast the returned
7fa7088e
BP
236 <tt>void *</tt> pointer to the correct type and, even more annoyingly, you
237 have to repeat this type twice if you want to declare and define a function
238 pointer all in one line.
239
23324ae1 240 This macro makes this slightly less painful by allowing you to specify the
7fa7088e
BP
241 type only once, as the first parameter, and creating a variable of this
242 type named after the function but with @c pfn prefix and initialized with
243 the function @a name from the wxDynamicLibrary @a dynlib.
7c913512
FM
244
245 @param type
7fa7088e 246 The type of the function.
7c913512 247 @param name
7fa7088e
BP
248 The name of the function to load, not a string (without quotes, it is
249 quoted automatically by the macro).
7c913512 250 @param dynlib
7fa7088e
BP
251 The library to load the function from.
252
253 @header{wx/dynlib.h}
23324ae1 254*/
7fa7088e
BP
255#define wxDYNLIB_FUNCTION(type, name, dynlib)
256
257//@}
23324ae1 258