I am updating a rather old application. It used INI file accesses all around the code, creating and freeing INI-accessing class instances here and there.
I want to centralize this to several single instances, one per used file.
So we’d get rid of instances creating/freeing copy-pasted everywhere and would have freedom to completely replace those classes would be decision to switch from INI to other settings storage.
Should one call WritePrivateProfileString(NULL, NULL, NULL…) to apply the changes?
Assume that:
1) the access goes directly to real INI-files, not to registry mapped ones.
2) OS is of NT family (maybe rarely Win2000, most probably WinXP and later). Win9x/ReactOS/WinE/Odin/etc are not cared about.
So, should we flush the ini savings now explicitly or not ?
NT does not cache Registry key writes, do no need to regFlushKey now.
But what about INI files?
MSDN page about WritePrivateProfileString only describes flushing technique wrt Win9x and NT File-to-Reg mappings. It is silent about real INI files.
The documentation contradicts itself (my bold):
Is Windows caching the mapping or a file (what file)? But the comment in the sample code makes it clear:
It is the registry file mapping that is cached. If you alter the mapping in the registry then you need to tell Windows to refresh its cache.
This is also consistent with usage of the API in Windows 3.1, where you didn’t need to flush anything. It’s unlikely that Windows would fundamentally change the usage of the API.
To double-check, I called
WritePrivateProfileStringwhile running Process Monitor. As expected, Windows opens the INI file, updates it and closes it again.No flushing required.