Re: How do you declare a Global Variable in VC++6
Charlie Chan wrote:
I have read and tried every thing I could find to successfully create
a Global variable in VC++ 6 (not .net). All I get is 'variable not
declared' or 'variable redifinition'. There has got to be a way to do
it (I hope). Please help!
I see this has evolved into a 'what is a global'?
Here is my story...
First rule, globals are bad.
Second rule, you can't avoid them.
The derivative of CWinApp is a global, theApp. What is necessary is the
continuation of that object compartmentalization that you would use with
'theApp'.
theApp is about the UI. If you have a 'project', that is another global
object. There is no good reason that theApp should know about the
'project' any more than it needs to. theProject needs to know nothing
about theApp. And what about the user policies? That is another global
object. What about the office wide policies? Yet another global object.
And what about those incidentals like, (picked the first I came across):
// Account types
.............................................................
namespace StrTypeAccountTypes
{
AFX_STATIC_DATA const LPCTSTR accountTypesStrList[]= {
_T("(null)"),
_T("MMA"),
_T("CD"),
_T("LN"),
_T("SAV"),
_T("CH"),
NULL, //needed for simple list control
};
enum AccountTypes {
actTypeNull,
actTypeMMA,
actTypeCD,
actTypeLN,
actTypeSAV,
actTypeCH,
};
)
I prefer to make theApp as stupid about what I'm doing as possible. When
I enhance theApp, it is in a generic way, applicable to any future
application. Only the top derivative, where like I implement doc
templates, does it become app sensitive. And if at all possible, only
the docs know about the specific app.
</end ramble>
Globals are part of the mix even if compartmentalized. Registry keys are
globals, and there are a lot of them....
Best, Dan.