/* =============================================================================
 *  scpp_dl.hpp
 *  Copyright (c)  2003 - 2011  Nomura Kei
 *  LICENSE :
 *  LGPL (GNU Lesser General General Public License - Version 3,29 June 2007)
 *  http://www.gnu.org/copyleft/lesser.html
 * =============================================================================
 *
 *  ライブラリの動的ロードを行うモジュール
 *
 */
#ifndef SCPP_DL_HPP
#define SCPP_DL_HPP

#include <string>
#include <scpp_os.hpp>


namespace scpp
{

#if (SCPP_IS_WINDOWS)
typedef HINSTANCE      dl_handle_t;
typedef FARPROC WINAPI dl_func_t;
#else
typedef void*          dl_handle_t;
typedef void*          dl_func_t;
#endif


/**
 * 動的ライブラリのローダ.
 * 動的にライブラリをロードするクラスです.
 *
 * 使用例)
 * @code
 * typedef USHORT (WINAPI *RtlCaptureStackBackTraceDef) (ULONG FramesToSkip, ULONG FramesToCapture, PVOID *BackTrace, PULONG BackTraceHash);
 * RtlCaptureStackBackTraceDef RtlCaptureStackBackTraceProc; * DynamicLinkingLoader loader;
 * bool ret = loader.open("kernel32.dll");
 * if (ret)
 * {
 *     RtlCaptureStackBackTraceProc = reinterpret_cast<RtlCaptureStackBackTraceDef>(loader.sym("RtlCaptureStackBackTrace"));
 *     void* buffer[62];
 *     int   cnt = RtlCaptureStackBackTraceProc(0, 62, buffer, 0);
 *     for (int i = 0; i < cnt; i++)
 *     {
 *         std::cout << buffer[i] << std::endl;
 *     }
 * }
 * @endcode
 */
class DynamicLinkingLoader
{

	public:
		DynamicLinkingLoader();
		virtual ~DynamicLinkingLoader();
		bool      open(const std::string& fileName);
		dl_func_t sym(const std::string& symbol);

	private:
		DynamicLinkingLoader(const DynamicLinkingLoader&);
		DynamicLinkingLoader operator=(const DynamicLinkingLoader&);
		dl_handle_t handle;

};



}	// namespace scpp

#endif	// SCPP_DL_HPP

