- Rongsen.Com.Cn 版权所有 2008-2010 京ICP备08007000号 京公海网安备11010802026356号 朝阳网安编号:110105199号
- 北京黑客防线网安工作室-黑客防线网安服务器维护基地为您提供专业的
服务器维护
,企业网站维护
,网站维护
服务 - (建议采用1024×768分辨率,以达到最佳视觉效果) Powered by 黑客防线网安 ©2009-2010 www.rongsen.com.cn
作者:黑客防线网安VB教程基地 来源:黑客防线网安VB教程基地 浏览次数:0 |
在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会出现异常呢?
我要申请本站:N点 | 黑客防线官网 | |
专业服务器维护及网站维护手工安全搭建环境,网站安全加固服务。黑客防线网安服务器维护基地招商进行中!QQ:29769479 |