LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How to use WritePrivateProfileString and GetPrivateProfileString in CVI

  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

0 Kudos
Message 1 of 3
(5,752 Views)

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.



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 3
(5,745 Views)

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

0 Kudos
Message 3 of 3
(5,710 Views)