An application can store strings, integers, and binary data in an initialization file and retrieve them. To read from or write to an initialization file, your application must provide a section name and a key name that specify which setting to read or change. If the section or key name you specify in a writing operation does not exist in the file, it is added to the file and assigned the given value.
The following code fragment creates a section named "MyApp" and a key named "MainWindowColor" in a previously opened initialization file, and assigns the value of the RGB structure to the new setting:
HINI hini; RGB rgb = { 0xff, 0x00, 0x00 }; PrfWriteProfileData(hini, "MyApp", "MainWindowColor", &rgb, sizeof(RGB));
To read a setting, your application can retrieve the size of the setting and then read the setting into an appropriate buffer by using the PrfQueryProfileSize and PrfQueryProfileData functions, as shown in the following example. This example reads the setting "MainWindowColor" from the "MyApp" section only if the size of the data is equal to the size of the RGB structure.
HINI hini; ULONG cb; RGB rgb; PrfQueryProfileSize(hini, "MyApp", "MainWindowColor", &cb); if (cb == sizeof(RGB)) PrfQueryProfileData(hini, "MyApp", "MainWindowColor", &rgb, &cb);
An application can also read strings by using the PrfQueryProfileString function, write strings by using the PrfWriteProfileString function, and read integers (stored as strings) by using the PrfQueryProfileInt function.