GetWindowsDirectory()

来源:百度知道 编辑:UC知道 时间:2024/06/25 03:58:52
Option Explicit
Public Const max_path = 260
Public Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long

Sub getwindowsdirectory_test()
Dim s As String, length As Long
s = String(max_path, 0)
length = GetWindowsDirectory(s, max_path)
s = Left(s, InStr(s, Chr(0)) - 1)
MsgBox "windows 路径=" & s, , "getwindowsdirectory"
End Sub

上面的
length=getwindowsdirectory(s,max_path)
是什么意思
length得到什么值

GetWindowsDirectory

VB声明
Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
说明
这个函数能获取Windows目录的完整路径名。在这个目录里,保存了大多数windows应用程序文件及初始化文件

返回值
Long,复制到lpBuffer的一个字串的长度。如lpBuffer不够大,不能容下整个字串,就会返回lpBuffer要求的长度。零表示失败。会设置GetLastError

参数表

参数 类型及说明
lpBuffer String,指定一个字串缓冲区,用于装载Windows目录名。除非是根目录,否则目录中不会有一个中止用的“\”字符

nSize Long,lpBuffer字串的最大长度