Click here to Skip to main content
15,914,795 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: How to lock a file? Pin
Masaaki Onishi20-May-01 12:46
Masaaki Onishi20-May-01 12:46 
GeneralMouse Sampling Rage Pin
20-May-01 4:16
suss20-May-01 4:16 
GeneralCoM ( ATL): resizing of a window MPlayer Pin
20-May-01 1:06
suss20-May-01 1:06 
QuestionCoM ( ATL): events through a definite interval senden? Pin
20-May-01 0:55
suss20-May-01 0:55 
GeneralThe Com-interface for control Mediaplayer Pin
20-May-01 0:50
suss20-May-01 0:50 
Generalhelp! Counterfesance ATLMOVIE from MSDN not (( Pin
20-May-01 0:45
suss20-May-01 0:45 
Generalglobal variabls. please help me! URGENT !!! Pin
19-May-01 20:56
suss19-May-01 20:56 
GeneralRe: global variabls. please help me! URGENT !!! Pin
Rick York19-May-01 21:13
mveRick York19-May-01 21:13 
There are a variety of methods to do this but here is one that I use and it works for me. In one header file that all the source files include do this :

#ifdef DECLARE_GLOBALS
#define Global
#else
#define Global extern
#endif

Then you declare your global variable like this :

Global YourType YourVariable;

Now here is the really important part. In one and ONLY ONE file, typically the application class source file, you place this definition :

#define DECLARE_GLOBALS

right BEFORE you include the header file with the variables.
What this does is make the global variable declaration an extern in all files except for the one where the official, non-extern declaration occurs. So, this one file will look something like this :

#define DECLARE_GLOBALS
#include "YourHeader.h"

It is REALLY IMPORTANT that only one file has the DECLARE_GLOBALS definition. Otherwise you will get multiple variable declaration errors.


GeneralRe: global variabls. please help me! URGENT !!! Pin
19-May-01 21:46
suss19-May-01 21:46 
GeneralRe: Why do you want to use global variable? Pin
Masaaki Onishi20-May-01 5:15
Masaaki Onishi20-May-01 5:15 
GeneralRe: Why do you want to use global variable? Pin
#realJSOP20-May-01 7:31
professional#realJSOP20-May-01 7:31 
Generalthe all very nice, but my code DON'T WORKING !!! Pin
20-May-01 8:53
suss20-May-01 8:53 
GeneralRe: the all very nice, but my code DON'T WORKING !!! Pin
Christian Graus20-May-01 10:06
protectorChristian Graus20-May-01 10:06 
GeneralRe: the all very nice, but my code DON'T WORKING !!! Pin
Rick York20-May-01 21:37
mveRick York20-May-01 21:37 
GeneralRe: Why do you want to use global variable? Pin
Masaaki Onishi20-May-01 12:09
Masaaki Onishi20-May-01 12:09 
GeneralIt's me again. Looking for suggestions... Pin
Stephen Caldwell19-May-01 19:46
Stephen Caldwell19-May-01 19:46 
GeneralRe: It's me again. Looking for suggestions... Pin
l a u r e n20-May-01 2:33
l a u r e n20-May-01 2:33 
GeneralRe: Hum, sound like IM Messenger. Pin
Masaaki Onishi20-May-01 5:00
Masaaki Onishi20-May-01 5:00 
GeneralRe: Hum, sound like IM Messenger. Pin
l a u r e n20-May-01 10:54
l a u r e n20-May-01 10:54 
GeneralMySql++ Pin
Stephen Caldwell19-May-01 18:53
Stephen Caldwell19-May-01 18:53 
GeneralRe: MySql++ Pin
l a u r e n20-May-01 2:35
l a u r e n20-May-01 2:35 
GeneralRe: MSDE? Pin
Masaaki Onishi20-May-01 7:34
Masaaki Onishi20-May-01 7:34 
GeneralRe: MSDE? Pin
Anders Molin20-May-01 8:54
professionalAnders Molin20-May-01 8:54 
GeneralRe: Humm. Pin
Masaaki Onishi20-May-01 11:56
Masaaki Onishi20-May-01 11:56 
GeneralRe: Humm. Pin
Anders Molin20-May-01 12:07
professionalAnders Molin20-May-01 12:07 

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.