summaryrefslogtreecommitdiff
path: root/ACE/examples/DLL/test_dll.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'ACE/examples/DLL/test_dll.cpp')
-rw-r--r--ACE/examples/DLL/test_dll.cpp90
1 files changed, 90 insertions, 0 deletions
diff --git a/ACE/examples/DLL/test_dll.cpp b/ACE/examples/DLL/test_dll.cpp
new file mode 100644
index 00000000000..49f385aff98
--- /dev/null
+++ b/ACE/examples/DLL/test_dll.cpp
@@ -0,0 +1,90 @@
+// $Id$
+
+// This program tests out how the various objects can be loaded
+// dynamically and method calls made on them.
+
+#include "Magazine.h"
+#include "ace/DLL.h"
+#include "ace/Auto_Ptr.h"
+#include "ace/Log_Msg.h"
+
+ACE_RCSID(DLL, test_dll, "$Id$")
+
+typedef Magazine* (*Magazine_Creator) (void);
+
+int
+ACE_TMAIN (int argc, ACE_TCHAR *argv[])
+{
+ ACE_UNUSED_ARG (argc);
+ ACE_UNUSED_ARG (argv);
+
+ ACE_DLL dll;
+
+ int retval = dll.open (ACE_TEXT("./") ACE_DLL_PREFIX ACE_TEXT("DLL_Today"));
+
+ if (retval != 0)
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "%p",
+ "dll.open"),
+ -1);
+ Magazine_Creator mc;
+
+ // Cast the void* to non-pointer type first - it's not legal to
+ // cast a pointer-to-object directly to a pointer-to-function.
+ void *void_ptr = dll.symbol (ACE_TEXT ("create_magazine"));
+ ptrdiff_t tmp = reinterpret_cast<ptrdiff_t> (void_ptr);
+ mc = reinterpret_cast<Magazine_Creator> (tmp);
+
+ if (mc == 0)
+ {
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "%p",
+ "dll.symbol"),
+ -1);
+ }
+
+ {
+ auto_ptr <Magazine> magazine (mc ());
+
+ magazine->title ();
+ }
+
+ dll.close ();
+
+ // The other library is now loaded on demand.
+
+ retval = dll.open (ACE_DLL_PREFIX ACE_TEXT ("DLL_Newsweek"));
+
+ if (retval != 0)
+ {
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "%p",
+ "dll.open"),
+ -1);
+ }
+
+ // Cast the void* to non-pointer type first - it's not legal to
+ // cast a pointer-to-object directly to a pointer-to-function.
+ void_ptr = dll.symbol (ACE_TEXT ("create_magazine"));
+ tmp = reinterpret_cast<ptrdiff_t> (void_ptr);
+ mc = reinterpret_cast<Magazine_Creator> (tmp);
+
+ if (mc == 0)
+ {
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "%p",
+ "dll.symbol"),
+ -1);
+ }
+
+ {
+ auto_ptr <Magazine> magazine (mc ());
+
+ magazine->title ();
+ }
+
+ dll.close ();
+
+ return 0;
+}
+