vb.net中使用GetPrivateProfileString访问INI文件_VB.net_黑客防线网安服务器维护基地--Powered by WWW.RONGSEN.COM.CN

vb.net中使用GetPrivateProfileString访问INI文件

作者:黑客防线网安VB教程基地 来源:黑客防线网安VB教程基地 浏览次数:0

本篇关键词:文件访问使用String
黑客防线网安网讯:    在vb.net2005+winxp中,我使用GetPrivateProfileString读取一个ini文件,如果文件路径中含有中文,就会遇到一个奇怪的问题:第一次读取正常,第二次读取就取不到值。代码如下: Private...

    在vb.net2005+winxp中我使用GetPrivateProfileString读取一个ini文件如果文件路径中含有中文,就会遇到一个奇怪的问题:第一次读取正常,第二次读取就取不到值代码如下:


Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Integer, ByVal lpFileName As String) As Integer

Private m_filename As String = "c:\椅子\slcuserinfo.ini"

Public Function GetiniValue(ByVal lpKeyName As String, ByVal strName As String) As String

Dim strTmp As String

'Dim fileTmp As String

'fileTmp = m_filename

strTmp = New String(" ", 100)

'Call GetPrivateProfileString(lpKeyName, strName, "", strTmp, Len(strTmp), fileTmp)

Call GetPrivateProfileString(lpKeyName, strName, "", strTmp, Len(strTmp), m_filename)

 

GetiniValue = Left$(strTmp, InStr(strTmp, vbNullChar) - 1)

End Function

Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Integer, ByVal lpFileName As String) As Integer

Private m_filename As String = "c:\椅子\slcuserinfo.ini"

Public Function GetiniValue(ByVal lpKeyName As String, ByVal strName As String) As String

Dim strTmp As String

'Dim fileTmp As String

'fileTmp = m_filename

strTmp = New String(" ", 100)

'Call GetPrivateProfileString(lpKeyName, strName, "", strTmp, Len(strTmp), fileTmp)

Call GetPrivateProfileString(lpKeyName, strName, "", strTmp, Len(strTmp), m_filename)

 

GetiniValue = Left$(strTmp, InStr(strTmp, vbNullChar) - 1)

End Function 反复试验过以后,发现取消注释掉的代码就可以正常运行百思不得其解,看api的声明没有问题啊,为什么lpFileName会出现异常呢?

    黑客防线网安服务器维护方案本篇连接:http://www.rongsen.com.cn/show-14797-1.html
网站维护教程更新时间:2012-04-03 01:14:34  【打印此页】  【关闭
我要申请本站N点 | 黑客防线官网 |  
专业服务器维护及网站维护手工安全搭建环境,网站安全加固服务。黑客防线网安服务器维护基地招商进行中!QQ:29769479

footer  footer  footer  footer