blob: 309302e58186b0a705f57051b2cb6297893dd2d2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
#include <example.h>
#include <example_exe.h>
#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()
{
kwsys_stl::string libName = EXAMPLE_EXE_PLUGIN_DIR CONFIG_DIR "/";
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;
}
#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))
{
kwsys_ios::cerr << "Incorrect return value from plugin!"
<< kwsys_ios::endl;
return 1;
}
kwsys::DynamicLoader::CloseLibrary(handle);
return 0;
}
|