Click to See Complete Forum and Search --> : Gloabal objects


Philmes
August 12th, 1999, 04:42 PM
Is there anyway in C++ of declaring a global object? I want to create a single workspace object for my DB appliction, and access this object from my entire application. Any way of achieving this?
Regards, Phil Messenger

Dmitriy
August 12th, 1999, 06:07 PM
Are your "entire app" and "DB app" different exe-s?
If so, what do you want? If you want just exchange by messages beetwen apps you can registr
your custom messages for the exchange.
Another way - create separate thread and exchange
with this thread by SetEvent, while the thread will be "WaitForMultipleObject"


Dmitriy, MCSE

John Killingbeck
August 12th, 1999, 10:06 PM
You declare a global anything by putting it in a .cpp file outside of any function, such as directly after you #includes. If you need to use the global in another .cpp file use the 'extern' keyword in front of the declaration. No redefinition is needed. You do seem to be defeating the purpose of object oriented programming, however. OOP procedures are developed to minimize problems, so following them will make life easier (or at least programming). Try keeping your workspace object in your CDocument class and access it from there.