FormatEx Function?

  • Thread starter Thread starter Schorschi
  • Start date Start date
S

Schorschi

' VOID FormatEx(
' PWCHAR DriveRoot,
' DWORD MediaFlag,
' PWCHAR FSType,
' PWCHAR Label,
' BOOL QuickFormat,
' DWORD ClusterSize,
' PFMIFSCALLBACK CallBackFunc
' );

Anyone try calling this from VB .NET?

<DllImport("FMIFS.DLL", _
EntryPoint:="FormatEx", _
SetLastError:=True, _
CharSet:=CharSet.Unicode, _
ExactSpelling:=True, _
CallingConvention:=CallingConvention.StdCall)> _
Private Shared Sub FormatEx _
(ByVal thePath As String, ByVal theFlag As Int32, ByVal
theType As String, ByVal theLabel As String, ByVal theQuickOrNot As
Byte, ByVal theSize As Integer, ByVal theCallBack As
FormatExCallBackDelegate)

'

End Sub

Does this seem right?

The call to FormatEx jumps and I get a call-back to my delegate
function, but I am getting really weird results. I can't seem to find
any docs on FormatEx beyond what is at sysinternals. But it does not
define all the FormatEx call-back commands?
 
' VOID FormatEx(
' PWCHAR DriveRoot,
' DWORD MediaFlag,
' PWCHAR FSType,
' PWCHAR Label,
' BOOL QuickFormat,
' DWORD ClusterSize,
' PFMIFSCALLBACK CallBackFunc
' );

Anyone try calling this from VB .NET?

<DllImport("FMIFS.DLL", _
EntryPoint:="FormatEx", _
SetLastError:=True, _
CharSet:=CharSet.Unicode, _
ExactSpelling:=True, _
CallingConvention:=CallingConvention.StdCall)> _
Private Shared Sub FormatEx _
(ByVal thePath As String, ByVal theFlag As Int32, ByVal
theType As String, ByVal theLabel As String, ByVal theQuickOrNot As
Byte, ByVal theSize As Integer, ByVal theCallBack As
FormatExCallBackDelegate)

'

End Sub

Does this seem right?

The call to FormatEx jumps and I get a call-back to my delegate
function, but I am getting really weird results. I can't seem to find
any docs on FormatEx beyond what is at sysinternals. But it does not
define all the FormatEx call-back commands?

Your declaring the ByVal theQuickOrNot flag as a Byte - it should be an
Integer. At least last time I checked, a win32 BOOL was a 32-bit value.
In fact, I would probably just declare that as a VB Boolean - if all you
need to pass is a true or false value.
 
Tom,

Yeah, I realized that after I posted. The issue I have now is that
although the call works, it does not seem to function as expected. I
have walked thru the code from sysinternals that illustratives
FormatEx, and it works. But when I convert the code to VB .NET, the
FormatEx returns the 'done' command immediately, and the floppy is not
formated.

'
' FormatEx() Is An Undocumented API Routine...
'
' VOID FormatEx(
' PWCHAR DriveRoot,
' DWORD MediaFlag,
' PWCHAR FSType,
' PWCHAR Label,
' BOOL QuickFormat,
' DWORD ClusterSize,
' PFMIFSCALLBACK CallBackFunc
' );
'
' BOOLEAN FormatCallback(
' CALLBACKCOMMAND Command,
' DWORD SubAction,
' PVOID ActionInfo
' );

'

Public Enum FormatCluster

'

SizeDefault = 0
Size512 = 512
Size1K = 1024
Size2K = 2048
Size4K = 4096
Size8K = 8192
Size16K = 16384
Size32K = 32768
Size64K = 65536
Size128K = 131072
Size256K = 262144

End Enum

Public FormatTypeArray As String() = {"FAT"}

Public Enum FormatType

'

FAT = 0

End Enum

Public Enum FormatMedia

'

FMIFS_HARDDISK = &HC
FMIFS_FLOPPY = &H8

End Enum

Public Enum FormatCommand

'

Progress
DoneWithStructure
UnKnown2
UnKnown3
UnKnown4
UnKnown5
InsufficientRights
WriteProtected
UnKnown8
UnKnown9
UnKnownA
Done
UnKnownC
UnKnownD
OutPut
StructureProgress

End Enum

<DllImport("FMIFS.DLL", _
EntryPoint:="FormatEx", _
SetLastError:=True, _
CharSet:=CharSet.Unicode, _
ExactSpelling:=True, _
CallingConvention:=CallingConvention.StdCall)> _
Private Shared Sub FormatEx _
(ByVal thePath As String, ByVal theFlag As Int32, ByVal
theType As String, ByVal theLabel As String, ByVal theQuickOrNot As
Boolean, ByVal theSize As Int32, ByVal theCallBack As
FormatExCallBackDelegate)

'

End Sub

Delegate Function FormatExCallBackDelegate _
(ByVal theCommand As FormatCommand, ByVal theSubAction As
Int32, ByVal theAction As IntPtr) As Boolean

Function FormatExCallBack(ByVal theCommand As FormatCommand, ByVal
theSubAction As Int32, ByVal theAction As IntPtr) As Boolean

'

Select Case (theCommand)

Case FormatCommand.Progress

Case FormatCommand.DoneWithStructure

Case FormatCommand.UnKnown2

Case FormatCommand.UnKnown3

Case FormatCommand.UnKnown4

Case FormatCommand.UnKnown5

Case FormatCommand.InsufficientRights

Case FormatCommand.WriteProtected

Case FormatCommand.UnKnown8

Case FormatCommand.UnKnown9 ' Invalid Drive Root?

Case FormatCommand.UnKnownA

Case FormatCommand.Done

Case FormatCommand.UnKnownC

Case FormatCommand.UnKnownD

Case FormatCommand.OutPut

Case FormatCommand.StructureProgress

Case Else

End Select

#If DEBUG Then

'

Debug.WriteLine(String.Format("Command {0}", theCommand))

#End If

Return (True)

End Function

Function HighLevel(ByVal theType As FormatType, ByVal theCluster
As FormatCluster, Optional ByVal theLabel As String = Nothing,
Optional ByVal theQuickOrNot As Boolean = True) As Boolean

'

Select Case (theLabel)

Case Nothing

'

Case Else

'

theLabel = Left(theLabel, 11)

End Select

FormatEx("A:\", 8, "FAT", "TEST", False, 0, AddressOf
FormatExCallBack)

End Function
 
Tom,

Yeah, I realized that after I posted. The issue I have now is that
although the call works, it does not seem to function as expected. I
have walked thru the code from sysinternals that illustratives
FormatEx, and it works. But when I convert the code to VB .NET, the
FormatEx returns the 'done' command immediately, and the floppy is not
formated.

'
' FormatEx() Is An Undocumented API Routine...
'
' VOID FormatEx(
' PWCHAR DriveRoot,
' DWORD MediaFlag,
' PWCHAR FSType,
' PWCHAR Label,
' BOOL QuickFormat,
' DWORD ClusterSize,
' PFMIFSCALLBACK CallBackFunc
' );
'
' BOOLEAN FormatCallback(
' CALLBACKCOMMAND Command,
' DWORD SubAction,
' PVOID ActionInfo
' );

'

Public Enum FormatCluster

'

SizeDefault = 0
Size512 = 512
Size1K = 1024
Size2K = 2048
Size4K = 4096
Size8K = 8192
Size16K = 16384
Size32K = 32768
Size64K = 65536
Size128K = 131072
Size256K = 262144

End Enum

Public FormatTypeArray As String() = {"FAT"}

Public Enum FormatType

'

FAT = 0

End Enum

Public Enum FormatMedia

'

FMIFS_HARDDISK = &HC
FMIFS_FLOPPY = &H8

End Enum

Public Enum FormatCommand

'

Progress
DoneWithStructure
UnKnown2
UnKnown3
UnKnown4
UnKnown5
InsufficientRights
WriteProtected
UnKnown8
UnKnown9
UnKnownA
Done
UnKnownC
UnKnownD
OutPut
StructureProgress

End Enum

<DllImport("FMIFS.DLL", _
EntryPoint:="FormatEx", _
SetLastError:=True, _
CharSet:=CharSet.Unicode, _
ExactSpelling:=True, _
CallingConvention:=CallingConvention.StdCall)> _
Private Shared Sub FormatEx _
(ByVal thePath As String, ByVal theFlag As Int32, ByVal
theType As String, ByVal theLabel As String, ByVal theQuickOrNot As
Boolean, ByVal theSize As Int32, ByVal theCallBack As
FormatExCallBackDelegate)

'

End Sub

Delegate Function FormatExCallBackDelegate _
(ByVal theCommand As FormatCommand, ByVal theSubAction As
Int32, ByVal theAction As IntPtr) As Boolean

Function FormatExCallBack(ByVal theCommand As FormatCommand, ByVal
theSubAction As Int32, ByVal theAction As IntPtr) As Boolean

'

Select Case (theCommand)

Case FormatCommand.Progress

Case FormatCommand.DoneWithStructure

Case FormatCommand.UnKnown2

Case FormatCommand.UnKnown3

Case FormatCommand.UnKnown4

Case FormatCommand.UnKnown5

Case FormatCommand.InsufficientRights

Case FormatCommand.WriteProtected

Case FormatCommand.UnKnown8

Case FormatCommand.UnKnown9 ' Invalid Drive Root?

Case FormatCommand.UnKnownA

Case FormatCommand.Done

Case FormatCommand.UnKnownC

Case FormatCommand.UnKnownD

Case FormatCommand.OutPut

Case FormatCommand.StructureProgress

Case Else

End Select

#If DEBUG Then

'

Debug.WriteLine(String.Format("Command {0}", theCommand))

#End If

Return (True)

End Function

Function HighLevel(ByVal theType As FormatType, ByVal theCluster
As FormatCluster, Optional ByVal theLabel As String = Nothing,
Optional ByVal theQuickOrNot As Boolean = True) As Boolean

'

Select Case (theLabel)

Case Nothing

'

Case Else

'

theLabel = Left(theLabel, 11)

End Select

FormatEx("A:\", 8, "FAT", "TEST", False, 0, AddressOf
FormatExCallBack)

End Function

Can you give a link to the code before you converted it? I haven't used
the FormatEx call before - so it would help to see the original code
(I'm assuming C or C++?).
 
Back
Top