LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How to use the functions in toolbox\inifile.fp to use an ini file ? Example ?

I want to create/read/write Windows-style ini-files. I found an instrument file which seems to contain the necessary functions but I don't know how to proceed.
0 Kudos
Message 1 of 2
(3,661 Views)
I extensively use INI-style files to save configuration and parameters in my applications. I have found more confortable to load the IniFile instrument as a library than as an instrument, so it is available for all of my projects without need to load it for each of them.

It can be useful for you to study the ini.prj example that ships with CVI (you'll find it in \samples\toolbox directory): it covers almost all functions included in the instrument.

For a simple skeleton code, here you'll find some lines of code for saving some configuration information to a file.

int SaveSession (void)

// Saving session data
{
int error = 0;
char msg[128];
IniText T = 0;

// Create a IniText object and reaf existing data from the file
nullChk (T =
Ini_New (0));
errChk (Ini_ReadFromFile (T, "session.cfg"));

// Saving new data
errChk (Ini_PutInt (T, "Session", "Type", type));

// Test results
errChk (Ini_PutInt (T, "Session", "Tested", test));
errChk (Ini_PutInt (T, "Session", "Good", good));
errChk (Ini_PutBoolean (T, "Session", "CalcToBeDone?", toCalc));

// Saving new entries to the file
errChk (Ini_WriteToFile (T, "session.cfg"));

Error:
if (T) Ini_Dispose (T);
if (error < 0) {
sprintf (msg, "Error %d received in %s:\n%s.", error, __FUNCTION__,
GetGeneralErrorString (error));
MessagePopup ("Critical error", msg);
}
return error;
}


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,661 Views)