Implementation of Factory Patern using C++ DLL's

R

Roi

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
 
B

Bob Hairgrove

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).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top