04-28-2006 09:27 PM
I use txt files to save and load settings in CVI. For example, if I want to save current values of UIR controls, I could save these values to a txt file, then next time when I open that, I could load those values from that txt file. Sometimes, it’s not convenient when the contents in text file are quite big. Another way is to use registry, but still not convenient. Recently I know there’s another way to do that: to use ini file, by using two API functions in windows.h: WritePrivateProfileString, GetPrivateProfileString. However I failed to use this two functions in CVI. I appreciate anybody could provide a CVI example.
Thanks!
Jacky
04-29-2006 03:44 PM
Jacky, according to SDK documentation, WritePrivateProfileString is intended for compatibility with 16-bit versions of Windows; instead, the documentation encourages you to write directly to the Registry. Nevertheless, WritePrivateProfileString will indeed write values to a actual ini file if you respect some conventions when calling this function.
In my opinion, if you are interested to create and maintain a inizialitation file with parameters specific to your application you should better use the IniFile instrument shipped with CVI: you will find it into <cvidir>\toolslib\toolbox directory. The instrument is called inifile.fp and you can find an useful example on how to use it under <cvidir>\samples\toolbox\ini.cws.
CVI IniFile instrument is a powerful tool that makes using ini files easy: I reccommend you study it and incorporate into your set of instruments. In every project I create I always include IniFile instrument in the little set of general-purpose tools that I am accustomed to use.
05-02-2006 05:13 AM
With these SDK functions, there is a small trap to catch the unwary. The filename specified should be a complete pathname, not just a filename. The reason is that Windows will redirect the function to operate on the registry if only a (relative) filename is given, whereas a full (absolute) path/filename will force Windows into actual file operations.
JR