   extern/windows programming question
  HiI'm currently using the windows implementation provided by the folk at nehe in my little shooter game.  At the moment i'm trying to create a font class which for defining a new font then being able to print text with the font.  The problem is I need access to my Device Context handle but that's in a different file.I've got a few source files windows.cpp which holds all the windows code (the hDC) and i've created a font class in not surprisingly font.h and .cpp.   I tried taking the variables from the top of the windows.cpp file and putting them into a windows.h file but that seems to screw everthing up.  THE FONT unsigned int Font::Create_Font(char *fontName, int fontSize){// Windows font.HFONT hFont;unsigned int base;// Create space for 96 characters.base = glGenLists(96);if(stricmp(fontName, "symbol")==0){hFont = CreateFont(   -24, 0, 0, 0, FW_BOLD, FALSE, FALSE, FALSE,SYMBOL_CHARSET, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS,ANTIALIASED_QUALITY, FF_DONTCARE | DEFAULT_PITCH, fontName);}else{hFont = CreateFont(-24, 0, 0, 0, FW_BOLD, FALSE, FALSE, FALSE,ANSI_CHARSET, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS,ANTIALIASED_QUALITY, FF_DONTCARE | DEFAULT_PITCH, fontName);}if(!hFont) return 0;SelectObject(hDC, hFont);wglUseFontBitmaps(hDC, 32, 96, base);return base;}AND THE BIT OF WINDOWS CODE FROM THE TOP OF WINDOWS.CPPHDChDC  =NULL;// Private GDI Device ContextHGLRChRC  =NULL;// Permanent Rendering ContextHWNDhWnd  =NULL;// Holds Our Window HandleHINSTANCEhInstance;// Holds The Instance Of The ApplicationOne of my mates mentioned that I might be able to do something with externs to make the hDC a totally global variable or something but I haven't got the first clue about that.  Cheers for advice and help.Neil[Edited by - bapti on December 4, 2005 11:40:49 AM]
  well if I remember the nehe tutorials correctly the hdc is allready a global so yes you declare it as extern and use it in your font file:).That may offend teh sensibilities of some people on this list but it will let you get going on your font renderer!CheersChris   ;  sorry to be a pest but I don't really know how to define this extern stuff.  This is what I tried failedextern  HDChDC=NULL;// Private GDI Device ContextI did see this when I was looking through other posts which had extern in themextern 'C'{}Do I also have to make changes to my font class and declare a hDC at the top of the font.cpp or something like that?  I'm just picking up tid-bits from other posts i've read.   ;  You can't initialize an extern - an extern is like a prototype. So, yes, declare extern HDChDC; in the top of font.cpp (Thus removing =NULL)extern 'C' { } Is actually a way to export C functions and code, ie. in a C++ library, where you want a program written in C to be able to access certain wrapper functions, etc.   ;  It would be better to pass hDC as a parameter to Font::Create_Font.   