On 1 Nov 2005 05:01:59 -0800, "Roi" <ro*******@yahoo.com> wrote:
Hello,
I'm trying to implements Factory Patern using 2 DLL's.
On the first DLL i implemented the Factory,
and on the other I defines global variables which activating the
Factory.
the problem is:
The DLL's aren't loaded until I call a function from them,
therefore the global variables aren't initialized and the Factory
doesn't work
Can anyone help me?
Regards in your advice,
Roi
You might be able to initialize your factory like this: first, put
these in some header file:
extern void FunctionInDll();
struct FactoryInit {
FactoryInit() { FunctionInDll(); }
};
FunctionInDll() can be just a dummy function, or it can do real work
initializing your globals. Often it will increment a counter or set a
flag in order to tell whether the function had been previously called
and/or how many times.
In one of your .cpp files which implement the non-DLL part of your
application, define a static global variable of type FactoryInit:
static FactoryInit fi;
It will be initialized before main() or whatever the entry point is.
The constructor will call the DLL function, thus your globals should
be set up after the object has finished construction.
If you need to control the order of initialization so that this is
done before any other static or global variables, you'll have to
resort to compiler- and platform-specific mechanisms (OT hint: for
MSVC++, look for #pragma init_seg).
--
Bob Hairgrove
No**********@Home.com