2
CLAW - a C++ Library Absolutely Wonderful
4
CLAW is a free library without any particular aim but being useful to
7
Copyright (C) 2005-2008 Julien Jorge
9
This library is free software; you can redistribute it and/or
10
modify it under the terms of the GNU Lesser General Public
11
License as published by the Free Software Foundation; either
12
version 2.1 of the License, or (at your option) any later version.
14
This library is distributed in the hope that it will be useful,
15
but WITHOUT ANY WARRANTY; without even the implied warranty of
16
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17
Lesser General Public License for more details.
19
You should have received a copy of the GNU Lesser General Public
20
License along with this library; if not, write to the Free Software
21
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23
contact: julien_jorge@yahoo.fr
26
* \file dynamic_library_traits_win32.hpp
27
* \brief Microsoft Windows interface for using dynamic libraries.
28
* \author Julien Jorge
30
#ifndef __CLAW_DYNAMIC_LIBRARY_TRAITS_WIN32_HPP__
31
#define __CLAW_DYNAMIC_LIBRARY_TRAITS_WIN32_HPP__
36
//#include <winbase.h>
42
* \brief Microsoft Windows interface for using dynamic libraries.
43
* \author Julien Jorge
45
class dynamic_library_traits_win32
48
/** \brief Type of the system handle to the library. */
49
typedef HMODULE handle;
52
/*------------------------------------------------------------------------*/
54
* \brief Open a library.
55
* \param name The name of the library to open.
56
* \return The handle on the loaded library.
58
static handle open( const std::string& name )
60
return LoadLibrary( name.c_str() );
61
} // dynamic_library_traits_win32::open()
63
/*------------------------------------------------------------------------*/
65
* \brief Open the current program.
66
* \param name The name of the current program.
67
* \return The handle on the loaded library.
69
static handle auto_open( const std::string& name )
71
return LoadLibrary( name.c_str() );
72
} // dynamic_library_traits_win32::auto_open()
74
/*------------------------------------------------------------------------*/
76
* \brief Close a library.
77
* \param h The handle of the library to close.
79
static void close( handle h )
82
} // dynamic_library_traits_win32::close()
84
/*------------------------------------------------------------------------*/
86
* \brief Get a symbol from a library.
87
* \param h Handle of the library.
88
* \param name The name of the symbol to load.
91
static T get_symbol( handle h, const std::string& name )
93
/* HACK : ISO standard doesn't allow to cast from a pointer to an object
94
to a pointer to a function. */
96
*(FARPROC*)(&result) = GetProcAddress( h, name.c_str() );
99
} // dynamic_library_traits_win32::get_symbol()
101
/*------------------------------------------------------------------------*/
103
* \brief Tell if a symbol is in the library.
104
* \param h Handle of the library.
105
* \param name The name of the symbol to find.
107
static bool have_symbol( handle h, const std::string& name )
109
return GetProcAddress( h, name.c_str() ) != NULL;
110
} // dynamic_library_traits_win32::have_symbol()
112
/*------------------------------------------------------------------------*/
114
* \brief Tell if an handle is a valid library handle.
115
* \param h The handle to test.
117
static bool valid_handle( handle h )
120
} // dynamic_library_traits_win32::valid_handle()
122
}; // class dynamic_library_traits_win32
124
typedef dynamic_library_traits_win32 dynamic_library_traits;
127
#endif // __CLAW_DYNAMIC_LIBRARY_TRAITS_WIN32_HPP__