'读取注册表
Public Function GetIniValue(AppName As String, KeyName As String, Default As String, FileName As String) As String
Dim ret As String, NC As Long
ret = String(255, 0)
NC = GetPrivateProfileString(AppName, KeyName, Default, ret, 255, FileName)
'NC is the number of characters copied to the buffer
If NC <> 0 Then ret = Left$(ret, NC)
GetIniValue = ret
End Function
Public Function GetIniValue(AppName As String, KeyName As String, Default As String, FileName As String) As String
Dim ret As String, NC As Long
ret = String(255, 0)
NC = GetPrivateProfileString(AppName, KeyName, Default, ret, 255, FileName)
'NC is the number of characters copied to the buffer
If NC <> 0 Then ret = Left$(ret, NC)
GetIniValue = ret
End Function
Dim t As String * 255
GetPrivateProfileString "dbsource", "dsn", Default, t, 255, "C:\test\setting.ini"
Print Left(t, InStr(t, Chr(0)) - 1) 'newtest
End Sub
Dim t As String * 255
GetPrivateProfileString szAppName, szKey, szDefault, t, 255, "C:\test\setting.ini"
ReadCfg = Left(t, InStr(t, Chr(0)) - 1)
End Function
Private Sub Command1_Click()
Print ReadCfg("dbsource", "dsn", "")
End Sub
Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpRetunedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long