Option Explicit
Private Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, _
ByVal nSize As Long) As Long
Private Sub Command1_Click()
'变量定义。
Dim dstr1 As String
dstr1 = String(255, 0)
'调用函数。
Call GetWindowsDirectory(dstr1, 255)
'返回数值处理。
dstr1 = Left(dstr1, InStr(1, dstr1, Chr(0)) - 1)
'数据的输出。
Text1.Text = dstr1
End Sub
Private Sub Command2_Click()
End '退出。
End Sub
'获得系统的临时文件夹
Option Explicit
Private Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
Private Const Max_PATH = 260
Private Function GetTempDir() As String
Dim TempDir As String
Dim ChrLen As Long
TempDir = Space(Max_PATH)
ChrLen = GetTempPath(Max_PATH, TempDir)
If ChrLen > Max_PATH Then
ChrLen = GetTempPath(TempDir, ChrLen)
End If
GetTempDir = Left(TempDir, ChrLen)
End Function
Private Sub Form_Load()
With Text1
.Font = 18
.Text = GetTempDir
End With
End Sub
'获得系统文件夹
Option Explicit
Private Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
Private Const MAX_PATH = 260
Private Function GetSysDir() As String
Dim SysDir As String
Dim ChrLen As String
SysDir = Space(MAX_PATH)
ChrLen = GetSystemDirectory(SysDir, MAX_PATH)
If ChrLen > MAX_PATH Then
ChrLen = GetSystemDirectory(SysDir, ChrLen)
End If
GetSysDir = Left(SysDir, ChrLen)
End Function
Private Sub Form_Load()
Dim SysDir As String
SysDir = GetSysDir
Text1 = SysDir
End Sub