06-30-2008 04:41 PM
06-30-2008 04:42 PM
06-30-2008 06:29 PM
07-01-2008 02:11 AM
The local pointer to str inside ReadSiteSettings cannot be passed back to the caller. I have rewritte your functions using pointers to pointers so that Ini_GetRawStringCopy can correctly allocate the string and read its value back; I have added some error checking too. Finally, keep in mind that you must free the allocated strings after you use them
int CVICALLBACK DFFilter1 (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
int line, error = 0;
char *StrDFFileName = NULL, *StrDFFileDir = NULL;
if (event != EVENT_COMMIT) return 0;
errChk (ReadSiteSettings ("Generale","Manuale", &StrDFFileName));
errChk (ReadSiteSettings ("Generale","Impostazione", &StrDFFileDir));
// Use the strings
Error:
// Free the strings if allocated by the function
if (StrDFFileName) free (StrDFFileName);
if (StrDFFileDir) free (StrDFFileDir);
// Warn the operator of an error
if (error < 0) {
...
}
return 0;
}
int ReadSiteSettings (char *SectionName, char *ItemName, char **str)
{
int error = 0;
IniText IniFile = 0;
nullChk (IniFile = Ini_New(0));
if (Ini_ReadFromFile (IniFile, FCFG) == 0) {
if (Ini_SectionExists (IniFile, SectionName)) {
errChk (Ini_GetRawStringCopy (IniFile, SectionName, ItemName, str));
}
}
Error:
// Free the resource
if (IniFile) Ini_Dispose (IniFile);
// Pass the error back to the caller
return error < 0 ? error : 0;
}
As the last note, your functions could be rewritten so that the IniFile is opened only once and all needed parameters are read together, to avoid unnecessary continuous allocation of resources and access to disk.
07-01-2008 04:13 AM
07-01-2008 05:40 AM
07-01-2008 08:32 AM
07-07-2008 02:03 PM
07-07-2008 04:00 PM
07-07-2008 11:07 PM