.版本 2
.子程序 取系统目录_API, 文本型
.局部变量 缓冲区, 文本型
.局部变量 长度, 整数型
缓冲区 = 取空白文本 (260)
长度 = GetSystemDirectoryA (缓冲区, 260)
返回 (缓冲区)
VB应用示例
Declare Function GetSystemDirectory Lib "kernel32.dll" Alias "GetSystemDirectoryA" (ByVal strBuffer As String, ByVal lngSize As Long) As Long '定义API
Public Function TheSystemDir() As String
Dim strBuffer As String
Dim l As Long
strBuffer = Space(255) '建立缓冲区为255个空格
l = GetSystemDirectory(strBuffer, 255)
TheSystemDir = Left(strBuffer, l) '取其中一部分
End Function
'调用时使用以下代码即可
TheSystemDir
VC应用示例
#include<iostream>
#include<windows.h>
usingnamespacestd;
intmain()
{
charpath[MAX_PATH];
GetSystemDirectory(path,MAX_PATH);
cout<<path<<endl;
return0;
}