2007-04-17 21:43:03 +04:00
|
|
|
#include <example.h>
|
|
|
|
|
2007-04-17 21:52:50 +04:00
|
|
|
#include <example_exe.h>
|
|
|
|
|
2007-04-17 21:43:03 +04:00
|
|
|
#include <kwsys/DynamicLoader.hxx>
|
|
|
|
#include <kwsys/ios/iostream>
|
|
|
|
#include <kwsys/stl/string>
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
// Implement the ABI used by plugins.
|
|
|
|
extern "C" int example_exe_function()
|
|
|
|
{
|
|
|
|
kwsys_ios::cout << "hello" << kwsys_ios::endl;
|
|
|
|
return 123;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CMAKE_INTDIR
|
|
|
|
# define CONFIG_DIR "/" CMAKE_INTDIR
|
|
|
|
#else
|
|
|
|
# define CONFIG_DIR ""
|
|
|
|
#endif
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
2007-04-17 21:52:50 +04:00
|
|
|
kwsys_stl::string libName = EXAMPLE_EXE_PLUGIN_DIR CONFIG_DIR "/";
|
2007-04-17 21:43:03 +04:00
|
|
|
libName += kwsys::DynamicLoader::LibPrefix();
|
|
|
|
libName += "example_mod_1";
|
|
|
|
libName += kwsys::DynamicLoader::LibExtension();
|
|
|
|
kwsys::DynamicLoader::LibraryHandle handle =
|
|
|
|
kwsys::DynamicLoader::OpenLibrary(libName.c_str());
|
|
|
|
if(!handle)
|
|
|
|
{
|
|
|
|
kwsys_ios::cerr << "Could not open plugin \""
|
|
|
|
<< libName << "\"!" << kwsys_ios::endl;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
kwsys::DynamicLoader::SymbolPointer sym =
|
|
|
|
kwsys::DynamicLoader::GetSymbolAddress(handle, "example_mod_1_function");
|
|
|
|
if(!sym)
|
|
|
|
{
|
|
|
|
kwsys_ios::cerr
|
|
|
|
<< "Could not get plugin symbol \"example_mod_1_function\"!"
|
|
|
|
<< kwsys_ios::endl;
|
|
|
|
return 1;
|
|
|
|
}
|
2007-04-19 19:32:43 +04:00
|
|
|
#ifdef __WATCOMC__
|
|
|
|
int(__cdecl *f)(int) = (int(__cdecl *)(int))(sym);
|
|
|
|
#else
|
|
|
|
int(*f)(int) = reinterpret_cast<int(*)(int)>(sym);
|
|
|
|
#endif
|
|
|
|
if(f(456) != (123+456))
|
2007-04-17 21:43:03 +04:00
|
|
|
{
|
|
|
|
kwsys_ios::cerr << "Incorrect return value from plugin!"
|
|
|
|
<< kwsys_ios::endl;
|
|
|
|
return 1;
|
2007-09-11 01:10:40 +04:00
|
|
|
}
|
|
|
|
kwsys::DynamicLoader::CloseLibrary(handle);
|
2007-04-17 21:43:03 +04:00
|
|
|
return 0;
|
|
|
|
}
|