By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,515 Members | 1,848 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,515 IT Pros & Developers. It's quick & easy.

Implementation of Factory Patern using C++ DLL's

P: n/a
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

Nov 1 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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
Nov 1 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.