|
Yes, that's exactly what I mean. I don't have a specific problem using it but I wanted to have one file where everything global is defined so I wouldn't have to go into every file and use extern in its header. Is this possible at all?
|
|
|
|
|
yes, it is possible.
Here's one way :
#ifdef DECLARE_GLOBALS
#define Global
#else
#define Global extern
#endif
class CMyClass
{
...
};
Global CMyClass g_GlobalObject;
then place the definition :
#define DECLARE_GLOBALS
in one and ONLY one file, before it includes the header declaring CMyClass.
__________________________________________
a two cent stamp short of going postal.
|
|
|
|
|
Use a common header file, with the extern keyword, that is included by every implementation file. For example, MFC uses 'stdafx.h' file to include all common Windows/MFC/Sockets/ODBC/Whatever header files required in all files.
Of course, you need to use a pragma definition (#pragma once), otherwise you might get multiple-declaration errors.
Always remember, though that having too many global objects is a sure way to invite trouble in the house. Put only those variables global that MUST be, use class members and pointers to class members elsewhere whenever possible. For example, if I have a dialog that has a list control, my database class might have a direct pointer to this control, allowing manipulation where necessary.
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
OK, this is something that I was thinking of. Let me try to understand this. Make a header file and include the global class objects as externs, then include this header file in every cpp file that needs to use those objects.
I don't understand the final step. Does it have to be clearly defined in one file as not extern? If so, is this where #pragma comes in?
|
|
|
|
|
I generally find it problematic to put variable declarations (as opposed to definitions) into header files. The tricks suggested about using #ifdef... are really just to trick the compiler into accepting a generally ill-advised way of writing code.
My suggestion is to declare your global variables in the source file where they are originally created, not in a header file, and then every other source file that needs access to the global variables needs to use extern . For these other source files, they can #include a GlobalVars.h file that simply contains all of the necessary extern statements for the global variables. The main source file does not #include GlobalVars.h, as it is the file that is declaring them.
The advantage to this approach is that variables (and the access to them) is not hidden through a set of #include , #define , and #ifdef statements. You are writing exactly what you want in a straightforward way that will be less prone to error and easier to understand.
While it makes no difference to the compiler, it will be more understandable to anyone reading the code.
Dave
"You can say that again." -- Dept. of Redundancy Dept.
|
|
|
|
|
I am trying to write a small program in VC++7 (win32 console app) that invokes BIOS and DOS interrupts. I am taking an assembly langiage class, and I can add __asm blocks, but the program crashes whenever int 10h, int21h or int 33h is called. Apparently VC7 does not support the int86 function for calling interupts. Can anyone help with this
'
James Meade
vLT(jg) vUSN
vOPSOFF VAQ-140
|
|
|
|
|
If you're using Windows NT, Windows 2000, or Windows XP then using DOS interrupts directly are going to give you problems because those versions of Windows don't use DOS.
Jeremy Falcon
|
|
|
|
|
Tank_Aviator wrote:
...but the program crashes whenever int 10h, int21h or int 33h is called
As it should. The HAL is doing its job by restricting access to the hardware. You'd need to create a ring-0 application if you want to communicate directly with the hardware. This article has some useful bits in it.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
The BIOS and DOS ints don't exist inside a Win32 console app. You need to create a 16 bit DOS app with the 16 bit tools and then run that, which will mostly work on NT.
Paul
|
|
|
|
|
You can't, use the correct Win32 APIs instead: for example, CreateFile for opening files, SetConsoleOutputCharacter and kin for manipulating the console.
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
it does support them but you are not allowed to call interrupts except the general ones and the native interrupts for windows nt.
if you are calling anything different your software WILL crash!
even in kernel mode you don't have access to bios interrupts because the system uses it's own ways to communicate with the hardware. I propose you have a look at the future!
Don't try it, just do it!
|
|
|
|
|
This is an odd question to place in the correct forum, so I chose this one hoping it would be the most relavent due to the subject.
I have a bunch of VS.NET 2003 C++ projects that I need to compile in VC++ 6.0. Don't ask why because it pains me just to think about it. The projects will all compile fine with VC6 so that wont be a problem. I could recreate the project files by hand, but it would take me a good few days to do them all and even after doing just one my nerves are a complete mess. What I need is a utility, macro, or whatever that can take a VS.NET 2003 project file and create a VC6 one with the appropriate settings carried across (or one that can take VS.NET 2002 files as there is a converter between 2003 and 2002 on this site).
Does such a thing exist or am I destined to be punished and should stock up on caffeine?
Putting the laughter back into slaughter
|
|
|
|
|
I think you are look for this[^].
Chris Meech
We're more like a hobbiest in a Home Depot drooling at all the shiny power tools, rather than a craftsman that makes the chair to an exacting level of comfort by measuring the customer's butt. Marc Clifton
VB is like a toolbox, in the hands of a craftsman, you can end up with some amazing stuff, but without the skills to use it right you end up with Homer Simpson's attempt at building a barbeque or his attempt at a Spice rack. Michael P. Butler
|
|
|
|
|
So much for the CodeProject search.
Thanks Chris. ++
Putting the laughter back into slaughter
|
|
|
|
|
Hi. I have a question: how can I change the pixel values of a jpeg image? (after decompression of course). I'm not really good at this... any help is appreciated. Thanks.
We are accidents waiting to happen...
|
|
|
|
|
JPG is a lossy compression format.
It means that if you modify an jpg image
and save it again it will lose
quality very much.
But you can handle it's view in rendering level
by graphical CDC function in show time.
|
|
|
|
|
If you're using GDI+ it's easy, check out my image processing articles ( in C#, but easy to convert, they started in C++ ). If you're using GDI, you need to load the image into a DIBSection. The library you use to load jpeg ( if you're not using GDI+ to do it ) probably uses a DIBSection wrapper internally, DDB's are pretty much useless.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
Hello All,
I have looked, but cannot find an answer to my specific need. Maybe there is some code somewhere that I have overlooked and if that is the case please direct me to it. Otherwise please (and an example would be VERY much appreciated) can any one tell me how to dynamically create a Doc/View in a Dialog with the ability to add information to the Doc/View based on selection made by the user from the Dialog.
For instance if I have some radio buttons on the dialog and a combo box. The user selects a radio button then makes multiple selection from the ComboBox and depending on those selection a Doc/View would be created and filled in based on the selections made.
Utilizing the code from "Inserting a Doc/Frame/View in a dialog using a custom control" which I got from this site. I am able to get the Doc/View to work, but I have been unsuccessful in placing the information needed on it once created.
What I have found to this point is that if I place information in the constructor of the Dialog I can get that information to show on the Doc/View. However, if I try to make any changes on the dialog I can't get the Doc/View to show the new information. So if anyone can help me get back on track with this I would be very Thankful!
I have tried to locate some code examples here and at Code Guru, but I haven't found anything that dynamically or programtically does what I am trying to do. So a good code example is what I am really looking for. However, any help would be appreciated. Thanks in advance.
Charlie
|
|
|
|
|
CharlieC wrote:
What I have found to this point is that if I place information in the constructor of the Dialog I can get that information to show on the Doc/View. However, if I try to make any changes on the dialog I can't get the Doc/View to show the new information. So if anyone can help me get back on track with this I would be very Thankful!
Assuming you have a pointer to your document, can't you just change the document contents when needed,
and call CDocument::UpdateAllViews...?
Iain.
|
|
|
|
|
|
I want to implement send as fax in my app.How can I do this?Thanks.
|
|
|
|
|
The easiest way is to implement standard printing and setup a fax device on the machine and print to that.
Ant.
|
|
|
|
|
I want to send from my fax to another fax rtf files.If you know how can i do this please tell me.I need this desperately.Thanks a lot.
|
|
|
|
|
I want to open rtf files with my own app.How can I do this?Thanks.
|
|
|
|
|
How about using ShellExecute() ?
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|