先 Imports System.Runtime.InteropServices
然后创建包装类
Class LIBWARP
<DllImport("Kernel32.dll")> _
Friend Shared Function GetVolumeInformation(ByVal strRoot As [String], ByVal strVolumeName As System.Text.StringBuilder, ByVal nSizeName As Integer, ByRef serial As Integer, ByRef maxComponentLength As Integer, ByRef nFSOptions As Integer, ByVal strFileSystemName As System.Text.StringBuilder, ByVal nFSNameSize As Integer) As Boolean
End Function
End Class
最后测试
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim bufName As New System.Text.StringBuilder(1024)
Dim bufFS As New System.Text.StringBuilder(1024)
Dim size As Integer = bufName.Capacity
Dim n As Integer = 0
Dim serial As Integer = 0
LIBWARP.GetVolumeInformation("C:\\", bufName, size, serial, n, n, bufFS, size)
MsgBox(Convert.ToString(serial, 16))
End Sub
End Class
|