Results 1 to 3 of 3

Thread: GetVolumeInformation & GetLastError

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2002
    Location
    UK
    Posts
    506

    GetVolumeInformation & GetLastError

    If i use GetVolumeInformation on a CD drive with no disc in the drive it returns 0, if I then go on to use GetLastError that also returns 0 - shouldn't it be returning some nice error code for me? or do I presume that if the result of GetVolumeInformation is 0 then there is no disc in the drive?

    Heres a snippet of the code I'm using, I may be using GetLastError wrong as I've never used it before.

    VB Code:
    1. If GetVolumeInformation(sDrives(l), sLabel, 255, lSerial, 0, 0, sFilesystem, 255) = 0 Then
    2.         'Error when retrieving volume information, probably no disc in drive
    3.         MsgBox GetLastError
    4.        
    5.         Dim sError As String * 255
    6.        
    7.         FormatMessage FORMAT_MESSAGE_FROM_SYSTEM, ByVal 0&, GetLastError, LANG_NEUTRAL, sError, 255, ByVal 0&
    8.        
    9.         MsgBox sError
    10.       End If

    Help appreciated.

  2. #2

  3. #3
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758
    You can't use GetLastError with VB. VB does some processing behind the scenes when you call an API function. Basically, one or more additional API functions are called after the one you specified. Since the last error is only available after each API call the value you want is gone.

    Fortunately VB stores the return value of the API in the error object. Use Err.LastDLLError instead.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width