读写INI文件的自定义函数(VB)

王朝vb·作者佚名  2006-01-09
宽屏版  字体: |||超大  

Private Declare Function GetPrivateProfileInt Lib "kernel32" Alias "GetPrivateProfileIntA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal nDefault As Long, ByVal lpFileName As String) As Long

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

Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long

Private Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long

'写INI文件(字符串)

Public Sub WriteINI(ByVal FileName As String, ByVal App As String, ByVal Key As String, ByVal strValue As String)

Dim Result As Long

Result = WritePrivateProfileString(App, Key, strValue, FileName)

End Sub

'读整型

Public Function GetINIint(ByVal FileName As String, ByVal App As String, ByVal Key As String) As Long

Dim Result As Long

Result = GetPrivateProfileInt(App, Key, 0, FileName)

GetINIint = Result

End Function

'读字符串

Public Function GetINIstr(ByVal FileName As String, ByVal App As String, ByVal Key As String) As String

Dim Result As Long

Dim BufferStr As String * 255

Result = GetPrivateProfileString(App, Key, "", BufferStr, Len(BufferStr), FileName)

If Result = 0 Then

GetINIstr = ""

Else

GetINIstr = Left(BufferStr, Result)

End If

End Function

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
© 2005- 王朝网络 版权所有