无声息格式化磁盘的API,VB版

无声息格式化磁盘的API,VB版,使用方法:
doFormat("E:")

曾经用这API做了个小恶软,专格式化U盘,代码在这里就不予公开了~~~

Public Declare Function FormatEx Lib "FMIFS.DLL" _
(DriveRoot As Any, _
ByVal MediaFlag As Long, _
Format As Any, _
Label As Any, _
ByVal QuickFormat As Long, _
ByVal ClusterSize As Long, _
ByVal Callback As Long) As Long

Public Const FMIFS_HARDDISK = &HC
Public Const FMIFS_FLOPPY = &H8

Public Const FMIFS_SizeDefault = 0
Public Const FMIFS_Size512 = 512
Public Const FMIFS_Size1K = 1024
Public Const FMIFS_Size2K = 2048
Public Const FMIFS_Size4K = 4096
Public Const FMIFS_Size8K = 8192
Public Const FMIFS_Size16K = 16384
Public Const FMIFS_Size32K = 32768
Public Const FMIFS_Size64K = 65536
Public Const FMIFS_Size128K = 131072
Public Const FMIFS_Size256K = 262144

Public Const FMIFS_Progress = 0
Public Const FMIFS_DoneWithStructure = 1
Public Const FMIFS_InsufficientRights = 6
Public Const FMIFS_WriteProtected = 7
Public Const FMIFS_Done = 11
Public Const FMIFS_OutPut = 14
Public Const FMIFS_StructureProgress = 15

Public gbytResult As Byte

Function doFormat(sDriveLetter As String) As Boolean

On Error Resume Next
Dim bytDrive() As Byte
Dim bytFS() As Byte
Dim bytLabel() As Byte

bytDrive = sDriveLetter & Chr$(0)
bytFS = "FAT" & Chr$(0)
bytLabel = GetDriveVol(sDriveLetter) & Chr$(0)

Call FormatEx(bytDrive(0), _
FMIFS_HARDDISK, _
bytFS(0), _
bytLabel(0), _
0, _
FMIFS_SizeDefault, _
AddressOf FormatexCallBack)

If gbytResult = 1 Then
doFormat = True
Else
doFormat = False
End If

End Function

Public Function FormatexCallBack(ByVal lngCommand As Long, ByVal lngSubAction As Long, ByVal ActionInfo As Long) As Long

On Error Resume Next
Dim lngInfo As Long
Dim bytMessage(256) As Byte

Select Case lngCommand
Case FMIFS_Progress
DoEvents
Case FMIFS_DoneWithStructure
DoEvents
Case FMIFS_InsufficientRights
DoEvents
Case FMIFS_WriteProtected
DoEvents
Case FMIFS_Done
Call CopyMemory(gbytResult, ByVal ActionInfo, 1)
DoEvents
Case FMIFS_OutPut
DoEvents
Case FMIFS_StructureProgress
DoEvents
End Select

FormatexCallBack = 1

End Function

你可能感兴趣的:(api)