Хабр Курсы для всех
РЕКЛАМА
Практикум, Хекслет, SkyPro, авторские курсы — собрали всех и попросили скидки. Осталось выбрать!
DL_NS_BLOCK(( shapes )
(
DL_LIBRARY(lib)
(
( shapes::figure, create_rectangle, (double,left)(double,top)(double,width)(double,height) )
extern"C" DLX_DLL_EXPORT ::dlx::library<dl_library>::ftable const* DLX_CALL dynamic_library()
fn("_dynamic_library@0", lib_fn, std::nothrow);\
if (lib_fn == 0)\
fn("dynamic_library@0", lib_fn, std::nothrow);\
if (lib_fn == 0)\
::dlx::throw_ex< ::dlx::runtime_error >( std::string("library '") + dll_path + "' is not a DL-library");\
try
{
// прямой вызов функции объекта (библиотеки)
}
catch ( ... )
{
return create_error_info();
}
error_info* create_error_info()
{
try
{
throw;
}
catch (std::exception const& e)
{
return create_info( typeid(e).name(), e.what() );
}
catch (...)
{
return create_info( "unknown", "not available" );
}
}
исключениями в виду их некоторых проблем в винде не пользуетсяА какие в винде проблемы с исключениями?
typedef void (__stdcall *init_fn) ();
typedef void (__stdcall *decode_fn) ();
typedef void (__stdcall *free_fn) ();
int main()
{
HMODULE LibHandle = LoadLibraryA("decode.dll");
if ( LibHandle == NULL )
{
std::cout << "error: Can't load library!";
return -1;
}
init_fn init = reinterpret_cast<init_fn>(::GetProcAddress(lib, "init"));
decode_fn decode = reinterpret_cast<decode_fn>(::GetProcAddress(lib, "decode"));
free_fn free = reinterpret_cast<free_fn>(::GetProcAddress(lib, "free"));
//Или другим способом определяем какая функция не загрузилась
if (init == 0 || decode == 0 || free == 0)
{
FreeLibrary(LibHandle);
std::cout << "error: Can't load function!";
return -1;
}
init();
decode();
free();
FreeLibrary(LibHandle);
return 0;
}
#include <dl/include.hpp>
DL_BLOCK
(
DL_C_LIBRARY( lib )
(
( void, __stdcall, (init), () )
( void, __stdcall, (decode), () )
( void, __stdcall, (free), () )
)
)
int main()
{
try
{
lib some("decode.dll");
some.init();
some.decode();
some.free();
}
catch (std::exception const& e)
{
std::cout << "error: " << e.what();
}
}
static double epsilon()DL_LIBRARY( some_lib )
(
( double, sum, (double,x)(double,y,=0) )
)
struct some_lib_ftable
{
error_info const* (*sum_fn) ( double x, double y, double& result );
// служебные функции
};
DynLib: библиотека для создания и работы с DLL