Public Function loadINI(strfileName, strSection, strKey) As String
    On Error GoTo err
    states = GetPrivateProfileString(strSection, strKey, "", strResult, 255, strfileName)
    If (states = 0) Then
    MsgBox ("no read the value")
    Else
    loadINI = strResult
    End If
    Exit Function
err:
    Exit Function
End Function以上是我的代码 ,可是不知道为什么就是导致vb6.0退出。
请大家帮忙,,,,,

解决方案 »

  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 pFileName As String) As LongPublic Function loadINI(strfileName, strSection, strKey) As String 
        On Error GoTo err 
        strResult = VBA.String(255, 0)
        states = GetPrivateProfileString(strSection, strKey, "", strResult, 255, strfileName) 
        If (states = 0) Then 
        MsgBox ("no read the value") 
        Else 
        loadINI = strResult 
        End If 
        Exit Function 
    err: 
        Exit Function 
    End Function 
      

  2.   

    fvflove雪情  你很聪明
    按照你的指示我修改后果然通过了
    请问这是什么原因呢?
    我能定位到是 strResult 的问题。
    但是我无法改正。
    请问你的strResult = VBA.String(255, 0)是什么意思呢?
      

  3.   

    strResult = VBA.String(255, 0)是给 strResult 分配内存大小.一般来说. 调用API 时, API不会自己为变量分配内存的.所以要自己分配.
      

  4.   

    我在定义strResult 时定义为strResult  AS NEW STRING 就不会被分配内存吗?
    而定义为strResult  AS NEW STRING * 255却可以正确了,这句跟你的strResult = VBA.String(255, 0)的意图是一样的啊