1 // To use the export macros with a DLL, a file will need to be
2 // created (see ACE_wrapper/bin/generate_export_file.pl) and
3 // included. This file defines Test_Export (and the
4 // TEST_SINGLETON_* macros).
5 #include "test_export.h"
7 #include "ace/Singleton.h"
8 #include "ace/Null_Mutex.h"
12 // To expose a function outside of a DLL, use the *_Export
13 // at the beginning of the function declaration.
15 Test_Export
int test_function ();
17 // To expose data, put use the *Export at the beginning
18 // of the variable declaration. The extern is required when
19 // building static libraries.
21 extern Test_Export
int test_variable
;
23 // To expose a class, put the *_Export between "class"
24 // and the class name.
26 class Test_Export test_class
32 // ACE_Singleton and its relatives are special cases. The problem is
33 // that ACE_Singleton is a template. If the singleton is used in both
34 // the DLL and the executable linking the DLL, then two instances of
35 // the singleton will be used (which defeats the purpose of a Singleton).
37 // This occurs because the ACE_Singleton template is expanded in both
38 // places because Visual C++ and Borland C++ do this automatically by
39 // including the template source. This in turn creates two copies of
40 // the static member variable.
42 // So to get around this problem, the *_SINGLETON_DECLARE macro is
43 // used to instruct the compiler to not create the second copy in the
44 // program. This macro solution does not work for Borland C++, so for
45 // this compiler you must explicitly disable the template instantiation
46 // using a #pragma (or use the other workaround below).
48 // Another workaround for this is to not to expose the Singleton itself
49 // to the outside world, but to instead supply a function or static
50 // member function that returns the singleton to the executable
51 // (like get_dll_singleton () does below).
53 #if defined (__BORLANDC__)
54 # if !defined (TEST_BUILD_DLL)
55 # pragma option push -Jgx
58 TEST_SINGLETON_DECLARE (ACE_Singleton
, test_class
, ACE_Null_Mutex
)
59 #if defined (__BORLANDC__)
60 # if !defined (TEST_BUILD_DLL)
65 typedef ACE_Singleton
<test_class
, ACE_Null_Mutex
> TEST_SINGLETON
;
67 Test_Export test_class
*get_dll_singleton ();