Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to declare a global variable?

Status
Not open for further replies.

scecilia

Programmer
Jul 8, 2002
35
US
Hello,

How can I declare a global variable to be used by all the classes in a VC++ project? I added the variable (HANDLE processHandle) in the .h file of the main function, but apparently this cannot be seen other classes in the app.

thanks,
 
You need to declare it in a .cpp first, like so:
HANDLE hProc = NULL; //(or whatever).

Then you must either extern it in all the .cpp's that use it or (and this is my preference) extern it in a header file that's included in every .cpp (like for instance stdafx.h) like so: extern HANDLE hProc;
Greetings,
Rick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top