Announcement

Collapse
No announcement yet.

GetVolumeInformation

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • GetVolumeInformation

    I have had an application which reads volume information for some time now, but recently, after reorganizing things around different partitions, I have run into a problem.

    I can't get volume information from the drive which the PB app executes from. I don't know if this problem is new to PB6, or if I just never happened to get info on the current drive before.

    Is there a reason the execution drive would be locked out? If I move the dll to a different drive it works fine (except for that drive of course).
    Thanks,

    John Kovacich
    Ivory Tower Software

  • #2
    Sounds very strange. Can you post the separate fragment, which not works ?

    ------------------

    Comment


    • #3
      There is no reason that an API call should *ever* work differently from one version of the "compiler" to another. Although, things can work different from one version of the "operating system" to another.

      Without any sample code to review, attempting to help you would be akin to a doctor providing a diagnosis without ever seeing a patient. And I'm not covered for malpractice.

      --Dave


      ------------------
      PowerBASIC Support
      mailto:[email protected][email protected]</A>
      Home of the BASIC Gurus
      www.basicguru.com

      Comment


      • #4
        Here you go. Just standard stuff. I wouldn't even have questioned the version issue, except that the PB IDE is similarly sensitive to which drive you are executing from, and which drive you compile to.

        SUB GetVolumeInfo ALIAS "GetVolumeInfo" (BYVAL lroot AS STRING, BYREF lvolume AS STRING, BYREF lvolserial AS LONG, BYREF lmaxlen AS LONG, lfileflags AS LONG, BYREF lfilesysname AS STRING) EXPORT
        DIM lvolumebuffer AS LONG, lfilenamebuff AS LONG
        DIM returnval AS LONG
        'Declare Function GetVolumeInformation Lib "kernel32" Alias "GetVolumeInformationA" (ByVal lpRootPathName As String, ByVal lpVolumeNameBuffer As String, ByVal nVolumeNameSize As Long, lpVolumeSerialNumber As Long, lpMaximumComponentLength As Long, _
        'lpFileSystemFlags AS LONG, BYVAL lpFileSystemNameBuffer AS STRING, BYVAL nFileSystemNameSize AS LONG) AS LONG

        lvolumebuffer = 255
        lvolume = SPACE$(lvolumebuffer)
        lfilenamebuff = 255
        lfilesysname = SPACE$(lfilenamebuff)

        ON ERROR RESUME NEXT

        returnval = GetVolumeInformation(lroot, lvolume, lvolumebuffer, lvolserial, lmaxlen, lfileflags, lfilesysname, lfilenamebuff)
        ' CALL GetVolumeInformation(sDrv & ":\", str, 256, RetVal,a, b, str2, 256)

        IF returnval = 0 THEN
        MSGBOX "Allocation Error on " & lroot & " - " & TRIM$(lvolume) & " - " & TRIM$(lfilesysname)
        ELSE
        ' lvolume = stripterminator(lvolume)
        ' lfilesysname = stripterminator(lfilesysname)
        ' print "Volume Name: "; lvolume
        ' print "Serial Number: "; lvolserial
        ' print "Max name length: "; lmaxlen
        ' print "File System: "; lfilesysname
        END IF

        END SUB

        ------------------
        Thanks,

        John Kovacich
        Ivory Tower Software

        Comment


        • #5
          I tried following.
          Code:
          #Compile Exe
          #Register None
          #Dim All
          #Include "Win32Api.Inc"
          '================================
          Sub CPrint (SOut As String)
             Static hConsole As Long, cWritten As Long
             If hConsole = 0 Then AllocConsole: hConsole = GetStdHandle(-11&)
             WriteConsole hConsole, ByCopy sOut + $CrLf, Len(sOut) + 2, cWritten, ByVal 0&
          End Sub
          '===============================
          CallBack Function CB_Dlg
             If CbMsg = %WM_COMMAND Then CPrint "CbCtl = " + Str$(CbCtl) + " " + Time$
          End Function
          Function PbMain
             Dim lpRootPathName As Asciiz * 4
             lpRootPathName = "C:\"
             Dim lpVolumeNameBuffer As Asciiz * 12
             Dim lpVolumeSerialNumber As Long
             Dim lpMaximumComponentLength As Long
             Dim lpFileSystemFlags As Long
             Dim lpFileSystemNameBuffer As Asciiz * 10
              
             If GetVolumeInformation(lpRootPathName, _
                                     lpVolumeNameBuffer, SizeOf(lpVolumeNameBuffer) - 1, _
                                     lpVolumeSerialNumber, _
                                     lpMaximumComponentLength, _
                                     lpFileSystemFlags, _
                                     lpFileSystemNameBuffer, SizeOf(lpFileSystemNameBuffer) - 1) = 0 Then
                CPrint "Allocation Error"
             Else
                CPrint "File System: "     + lpFileSystemNameBuffer
                CPrint "Max name length: " + Str$(lpMaximumComponentLength)
                CPrint "Volume Name: "     + lpVolumeNameBuffer
                CPrint "Serial Number:"    + Hex$(lpVolumeSerialNumber)
                CPrint "System Flags: "    + Hex$(lpFileSystemFlags)
             End If
             Sleep 3000
          End Function
          All works.
          John --
          perhaps, you specify "C:" instead of "C:\" ?

          ------------------

          Comment


          • #6
            Yup!

            And only the current process has a default directory other than root, so all other drives worked, and only the current one failed.

            Case closed.

            ------------------
            Thanks,

            John Kovacich
            Ivory Tower Software

            Comment

            Working...
            X
            😀
            🥰
            🤢
            😎
            😡
            👍
            👎