+ -
当前位置:首页 → 问答吧 → vb 2008使用GetPrivateProfile系列函数的问题

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

时间:2011-08-03

来源:互联网

本人新作工程 需要使用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

代码就不贴了。那位高手能帮忙分析一下哈?

作者: jintian01   发布时间: 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"))

作者: BestBadGod   发布时间: 2011-08-03

BestBadGod
刚才看了你给的函数作用后!我没有试验。因为该函数的作用是压缩文件的的路径。可是我的文件GetPrivateProfileInt(...,strFileName)‘时路径信息是完全正确的 而且首次可以执行。
只是首次执行过后,文件后面的".Ini"就莫名奇妙的丢失了。

作者: jintian01   发布时间: 2011-08-03

热门下载

更多