WritePrivateProfileSection不会覆盖 [英] WritePrivateProfileSection does not over-write

查看:203
本文介绍了WritePrivateProfileSection不会覆盖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的代码应该在ini文件中编写一个部分.

Microsoft帮助文件指出"WritePrivateProfileSection删除命名节的现有键和值,并将键名称和值插入lpString参数所指向的缓冲区中."

The following code is supposed to write a section in an ini-file.

Microsoft Help file states "WritePrivateProfileSection deletes the existing keys and values for the named section and inserts the key names and values in the buffer pointed to by the lpString parameter."

Public Function WriteIniSection(ByVal Section As String, ByVal Values() As String, ByVal IniPath As String) As Boolean
   Dim s As String = ""
   For Each a As String In Values
      If a <> "" Then s &= a & ControlChars.NullChar
   Next
   s &= ControlChars.NullChar
   Return WritePrivateProfileSection(Section, s, IniPath) = 0
End Function


除非它不会覆盖-否则会追加.
我正在使用Windows7 64位框架3.5.这是为什么?


Except it doesn''t overwrite - it appends.
I am using Windows7 64bit Framework 3.5. Is this why?

推荐答案

您是正确的,它确实会附加.

您是否找到了一种解决方案来覆盖它?
You are correct it does append.

did you find a solution to get it to overwrite ?


这可能是由于64位Windows,但我怀疑是由于.NET所致.这是因为这些是对kernel32.dll的API调用,并且是在.NET(非托管代码)之外进行处理的. IE.负责实际写入INI文件的组件不在.NET范围之内.

可能存在一些强制改写的怪异方法,就像将null值传递给WritePrivateProfileString等的特殊"行为一样……
It could be because of 64bit windows but I doubt it is because of .NET. This is because these are API calls into kernel32.dll and are handled outside of .NET (unmanaged code). I.E. The component responsible for actually writing to the INI file is outside of the scope of .NET.

There is probably some wonky way to force an overwite just like there is "special" behaviour for passing null values to WritePrivateProfileString etc...


我的解决方案是将ini文件视为普通文件并解析它们等等.
My solution is to treat the ini files as ordinary files and parse them etc.


这篇关于WritePrivateProfileSection不会覆盖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆