|
-
May 11th, 2001, 05:48 PM
#1
how to determine Diskette status?
Hello all,
What WinAPI would I use to determine the status of a diskette in the A: drive? When you insert a diskette into the A: drive NT can return several results.
1) Format is not recognized, format it now.
2) Bad CRC
3) No diskette present.
Which API call, method or function do I call in order to retrieve these types of resultants? thanks
Mark
-
May 11th, 2001, 08:07 PM
#2
Re: how to determine Diskette status?
I did a program before on GetDiskFreeSpace() and when I pointed it to A: and there is a problem, the function returns the ERROR and by processing the error, you should be able to determine the problem. Kinda not a real way to do it but it works.
-Cool Bizs
Good Luck,
-Cool Bizs
-
May 11th, 2001, 09:24 PM
#3
Re: how to determine Diskette status?
I created a form with the following code
'In general section
private Declare Function GetDiskFreeSpaceEx Lib "kernel32" Alias "GetDiskFreeSpaceExA" (byval lpRootPathName as string, _
byref lpFreeBytesAvailableToCaller as Currency, _
byref lpTotalNumberOfBytes as Currency, _
byref lpTotalNumberOfFreeBytes as Currency) as Long
private Declare Function GetLastError Lib "kernel32" () as Long
private Sub Command1_Click()
Dim lResult as Long, lResult2 as Long
Dim r as Long, BytesFreeToCalller as Currency, TotalBytes as Currency
Const RootPathName = "A:"
lResult = GetDiskFreeSpaceEx(RootPathName, BytesFreeToCalller, TotalBytes, TotalFreeBytes)
If lResult <> 0 then
me.AutoRedraw = true
me.Cls
me.print
me.print " Total Number Of Bytes:", Format$(TotalBytes * 10000, "###,###,###,##0") & " bytes"
me.print " Total Free Bytes:", Format$(TotalFreeBytes * 10000, "###,###,###,##0") & " bytes"
me.print " Free Bytes Available:", Format$(BytesFreeToCalller * 10000, "###,###,###,##0") & " bytes"
me.print " Total Space Used :", Format$((TotalBytes - TotalFreeBytes) * 10000, "###,###,###,##0") & " bytes"
else
me.Cls
lResult2 = GetLastError
lblError.Caption = "error Number: " & lResult & ":" & lResult2
End If
End Sub
I have a diskette that is unformatted and one that has a CRC error, but when I insert them the GetLastError is always zero. Any ideas?
Mark
-
May 11th, 2001, 10:18 PM
#4
Re: how to determine Diskette status?
Try putting the GetLastError() line before me.Cls. Remember that GetLastError() will retrieve the last system error and I think me.Cls might have cleared it off.
-Cool Bizs
Good Luck,
-Cool Bizs
-
May 13th, 2001, 04:10 AM
#5
Re: how to determine Diskette status?
Hmmm, it still doesn't work... I even tried the following code, but still doesn't work..
private Sub Command2_Click()
Dim lResult as Long, lResult2 as Long
lResult = GetFileAttributes("A:")
If lResult = -1 then
lResult2 = GetLastError
lblError.Caption = "error Number: " & lResult & ":" & lResult2
else
lblError.Caption = "No error"
End If
End Sub
I have no idea why it isn't working correctly... Maybe the GetlastError doesn't work correctly in VB?
Mark
-
May 17th, 2001, 08:13 AM
#6
Re: how to determine Diskette status?
You're right Mark. I've tried it too and for some reason GetLastError() keeps giving me 0 eventhough the previous API call failed. My workaround was to write a COM DLL to do the work.
-Cool Bizs
Good Luck,
-Cool Bizs
-
May 17th, 2001, 08:56 AM
#7
Re: how to determine Diskette status?
You can use the openfile API for this. If the API call return -1, there has been an error. The OFSTRUCT type can be used to retrieve the error number. This number is the DOS error code. I found out that code 23 means a bad crc, code 1005 means unrecognized file system.
private Declare Function OpenFile Lib "kernel32" (byval lpFileName as string, lpReOpenBuff as OFSTRUCT, byval wStyle as Long) as Long
private Declare Function CloseHandle Lib "kernel32" (byval hObject as Long) as Long
private Type OFSTRUCT
cBytes as Byte
fFixedDisk as Byte
nErrCode as Integer
Reserved1 as Integer
Reserved2 as Integer
szPathName(255) as Byte
End Type
private Sub Command1_Click()
Dim lResult as Long, lResult2 as Long
Dim r as Long, BytesFreeToCalller as Currency, TotalBytes as Currency
Dim F as Long
Dim os as OFSTRUCT
F = OpenFile("A:", os, 0)
If F <> -1 then
' all went well
else
' we had an error
lblError.Caption = "error Number: " & F & ":" & os.nErrCode
End If
' close the handle, to avoid conflicts
CloseHandle F
End Sub
Tom Cannaerts
[email protected]
Programming today is a race between software engineers striving to build bigger and better idot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook
-
May 18th, 2001, 05:11 AM
#8
Re: how to determine Diskette status?
Instead of using GetLastError ( VB seems to be clearing this before I am able to excute it ) use Err.LastDllError When using this it appears to be returning the correct results. Thanks a lot for your help
Mark
-
May 18th, 2001, 05:21 AM
#9
Re: how to determine Diskette status?
Funny, we're stuck in APIs up to our necks, and the answer is that simple. Well, i'm glad we sorted thisone out 
Tom Cannaerts
[email protected]
Programming today is a race between software engineers striving to build bigger and better idot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|