程序开始菜单--VB中文版--VB实用工具---API浏览器
需要先打开“文件”然后“加载文本文件”,选“WIN32API.TXT”。
也可以在VB6IDE中的“外接程序”->外接程序管理器”中对“VB 6 API VIEW”打钩 “在启动中加载”和 “加载/卸载”。建议打钩“视图”->“加载最后文件”,下次就不用选“WIN32API.TXT”了。
选“声明”,对于下方如果有累加的信息,可以点击“清除”按钮,选“私有”,然后双击你粘贴的“GetVolumeInformation”,可以得到:
Private Declare Function GetVolumeInformation Lib "kernel32" Alias "GetVolumeInformationA" (ByVal lpRootPathName As String, ByVal lpVolumeNameBuffer As String, ByVal nVolumeNameSize As Long, lpVolumeSerialNumber As Long, lpMaximumComponentLength As Long, lpFileSystemFlags As Long, ByVal lpFileSystemNameBuffer As String, ByVal nFileSystemNameSize As Long) As Long
可以用VB6IDE的插件MZTools自动分割成:
Private Declare Function GetVolumeInformation Lib "kernel32" Alias _
"GetVolumeInformationA" (ByVal lpRootPathName As String, ByVal _
lpVolumeNameBuffer As String, ByVal nVolumeNameSize As Long, _
lpVolumeSerialNumber As Long, lpMaximumComponentLength As Long, _
lpFileSystemFlags As Long, ByVal lpFileSystemNameBuffer As String, ByVal _
nFileSystemNameSize As Long) As Long
现在我们看下GetVolumeInformation这个函数,我们可以命名成GetVolumeInformation2也行,但是Alias后面的GetVolumeInformationA是原来Dll的不能变,否则找不到Dll入口!看下代码。
新建From1(窗体),新建Command1(按钮CommandButton),代码:
Private Declare Function GetVolumeInformation2 Lib "kernel32" Alias _
"GetVolumeInformationA" (ByVal lpRootPathName As String, ByVal _
lpVolumeNameBuffer As String, ByVal nVolumeNameSize As Long, _
lpVolumeSerialNumber As Long, lpMaximumComponentLength As Long, _
lpFileSystemFlags As Long, ByVal lpFileSystemNameBuffer As String, ByVal _
nFileSystemNameSize As Long) As Long
Private Sub Command1_Click()
Dim drvserialno As Long
Dim mydrvlabel As String * 256
Dim myfilesys As String * 256
Dim i As Long
Dim j As Long
Dim x As Long
x = GetVolumeInformation2("C:\", mydrvlabel, 256, drvserialno, i, j, myfilesys, 256)
Debug.Print "Label of C Drive is " & mydrvlabel
Debug.Print "It's serial number = " & Hex(serialno)
Debug.Print "FileSystem = " & myfilesys
End Sub
运行结果:
Label of C Drive is my-c
It's serial number = 0
FileSystem = NTFS