Merge pull request #2216 from jwillemsen/jwi-cxxversionchecks
[ACE_TAO.git] / ACE / examples / DLL / test_dll.cpp
blob4f27a2e02616298456a1bdcbca1fb4ed07117cbf
1 // This program tests out how the various objects can be loaded
2 // dynamically and method calls made on them.
4 #include "Magazine.h"
5 #include "ace/DLL.h"
6 #include "ace/Log_Msg.h"
7 #include <memory>
9 typedef Magazine* (*Magazine_Creator) ();
11 int
12 ACE_TMAIN (int argc, ACE_TCHAR *argv[])
14 ACE_UNUSED_ARG (argc);
15 ACE_UNUSED_ARG (argv);
17 ACE_DLL dll;
19 int retval = dll.open (ACE_DLL_PREFIX ACE_TEXT("DLL_Today"));
21 if (retval != 0)
22 ACE_ERROR_RETURN ((LM_ERROR,
23 "%p",
24 "dll.open"),
25 -1);
26 Magazine_Creator mc;
28 // Cast the void* to non-pointer type first - it's not legal to
29 // cast a pointer-to-object directly to a pointer-to-function.
30 void *void_ptr = dll.symbol (ACE_TEXT ("create_magazine"));
31 ptrdiff_t tmp = reinterpret_cast<ptrdiff_t> (void_ptr);
32 mc = reinterpret_cast<Magazine_Creator> (tmp);
34 if (mc == 0)
36 ACE_ERROR_RETURN ((LM_ERROR,
37 "%p",
38 "dll.symbol"),
39 -1);
43 std::unique_ptr<Magazine> magazine (mc ());
45 magazine->title ();
48 dll.close ();
50 // The other library is now loaded on demand.
52 retval = dll.open (ACE_DLL_PREFIX ACE_TEXT ("DLL_Newsweek"));
54 if (retval != 0)
56 ACE_ERROR_RETURN ((LM_ERROR,
57 "%p",
58 "dll.open"),
59 -1);
62 // Cast the void* to non-pointer type first - it's not legal to
63 // cast a pointer-to-object directly to a pointer-to-function.
64 void_ptr = dll.symbol (ACE_TEXT ("create_magazine"));
65 tmp = reinterpret_cast<ptrdiff_t> (void_ptr);
66 mc = reinterpret_cast<Magazine_Creator> (tmp);
68 if (mc == 0)
70 ACE_ERROR_RETURN ((LM_ERROR,
71 "%p",
72 "dll.symbol"),
73 -1);
77 std::unique_ptr<Magazine> magazine (mc ());
79 magazine->title ();
82 dll.close ();
84 return 0;