Option ExplicitPrivate Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As LongPrivate Sub Command1_Click()
    Dim lngResult As Long
    Dim strWinPath As String * 256
    
    lngResult = GetWindowsDirectory(strWinPath, 256)
    
    MsgBox strWinPath
End Sub

解决方案 »

  1.   

    Private Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
    Private Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As LongPrivate sRet As String
    Private lRet As Long
    Public Sub GetSysFolders(WinSysPath As String, WinPath As String)    sRet = Space(260)
        lRet = GetSystemDirectory(sRet, Len(sRet)) 'get the path
        WinSysPath = Left(sRet, lRet)                'parse the path into the global string
        
        lRet = GetWindowsDirectory(sRet, Len(sRet)) 'get the path
        WinPath = Left(sRet, lRet)                    'parse the path to the global string
       
    End Sub