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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

extern variables in WinMain and how to use GetVolumeInformation. 1

Status
Not open for further replies.

sirbu

Programmer
Sep 15, 1999
15
0
0
RO
Hy everyone,
first a question: I have a C file where the WinMain function resides, and where on the WM_COMMAND case I handle menu options. As an example on IDM_FILE_NEW I launch a dialog box from where I get some input which I convert to numeric variables. The dialog function I've wrote in a separate C file. So that the variables that I read with the dialog function to be available to the rest of the code, in the WndProc I've declared them with the extern attribute and the same in the file where resides the dialog function. I don't find this elegant because the variables will exist as long as the code will run. So my question is if someone has a better idea on how to read some variables through a dialog box and make them available to the rest of the code.
The second problem is that there is anyone who can pass me some sample code on how to use GetVolumeInformation function to read an harddisk serial number.
Thanks in advance
 
Well, sirbule, why don't you use some global variables to hold that information, maybe incorporate them in a global structure.
You can create a pointer to the structure and allocate the structure and dealocate it at any time, reducing the amount of memory used permanently by the program (only the 4 bytes of the pointer will be kept in memory permanently, so i think it is a good trade-off.
HTH...


[red]Nosferatu[/red]
We are what we eat...
There's no such thing as free meal...
once stated: methane@personal.ro
 
Some remark.
I am suggestion to keep out of public structures. Better use static structure inside your model (not visible outside of this module) and provide public function for access to some data. This will keep you free to change structure without changing whole code. This is maybe not very important for small closed application, but can be crucial for big application or libraries.
Better always use two function:
GetData(...);
ReleaseData(...);
In release data you can free unnessary data or keep it for future use. This is very important when number of user of this data more then one.
 
Excellent point, Lim! [red]Nosferatu[/red]
We are what we eat...
There's no such thing as free meal...
once stated: methane@personal.ro
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top