基本的なディレクトリ取得方法。GetTempPath 関数は、GetWindowsDirectory 関数 や GetSystemDirectory 関数 とちょっと作りが違う。名前の付け方といい、引数といい、取得するディレクトリ文字列といい…作者が違うのかな?
以下はAPI宣言
Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" (ByVal nSize As Long, ByVal lpBuffer As String) As Long |
◆ Windowsディレクトリを取得する ◆
'-------------------------------------------------------------------
' 関数名 : GetWindowsDir
' 機能 : Windowsディレクトリを取得する
' 引数 : なし
' 返り値 : 正常:Windowsディレクトリ エラー:空文字列
'-------------------------------------------------------------------
Public Function GetWindowsDir() As String
Dim FuncRet As Long
Dim tmpWinDir As String * 256
FuncRet = GetWindowsDirectory(tmpWinDir, Len(tmpWinDir))
If FuncRet Then GetWindowsDir = Left$(tmpWinDir, InStr(tmpWinDir, Chr$(0)) - 1)
'実はEnvironを使用とした方が1行だし簡単という噂がある
GetWindowsDir = Environ("windir")
End Function
|