vb 2008使用GetPrivateProfile系列函数的问题

jintian01 2011-08-03 09:51:33
本人新作工程 需要使用Ini文件的有关函数。调试过程中 发现 无论是GetPrivateProfileString还是GetPrivateProfileInt
如果文件名称设置为固定路径如“C:\Setting.ini”则读写Ini文件都没有问题。
一旦文件路径换成了相对路径,问题就来了:如文件路径为 My.Application.Info.DirectoryPath +"\Setting.Ini"。(该路径下存在该文件)。执行GetPrivateProfileSring(Int)后,就什么结果也不能返回。路径也被修改成My.Application.Info.DirectoryPath +"\Setting"。(后面的.Ini没有了)那位高手能帮忙分析一下哈?

Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal SectionName As String, _
ByVal KeyName As String, ByVal Defaultstring As String, ByVal Value As String, ByVal Size As Integer, ByVal FileName As String) As Integer '在配置文件内读取字符串信息
Declare Function GetPrivateProfileInt Lib "kernel32" Alias "GetPrivateProfileIntA" (ByVal lpApplicationName As String, _
ByVal lpKeyName As String, ByVal nDefault As Integer, ByVal lpFileName As String) As Integer

代码就不贴了。那位高手能帮忙分析一下哈?
...全文
169 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
jintian01 2011-12-02
  • 打赏
  • 举报
回复
再补充个问题,传输进入的路径必须是全字母的。不能含有任何汉字,否则路径文件名称也会被修改。GetPrivateProfileStringW 和GetPrivateProfileStringA都试验过了。问题一样。各位如果有新发现。不妨在这里回复一下.
jintian01 2011-11-23
  • 打赏
  • 举报
回复
我解决了。谢谢你 还在关注。问题的根本原因是,你必须为返回的String指定足够的长度。如果字符长度为7个。那么你必须显式的定义这个String大于7个才可以。
Delete2007 2011-11-22
  • 打赏
  • 举报
回复
GetPrivateProfileSring
这个函数的最后一个参数,路径必须是全路径的.
需要在当前目录获取应用程序的目录后,传进去的参数才正确.
jintian01 2011-08-03
  • 打赏
  • 举报
回复
BestBadGod
刚才看了你给的函数作用后!我没有试验。因为该函数的作用是压缩文件的的路径。可是我的文件GetPrivateProfileInt(...,strFileName)‘时路径信息是完全正确的 而且首次可以执行。
只是首次执行过后,文件后面的".Ini"就莫名奇妙的丢失了。
倒大霉的上帝 2011-08-03
  • 打赏
  • 举报
回复
Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long


GetPrivateProfileSring(GetShortPathName(My.Application.Info.DirectoryPath +"\Setting.Ini"))

1,486

社区成员

发帖
与我相关
我的任务
社区描述
VB API
社区管理员
  • API
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧