📄 dl_call.hpp
字号:
/* /////////////////////////////////////////////////////////////////////////
* File: winstl/dl/dl_call.hpp
*
* Purpose: Invocation of functions in dynamic libraries.
*
* Created: sometime in 1998
* Updated: 4th August 2007
*
* Home: http://stlsoft.org/
*
* Copyright (c) 1998-2007, Matthew Wilson and Synesis Software
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* - Neither the name(s) of Matthew Wilson and Synesis Software nor the names of
* any contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* ////////////////////////////////////////////////////////////////////// */
/** \file winstl/dl/dl_call.hpp
*
* \brief [C++ only] Definition of the winstl::dl_call() function suite
* (\ref group__library__dl "DL" Library).
*/
#ifndef WINSTL_INCL_WINSTL_DL_HPP_DL_CALL
#define WINSTL_INCL_WINSTL_DL_HPP_DL_CALL
#ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
# define WINSTL_VER_WINSTL_DL_HPP_DL_CALL_MAJOR 2
# define WINSTL_VER_WINSTL_DL_HPP_DL_CALL_MINOR 6
# define WINSTL_VER_WINSTL_DL_HPP_DL_CALL_REVISION 1
# define WINSTL_VER_WINSTL_DL_HPP_DL_CALL_EDIT 40
#endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
/* /////////////////////////////////////////////////////////////////////////
* Compatibility
*/
/*
// Alas, Como experiences an ICE when compiling dl_call
[Incompatibilies-start]
STLSOFT_COMPILER_IS_COMO:
STLSOFT_COMPILER_IS_WATCOM:
[Incompatibilies-end]
*/
/* /////////////////////////////////////////////////////////////////////////
* Includes
*/
#ifndef WINSTL_INCL_WINSTL_H_WINSTL
# include <winstl/winstl.h>
#endif /* !WINSTL_INCL_WINSTL_H_WINSTL */
#if defined(STLSOFT_COMPILER_IS_COMO)
# error dl_call is not compatible with Como, which experienced an ICE
#endif /* compiler */
#if defined(STLSOFT_COMPILER_IS_WATCOM)
# error dl_call is not compatible with Watcom, which does not have sufficient template support
#endif /* compiler */
#ifndef WINSTL_INCL_WINSTL_ERROR_HPP_WINDOWS_EXCEPTIONS
# include <winstl/error/exceptions.hpp>
#endif /* !WINSTL_INCL_WINSTL_ERROR_HPP_WINDOWS_EXCEPTIONS */
#ifndef WINSTL_INCL_WINSTL_DL_HPP_MODULE
# include <winstl/dl/module.hpp>
#endif /* !WINSTL_INCL_WINSTL_DL_HPP_MODULE */
#ifndef STLSOFT_INCL_STLSOFT_META_HPP_IS_FUNCTION_POINTER_TYPE
# include <stlsoft/meta/is_function_pointer_type.hpp>
#endif /* !STLSOFT_INCL_STLSOFT_META_HPP_IS_FUNCTION_POINTER_TYPE */
#ifndef STLSOFT_INCL_STLSOFT_META_HPP_IS_FUNDAMENTAL_TYPE
# include <stlsoft/meta/is_fundamental_type.hpp>
#endif /* !STLSOFT_INCL_STLSOFT_META_HPP_IS_FUNDAMENTAL_TYPE */
#ifndef STLSOFT_INCL_STLSOFT_META_HPP_IS_POINTER_TYPE
# include <stlsoft/meta/is_pointer_type.hpp>
#endif /* !STLSOFT_INCL_STLSOFT_META_HPP_IS_POINTER_TYPE */
#ifndef STLSOFT_INCL_STLSOFT_STRING_HPP_SPLIT_FUNCTIONS
# include <stlsoft/string/split_functions.hpp>
#endif /* !STLSOFT_INCL_STLSOFT_STRING_HPP_SPLIT_FUNCTIONS */
#ifndef STLSOFT_INCL_STLSOFT_STRING_HPP_STRING_VIEW
# include <stlsoft/string/string_view.hpp>
#endif /* STLSOFT_INCL_STLSOFT_STRING_HPP_STRING_VIEW */
#ifndef STLSOFT_INCL_STLSOFT_SHIMS_ACCESS_HPP_STRING
# include <stlsoft/shims/access/string.hpp>
#endif /* !STLSOFT_INCL_STLSOFT_SHIMS_ACCESS_HPP_STRING */
/* /////////////////////////////////////////////////////////////////////////
* Namespace
*/
#ifndef _WINSTL_NO_NAMESPACE
# if defined(_STLSOFT_NO_NAMESPACE) || \
defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
/* There is no stlsoft namespace, so must define ::winstl */
namespace winstl
{
# else
/* Define stlsoft::winstl_project */
namespace stlsoft
{
namespace winstl_project
{
# endif /* _STLSOFT_NO_NAMESPACE */
#endif /* !_WINSTL_NO_NAMESPACE */
/* /////////////////////////////////////////////////////////////////////////
* Compiler compatibility
*/
#if defined(STLSOFT_COMPILER_IS_MSVC) && \
_MSC_VER < 1200
# define WINSTL_DL_CALL_NO_ARG_TYPE_CHECK
#endif /* compiler */
/* /////////////////////////////////////////////////////////////////////////
* Classes
*/
/** \brief Indicates an entry point cannot be located in a dynamic library.
*
* \ingroup group__library__dl__error
*/
class missing_entry_point_exception
: public windows_exception
{
/// \name Types
/// @{
public:
typedef windows_exception parent_class_type;
typedef missing_entry_point_exception class_type;
private:
typedef parent_class_type::string_type string_type;
public:
typedef parent_class_type::error_code_type error_code_type;
/// @}
/// \name Construction
/// @{
public:
/// \brief Constructs an instance of the exception based on the given missing
/// function name, and Windows error code.
missing_entry_point_exception(char const* functionName, error_code_type err)
: parent_class_type(class_type::create_reason_(functionName), err)
{}
#ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
virtual ~missing_entry_point_exception() stlsoft_throw_0()
{}
#endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
/// @}
/// \name Implementation
/// @{
private:
static string_type create_reason_(char const* functionName)
{
return "Failed to find procedure \"" + string_type(functionName) + '"';
}
/// @}
/// \name Not to be implemented
/// @{
private:
class_type& operator =(class_type const&);
/// @}
};
/** \brief Indicates an invalid calling convention specifier.
*
* \ingroup group__library__dl__error
*/
class invalid_calling_convention_exception
: public windows_exception
{
/// \name Types
/// @{
public:
typedef windows_exception parent_class_type;
typedef invalid_calling_convention_exception class_type;
private:
typedef parent_class_type::string_type string_type;
public:
typedef parent_class_type::error_code_type error_code_type;
/// @}
/// \name Construction
/// @{
public:
/// \brief Constructs an instance of the exception based on the given
/// function name, and Windows error code.
invalid_calling_convention_exception(char const* callingConventionSpecifier)
: parent_class_type(class_type::create_reason_(callingConventionSpecifier), ERROR_INVALID_FUNCTION)
, m_ccs(callingConventionSpecifier)
{}
#ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
virtual ~invalid_calling_convention_exception() stlsoft_throw_0()
{}
#endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
/// @}
/// \name Accessors
/// @{
public:
string_type const &get_specifier() const
{
return m_ccs;
}
/// @}
/// \name Implementation
/// @{
private:
static string_type create_reason_(char const* callingConventionSpecifier)
{
return "Unrecognised or unsupported calling convention \"" + string_type(callingConventionSpecifier) + '"';
}
/// @}
/// \name Members
/// @{
private:
const string_type m_ccs;
/// @}
// Not to be implemented
/// @}
private:
class_type& operator =(class_type const&);
/// @}
};
/* /////////////////////////////////////////////////////////////////////////
* Enumerations
*/
namespace calling_convention
{
enum calling_convention
{
unknownCallConv = -1
#ifdef STLSOFT_CF_CDECL_SUPPORTED
, cdeclCallConv = STLSOFT_CDECL_VALUE
#endif /* STLSOFT_CF_CDECL_SUPPORTED */
#ifdef STLSOFT_CF_FASTCALL_SUPPORTED
, fastcallCallConv = STLSOFT_FASTCALL_VALUE
#endif // STLSOFT_CF_FASTCALL_SUPPORTED
#ifdef STLSOFT_CF_STDCALL_SUPPORTED
, stdcallCallConv = STLSOFT_STDCALL_VALUE
#endif // STLSOFT_CF_STDCALL_SUPPORTED
};
inline calling_convention from_int(int i)
{
switch(i)
{
default:
STLSOFT_MESSAGE_ASSERT("Invalid/unrecognised calling convention specifier. cdecl will be assumed", 0);
#ifdef STLSOFT_CF_CDECL_SUPPORTED
case cdeclCallConv:
return cdeclCallConv;
#endif /* STLSOFT_CF_CDECL_SUPPORTED */
#ifdef STLSOFT_CF_FASTCALL_SUPPORTED
case fastcallCallConv:
return fastcallCallConv;
#endif // STLSOFT_CF_FASTCALL_SUPPORTED
#ifdef STLSOFT_CF_STDCALL_SUPPORTED
case stdcallCallConv:
return stdcallCallConv;
#endif // STLSOFT_CF_STDCALL_SUPPORTED
}
}
} // namespace calling_convention
/* ////////////////////////////////////////////////////////////////////// */
struct function_descriptor_base
{
operator function_descriptor_base const* () const
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -