LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

how to make a startup config file

I need to make a config file where i can define a few constants that will be loaded even before the main is.

I know Visual studios can do this and was wondering if you could do it in Lab Windows

here is what i need to define

#define NUM_STATIONS 8
#define NUM_TESTS 4

I want these defined in a config file so someone can change these without recompiling my program.

I cant just read the files in because i have global arrays that depend on these 2 values.
0 Kudos
Message 1 of 2
(3,158 Views)
It seems that defines are not a solution to your needs: #define is a directive that can influence compiler behaviour, but is not recognized in a compiled executable.

Instead, you could structure your program to read a configuration file at the very beginning, and dynamically allocate your arrays based on the configuration options stored in this file.

Here is the structure I give to all my applications:

Program starting:
1. Read configuration file from disk
2. Define static and dynamic variables
3. Read parameters from disk
4. Retrieve status of the application (if applicable)
5. Start the GUI
6. End program


In detail:
1. Read configuration file from disk
For this part extensively use the INI files reading and writing them by means of the inifile.fp instrument driver (is in toolbox directory). The INI file is the standard file structure in sections and items: a sample file could be:

[General]
# of stations = 8
# of tests = 4

2. Define static and dynamic variables
In this routine I use calloc to dynamically allocate memory for the program. Keep in mind that calloc can treat arrays of structure: so you can define your own struct that holds all variables related for example to a testing station and allocate the necessary space for them. For example: define the struct in a include file:

tyedef struct { // Define the structure of your variable
int ID;
char SerialNumber;
// other variables needed
} station;
station *s; // Define the variable to be dynamically allocated

Next in the source code allocate memory for your stations:

s = calloc (n_stats, sizeof (station));

3. Read parameters from disk
In this routine I read from disk all variables parameters applicable to my program: in your case maybe some parameters related to stations and tests. Again, I rely on INI files to store informations.

4. Retrieve status of the application (if applicable)
No need for further explanation

5. Start the GUI
The program can start with all static and dynamic variables setup in a proper way

6. End program
Remember to free() all dynamic memory allocated in the program

I hope all this can help you a little
Roberto

Message Edited by Roberto Bozzolo on 06-25-2005 08:06 AM



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 2
(3,156 Views)