summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorbrunsch <brunsch@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>2000-05-09 16:17:44 +0000
committerbrunsch <brunsch@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>2000-05-09 16:17:44 +0000
commit9882e2ce66d45d273d7908af977e98244a96f605 (patch)
treec5870cf68452341307f8481c2c361f01e86a2eb3 /examples
parent469d758a0bcaf7a62d6aa78bd901d15a51673d42 (diff)
downloadATCD-9882e2ce66d45d273d7908af977e98244a96f605.tar.gz
ChangeLogTag:Tue May 9 09:01:24 2000 Darrell Brunsch <brunsch@uci.edu>
Diffstat (limited to 'examples')
-rw-r--r--examples/Export/README7
-rw-r--r--examples/Export/dll.cpp21
-rw-r--r--examples/Export/dll.h54
-rw-r--r--examples/Export/export_dll.dsp117
-rw-r--r--examples/Export/export_test.dsw44
-rwxr-xr-xexamples/Export/run_test.pl28
-rw-r--r--examples/Export/test.cpp64
-rw-r--r--examples/Export/test.dsp102
-rw-r--r--examples/Export/test_export.h40
9 files changed, 477 insertions, 0 deletions
diff --git a/examples/Export/README b/examples/Export/README
new file mode 100644
index 00000000000..83fc3108d50
--- /dev/null
+++ b/examples/Export/README
@@ -0,0 +1,7 @@
+$Id$
+
+The Export example is just an example that both shows off and tests
+the macros created by generate_export_file.pl (or the earlier
+GenExportH.bat). These macros are used to properly export functions
+and classes from a Win32 DLL. On other platforms these macros expand
+to nothing (since shared objects just export everything).
diff --git a/examples/Export/dll.cpp b/examples/Export/dll.cpp
new file mode 100644
index 00000000000..bef2877c058
--- /dev/null
+++ b/examples/Export/dll.cpp
@@ -0,0 +1,21 @@
+// $Id$
+#include "dll.h"
+
+int
+test_function ()
+{
+ test_variable = RETVAL;
+ return RETVAL;
+}
+
+int
+test_class::method ()
+{
+ return RETVAL;
+}
+
+test_class *
+get_dll_singleton ()
+{
+ return TEST_SINGLETON::instance ();
+}
diff --git a/examples/Export/dll.h b/examples/Export/dll.h
new file mode 100644
index 00000000000..cf22efe0eb9
--- /dev/null
+++ b/examples/Export/dll.h
@@ -0,0 +1,54 @@
+// $Id$
+
+// To use the export macros with a DLL, a file will need to be
+// created (see ACE_wrapper/bin/generate_export_file.pl) and
+// included. This file defines Test_Export (and the
+// TEST_SINGLETON_* macros).
+#include "test_export.h"
+
+#include "ace/Singleton.h"
+
+#define RETVAL 42
+
+// To expose a function outside of a DLL, use the *_Export
+// at the beginning of the function declaration.
+
+Test_Export int test_function ();
+
+// To expose data, put use the *Export at the beginning
+// of the variable declaration.
+
+Test_Export int test_variable;
+
+// To expose a class, put the *_Export between "class"
+// and the class name.
+
+class Test_Export test_class
+{
+public:
+ int method ();
+};
+
+// ACE_Singleton and its relatives are special cases. The problem is
+// that ACE_Singleton is a template. If the singleton is used in both
+// the DLL and the executable linking the DLL, then two instances of
+// the singleton will be used (which defeats the purpose of a Singleton).
+//
+// This occurs because the ACE_Singleton template is expanded in both
+// places because Visual C++ does this automatically by including
+// the template source. This in turn creates two copies of the static
+// member variable.
+//
+// So to get around this problem, the *_SINGLETON_DECLARE macro is
+// used to instruct the compiler to not create the second copy in the
+// program.
+//
+// Another workaround for this is to not to expose the Singleton itself
+// to the outside world, but to instead supply a function or static
+// member function that returns the singleton to the executable
+// (like get_dll_singleton () does below).
+
+typedef ACE_Singleton<test_class, ACE_Null_Mutex> TEST_SINGLETON;
+TEST_SINGLETON_DECLARE (ACE_Singleton, test_class, ACE_Null_Mutex);
+
+Test_Export test_class *get_dll_singleton ();
diff --git a/examples/Export/export_dll.dsp b/examples/Export/export_dll.dsp
new file mode 100644
index 00000000000..d735c659a5d
--- /dev/null
+++ b/examples/Export/export_dll.dsp
@@ -0,0 +1,117 @@
+# Microsoft Developer Studio Project File - Name="export_dll" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
+
+CFG=export_dll - Win32 Debug
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE
+!MESSAGE NMAKE /f "export_dll.mak".
+!MESSAGE
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "export_dll.mak" CFG="export_dll - Win32 Debug"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "export_dll - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
+!MESSAGE "export_dll - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+MTL=midl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "export_dll - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir ""
+# PROP Intermediate_Dir "Release"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "EXPORT_DLL_EXPORTS" /YX /FD /c
+# ADD CPP /nologo /MD /W3 /GX /O2 /I "../../../" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "TEST_BUILD_DLL" /FD /c
+# SUBTRACT CPP /YX
+# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC /l 0x409 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
+# ADD LINK32 ace.lib /nologo /dll /machine:I386 /libpath:"../../../ace/"
+
+!ELSEIF "$(CFG)" == "export_dll - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir ""
+# PROP Intermediate_Dir "Debug"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "EXPORT_DLL_EXPORTS" /YX /FD /c
+# ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /I "../../../" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "TEST_BUILD_DLL" /FD /c
+# SUBTRACT CPP /YX
+# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x409 /d "_DEBUG"
+# ADD RSC /l 0x409 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 aced.lib /nologo /dll /debug /machine:I386 /out:"export_dlld.dll" /pdbtype:sept /libpath:"../../../ace/"
+
+!ENDIF
+
+# Begin Target
+
+# Name "export_dll - Win32 Release"
+# Name "export_dll - Win32 Debug"
+# Begin Group "Source Files"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\dll.cpp
+# End Source File
+# End Group
+# Begin Group "Header Files"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# Begin Source File
+
+SOURCE=.\dll.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\test_export.h
+# End Source File
+# End Group
+# Begin Group "Resource Files"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# End Group
+# End Target
+# End Project
diff --git a/examples/Export/export_test.dsw b/examples/Export/export_test.dsw
new file mode 100644
index 00000000000..f46f6efeba6
--- /dev/null
+++ b/examples/Export/export_test.dsw
@@ -0,0 +1,44 @@
+Microsoft Developer Studio Workspace File, Format Version 6.00
+# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
+
+###############################################################################
+
+Project: "export_dll"=.\export_dll.dsp - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+}}}
+
+###############################################################################
+
+Project: "test"=.\test.dsp - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+ Begin Project Dependency
+ Project_Dep_Name export_dll
+ End Project Dependency
+}}}
+
+###############################################################################
+
+Global:
+
+Package=<5>
+{{{
+}}}
+
+Package=<3>
+{{{
+}}}
+
+###############################################################################
+
diff --git a/examples/Export/run_test.pl b/examples/Export/run_test.pl
new file mode 100755
index 00000000000..d88d4c72bea
--- /dev/null
+++ b/examples/Export/run_test.pl
@@ -0,0 +1,28 @@
+eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}'
+ & eval 'exec perl -S $0 $argv:q'
+ if 0;
+
+# $Id$
+# -*- perl -*-
+
+use lib "../../bin";
+
+require ACEutils;
+use Cwd;
+
+$cwd = getcwd();
+$test_exe = "$cwd$DIR_SEPARATOR"."test".$EXE_EXT;
+
+$TEST = Process::Create ($test_exe, "");
+
+$status = $TEST->TimedWait (20);
+if ($status == -1) {
+ print STDERR "ERROR: test timed out\n";
+ $status = 1;
+ $TEST->Kill (); $TEST->TimedWait (1);
+}
+elsif ($status > 0) {
+ print STDERR "ERROR: test failed\n";
+}
+
+exit $status;
diff --git a/examples/Export/test.cpp b/examples/Export/test.cpp
new file mode 100644
index 00000000000..69fe20158bf
--- /dev/null
+++ b/examples/Export/test.cpp
@@ -0,0 +1,64 @@
+// $Id$
+
+#include "dll.h"
+#include <iostream>
+
+int
+main (int, char *[])
+{
+ int failure_count = 0;
+ test_class my_test_class;
+
+ // Tet out the export of a class. I don't see
+ // How this can fail at runtime (rather it would
+ // probably give link errors), but just in case...
+
+ std::cout << "Method Test: ";
+ if (my_test_class.method () != RETVAL)
+ {
+ std::cout << "Failed" << std::endl;
+ ++failure_count;
+ }
+ else
+ std::cout << "Succeeded" << std::endl;
+
+ // Test out the export of a function. Like above,
+ // I don't know how this can fail at runtime.
+
+ std::cout << "Function Test: ";
+ if (test_function () != RETVAL)
+ {
+ std::cout << "Failed" << std::endl;
+ ++failure_count;
+ }
+ else
+ std::cout << "Succeeded" << std::endl;
+
+ // Also test out the export of data.
+
+ std::cout << "Variable Test: ";
+ if (test_variable != RETVAL)
+ {
+ std::cout << "Failed" << std::endl;
+ ++failure_count;
+ }
+ else
+ std::cout << "Succeeded" << std::endl;
+
+
+ // Test out the ACE_Singleton export by checking to see
+ // that we have the same instance pointer as the DLL does.
+ // This can fail at runtime.
+
+ std::cout << "Singleton Test: ";
+ if (TEST_SINGLETON::instance () != get_dll_singleton ())
+ {
+ std::cout << "Failed" << std::endl;
+ ++failure_count;
+ }
+ else
+ std::cout << "Succeeded" << std::endl;
+
+ // Return the number of failures
+ return failure_count;
+}
diff --git a/examples/Export/test.dsp b/examples/Export/test.dsp
new file mode 100644
index 00000000000..1e248decf25
--- /dev/null
+++ b/examples/Export/test.dsp
@@ -0,0 +1,102 @@
+# Microsoft Developer Studio Project File - Name="test" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Console Application" 0x0103
+
+CFG=test - Win32 Debug
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE
+!MESSAGE NMAKE /f "test.mak".
+!MESSAGE
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "test.mak" CFG="test - Win32 Debug"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "test - Win32 Release" (based on "Win32 (x86) Console Application")
+!MESSAGE "test - Win32 Debug" (based on "Win32 (x86) Console Application")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "test - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /MD /W3 /GX /O2 /I "../../../" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /YX /FD /c
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC /l 0x409 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+# ADD LINK32 export_dll.lib ace.lib /nologo /subsystem:console /machine:I386 /libpath:"../../../ace/"
+
+!ELSEIF "$(CFG)" == "test - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "test___Win32_Debug"
+# PROP BASE Intermediate_Dir "test___Win32_Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir ""
+# PROP Intermediate_Dir "Debug"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /I "../../../" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /YX /FD /c
+# ADD BASE RSC /l 0x409 /d "_DEBUG"
+# ADD RSC /l 0x409 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 export_dlld.lib aced.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept /libpath:"../../../ace/"
+
+!ENDIF
+
+# Begin Target
+
+# Name "test - Win32 Release"
+# Name "test - Win32 Debug"
+# Begin Group "Source Files"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\test.cpp
+# End Source File
+# End Group
+# Begin Group "Header Files"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# End Group
+# Begin Group "Resource Files"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# End Group
+# End Target
+# End Project
diff --git a/examples/Export/test_export.h b/examples/Export/test_export.h
new file mode 100644
index 00000000000..31a5150926e
--- /dev/null
+++ b/examples/Export/test_export.h
@@ -0,0 +1,40 @@
+// -*- C++ -*-
+// $Id$
+// Definition for Win32 Export directives.
+// This file is generated automatically by
+// generate_export_file.pl
+// ------------------------------
+#if !defined (TEST_EXPORT_H)
+#define TEST_EXPORT_H
+
+#include "ace/config-all.h"
+
+#if !defined (TEST_HAS_DLL)
+#define TEST_HAS_DLL 1
+#endif /* ! TEST_HAS_DLL */
+
+#if defined (TEST_HAS_DLL)
+# if (TEST_HAS_DLL == 1)
+# if defined (TEST_BUILD_DLL)
+# define Test_Export ACE_Proper_Export_Flag
+# define TEST_SINGLETON_DECLARATION(T) ACE_EXPORT_SINGLETON_DECLARATION (T)
+# define TEST_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_EXPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK)
+# else
+# define Test_Export ACE_Proper_Import_Flag
+# define TEST_SINGLETON_DECLARATION(T) ACE_IMPORT_SINGLETON_DECLARATION (T)
+# define TEST_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_IMPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK)
+# endif /* TEST_BUILD_DLL */
+# else
+# define Test_Export
+# define TEST_SINGLETON_DECLARATION(T)
+# define TEST_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK)
+# endif /* ! TEST_HAS_DLL == 1 */
+#else
+# define Test_Export
+# define TEST_SINGLETON_DECLARATION(T)
+# define TEST_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK)
+#endif /* TEST_HAS_DLL */
+
+#endif /* TEST_EXPORT_H */
+
+// End of auto generated file.