How to create an INI file with an empty section?
I want to write a *.ini
开发者_如何学Pythonfile in MFC. I know those typical methods with section names, key names and key values.
I`m wondering how to write a ini file which contains only a section name, an ini file like below:
...
[section]
...
I tried the function WritePrivateProfileString() with two NULL parameters; I thought it would work but failed.
Standard ini files are supposed to be in a special format, if you're writing them in a incompatible format (which I think you are), they're not standard ini files, but you can just write it manually using normal IO classes (CStdioFile
or similar, too long since I did MFC so I can't remember the best way).
That way you can write any data you want in any format you want.
Inorder to get an empty section first define a key in that section and then delete that key by doing this you will get an empty section. [section]
[DllImport("kernel32", CharSet = CharSet.Unicode)]
static extern long WritePrivateProfileString(string section, string key, string value, string filePath);
public void DeleteKey(string Key, string Section = null)
{
Write(Key, null, Section ?? exe);
}
精彩评论