Click here to Skip to main content
15,918,050 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: How is it possible to access to global variable in project ? Pin
18-May-01 18:52
suss18-May-01 18:52 
GeneralRe: How is it possible to access to global variable in project ? Pin
18-May-01 20:18
suss18-May-01 20:18 
GeneralWhere is the CMainFrame in dialog project ??? Pin
19-May-01 11:27
suss19-May-01 11:27 
GeneralRe: Where is the CMainFrame in dialog project ??? Pin
Christian Graus19-May-01 13:04
protectorChristian Graus19-May-01 13:04 
GeneralRe: Where is the CMainFrame in dialog project ??? Pin
Christian Graus19-May-01 13:12
protectorChristian Graus19-May-01 13:12 
GeneralPlease !! HELP ME !! I Don't SUCCESS !!! ??? Pin
19-May-01 20:40
suss19-May-01 20:40 
GeneralRe: Please !! HELP ME !! I Don't SUCCESS !!! ??? Pin
Christian Graus19-May-01 21:59
protectorChristian Graus19-May-01 21:59 
AnswerRe: How is it possible to access to global variable in project ? Pin
#realJSOP20-May-01 2:40
professional#realJSOP20-May-01 2:40 
If you're going to use global variables, do it this way (some of this code assumes you're using Visual C++ and MFC):

Create a header file with allof your variables defines as "extern", like so:

1) Create a file called "Globals.h", that contains these lines:

// this keeps your header file from being included more than once
#ifndef __GLOBALS_H
#define __GLOBALS_H

// insert your variables here

#endif



2) Type in your variable declarations under the comment line, like so (the ones I'm showing here are merely for example):

// insert your variables here

extern int g_nMyInt;
extern CString g_sMyString;



3) Create a file called Globals.cpp, that contains these lines:

#include "stdafx.h"
#include "Globals.h"

// insert your variables here


#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

#endif


4) Under the comment line that reads "// insert your variables here", add the following lines:

// insert your variables here

int g_nMyInt;
CString g_sMyString;



All you then have to do to use these global variables is add the Globals.h and Globals.cpp files to your project, and add the following line at the top of any CPP file that uses one of your global variables:

#include "Globals.h"

QuestionHow to pass the firewall?? Pin
realyxm17-May-01 22:08
realyxm17-May-01 22:08 
QuestionCan anyone erase the background bitmap? Pin
17-May-01 17:05
suss17-May-01 17:05 
AnswerRe: Can anyone erase the background bitmap? Pin
Christian Graus17-May-01 17:43
protectorChristian Graus17-May-01 17:43 
QuestionAny ideas on reducing link times? Pin
Chris Hafey17-May-01 15:18
Chris Hafey17-May-01 15:18 
AnswerRe: Any ideas on reducing link times? Pin
Anders Molin17-May-01 23:57
professionalAnders Molin17-May-01 23:57 
GeneralRe: Any ideas on reducing link times? Pin
Gerry18-May-01 3:30
Gerry18-May-01 3:30 
GeneralRe: Any ideas on reducing link times? Pin
18-May-01 4:52
suss18-May-01 4:52 
GeneralPrinting under MFC - ARGH !!! Pin
Christian Graus17-May-01 14:57
protectorChristian Graus17-May-01 14:57 
GeneralRe: Printing under MFC - ARGH !!! Pin
l a u r e n18-May-01 12:51
l a u r e n18-May-01 12:51 
GeneralRe: Printing under MFC - ARGH !!! Pin
Christian Graus18-May-01 12:59
protectorChristian Graus18-May-01 12:59 
GeneralRe: Printing under MFC - ARGH !!! Pin
CodeGuy18-May-01 16:50
CodeGuy18-May-01 16:50 
GeneralUnicode File I/O Pin
Shankar Chandra Bose17-May-01 14:35
Shankar Chandra Bose17-May-01 14:35 
GeneralRe: Unicode File I/O Pin
l a u r e n18-May-01 12:53
l a u r e n18-May-01 12:53 
GeneralCRecordset and SQL Server 2000 Pin
SuperGeek17-May-01 11:15
SuperGeek17-May-01 11:15 
GeneralRe: CRecordset and SQL Server 2000 Pin
4-Sep-01 1:27
suss4-Sep-01 1:27 
GeneralCFormView Throwing Exception Pin
Christopher17-May-01 10:45
Christopher17-May-01 10:45 
GeneralEjecting a CD Pin
17-May-01 8:53
suss17-May-01 8:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.