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 LongPrivate Sub Command1_Click()
   Dim str As String
   str = Space$(1000)
   profilePath = App.Path & "ABC.INI"
   a = GetPrivateProfileString("ROOT", "START", "", str, 1000, profilePath)
   If a = 0 Then
      MsgBox Left$(str, Len(Trim$(str)) - 1), vbInformation
   Else
      MsgBox "读取配置文件失败!", vbExclamation
   End If
End Sub
------------------------------------------------------------------------
ACB.INI文件:
[ROOT]
START=2006-2-16 9:32:06

解决方案 »

  1.   

    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    
    function ReadINIFile 
        Dim X As Long    X = GetPrivateProfileString(lpappname, lpKeyName, "~", temp, Len(temp),   App.Path + "\Profile.ini")
        ReadINIFile = Left(temp, InStr(temp, Chr(0)) - 1)
    end function
      

  2.   

    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    
    function ReadINIFile 
        Dim X As Long
        Dim temp As String * 128
        X = GetPrivateProfileString(lpappname, lpKeyName, "~", temp, Len(temp),   App.Path + "\Profile.ini")
        ReadINIFile = Left(temp, InStr(temp, Chr(0)) - 1)
    end function
      

  3.   

    TO:xeonwei(以下信息不对外公开),首先谢谢!
    按照你提供的代码,我改了我原来的,可是读取时提示失败啊!!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 LongPrivate Sub Command2_Click()
       Dim profilePath as String
       Dim str As String * 128
       profilePath = App.Path & "ABC.INI"   a = GetPrivateProfileString("ROOT", "START", "~", str, Len(str), profilePath)
       If a = 0 Then
          MsgBox Left(str, InStr(str, Chr(0)) - 1), vbInformation
       Else
          MsgBox "读取配置文件失败!", vbExclamation
       End If
    End Sub