Announcement

Collapse
No announcement yet.

Exceptional Error while using Disksize or Diskfree

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

  • Exceptional Error while using Disksize or Diskfree

    Hallo,

    if I use Disksize("a") or Diskfree("a") and no Disk is in the player then

    You get an exeptional error from Windows( XP, Vista ).

    Now I kill a dummy file : Kill "A:\test.txt" and then I get the right intern error
    return number 71: no Disk or Disk not readable.

    Please do I on Your update list => to Powerbasic support !

    Best Regards

    Matthias Kuhn

  • #2
    Seems OK here:
    Code:
     
    Function PbMain()
     Local DiskBytes As QUAD
     
      DiskBytes = DISKSIZE("a")
      MsgBox "> Size of disk "+ FORMAT$(DiskBytes, "#,###")
      DiskBytes = DISKFREE("a")
      MsgBox "> Free bytes " + FORMAT$(DiskBytes, "#,###")
     
    End Function
    '------------------/PBMain
    ' 
    '  Disk In:
    '> Size of disk 1,457,664
    '> Free bytes 44,544
    '(Same figures as Windows Explorer reports)
    ' 
    '  No Disk:
    '> Size of disk 0
    '> Free bytes 0
    '(No errors)
    WinXP Home, PBWin804
    Rgds, Dave

    Comment


    • #3
      PB.WIn 8.03...+ Windows/XP Pro SP2 all updates...

      With no disk in 'A' both DISKSIZE () and DISKFREE() give me a Windows Exception message box with caption "Windows - No Disk" with button options to Cancel, try again, or continue.

      I think that's a bug in the compiler. IMO these functions should return with ERR set without a system-generated message box.

      If that's happening in the latest compiler someone should send in that as a bug report.

      In the meantime, there must be a workaround, maybe calling FindFirstFile or DIR$ first and if that does not return a 'no disk' error, THEN calling DISKSIZE() or DISKFREE.

      GetDriveType looks promising, let me try that...nah, that just returns the drive type.

      HowAbout DIR$? No, that just returns a null string with no Error, which is what you'd get if there was an empty disk.

      Well, I'm sure someone will figure out a workaround.

      MCM
      Michael Mattias
      Tal Systems (retired)
      Port Washington WI USA
      [email protected]
      http://www.talsystems.com

      Comment


      • #4
        Originally posted by Michael Mattias View Post
        With no disk in 'A' both DISKSIZE () and DISKFREE() give me a Windows Exception message box with caption "Windows - No Disk" with button options to Cancel, try again, or continue.
        Yes, at least Windows XP gives us such a meaningful message.

        Look what Windows 2000 says:



        Ugly, isn't it?

        Windows 98 says
        Size of disk: 0
        Free bytes: 0
        Without any "blue screen", what I was expecting.

        Seems to be a Windows issue.

        Regards
        Albert
        „Let the machine do the dirty work.“
        The Elements of Programming Style, Brian W. Kernighan, P. J. Plauger 1978

        Comment


        • #5
          >Seems to be a Windows issue

          No, it isn't a Windows' issue... at least for you and me it isn't.

          DISKFREE and DISKSPACE are PowerBASIC functions, therefore PowerBASIC Inc. is responsible for their behavior.

          If PowerBASIC chooses to implement DISKFREE and DISKSPACE using various Windows' API functions, then PowerBASIC Inc. is responsible for handling any variations in the Windows' behavior for any platform their compiler product is designed to support.

          The reason we use a high-level language compiler is so that the compiler can handle this kind of stuff and we don't have to.

          MCM

          PS: BTW, your Win/2000 message is the same one I get on XP... I think. I don't speak German, but that's the same screen with the same three buttons I get on Windows/XP.
          Last edited by Michael Mattias; 18 Feb 2008, 12:43 PM.
          Michael Mattias
          Tal Systems (retired)
          Port Washington WI USA
          [email protected]
          http://www.talsystems.com

          Comment


          • #6
            truly is it Windows behavior

            Windows will handle this exception by default itself

            You can change this with API SetErrorMode()

            e.g.
            dwOld = SetErrorMode(%SEM_FAILCRITICALERRORS OR _
            %SEM_NOOPENFILEERRORBOX)
            DiskChange(..)
            SetErrorMode(dwOld)

            this is a process wide switch

            use it with caution while running more than one thread

            -Uwe

            Comment


            • #7
              Code:
                  dwOld = SetErrorMode(%SEM_FAILCRITICALERRORS OR _
              %SEM_NOOPENFILEERRORBOX)
              GREAT TIP!!!

              Gets rid of the Windows' message box and allows program to continue.

              MCM
              Michael Mattias
              Tal Systems (retired)
              Port Washington WI USA
              [email protected]
              http://www.talsystems.com

              Comment


              • #8
                Originally posted by Michael Mattias View Post
                BTW, your Win/2000 message is the same one I get on XP... I think. I don't speak German, but that's the same screen with the same three buttons I get on Windows/XP.
                Not quite. The XP error message is much more decent in telling us:



                Translation:
                There is no media in the drive. Please insert media into drive A:
                [Abort] [Retry] [Ignore]

                Originally posted by Uwe Heyer View Post
                truly is it Windows behavior
                Windows will handle this exception by default itself
                You can change this with API SetErrorMode()
                Right. IMO it is not the compiler's responsibility to (temporarily) change the OS' critical error handling in order to create a consistent behaviour accross the platforms.

                Regards
                Albert
                „Let the machine do the dirty work.“
                The Elements of Programming Style, Brian W. Kernighan, P. J. Plauger 1978

                Comment


                • #9
                  IMO it is not the compiler's responsibility to (temporarily) change the OS' critical error handling in order to create a consistent behaviour accross the platforms
                  Well, I guess that makes for two opinions on the subject.

                  e.g, would you like it if OPEN or ARRAY SORT or CONTROL ADD worked differently on different operating systems? I'll bet you would not like that at all.

                  So why should DISKFREE and DISKSPACE be allowed to vary their behavior depending on operating system?

                  MCM
                  Michael Mattias
                  Tal Systems (retired)
                  Port Washington WI USA
                  [email protected]
                  http://www.talsystems.com

                  Comment


                  • #10
                    Or better still....

                    Why should DISKFREE and DISKSPACE be allowed to vary their behavior depending on operating system without the help file documenting this behavior and suggesting a workaround?

                    MCM
                    Michael Mattias
                    Tal Systems (retired)
                    Port Washington WI USA
                    [email protected]
                    http://www.talsystems.com

                    Comment


                    • #11
                      Michael,

                      >> Why should DISKFREE and DISKSPACE be allowed to vary their behavior depending on operating system <<

                      why don't you ask why Windows is allowed to vary this behavior ?

                      >> without the help file documenting this behavior and suggesting a workaround? <<

                      but it is documented by MS

                      http://msdn2.microsoft.com/en-us/lib...48(VS.85).aspx

                      and when a compiler will handle all possible occurrences, who need a talented programmer anymore.

                      Greetings
                      -Uwe

                      Comment


                      • #12
                        Originally posted by Michael Mattias View Post
                        e.g, would you like it if OPEN or ARRAY SORT or CONTROL ADD worked differently on different operating systems? I'll bet you would not like that at all.
                        ARRAY SORT and CONTROL ADD for me have something in common - both don't communicate with external devices, something that OPEN and DISKFREE and DISKSPACE as opposed to indeed do.

                        I was taught at the real beginning of my programming career (1970/71) that I cannot assume that anything external - outside of the computer's (core) memory - might be available. So all typical file or disk operations need special care in terms of error handling.

                        So I am quite happy with the fact that PowerBASIC isn't providing me with bicycle training wheels. If this makes up two different opinions I can live with it.

                        Cheers
                        Albert
                        „Let the machine do the dirty work.“
                        The Elements of Programming Style, Brian W. Kernighan, P. J. Plauger 1978

                        Comment


                        • #13
                          Works here PB/Win 8.03:
                          Code:
                          #INCLUDE "WIN32API.INC"
                          FUNCTION PBMAIN () AS LONG
                              
                              CALL TestDiskMacro ()
                              
                          END FUNCTION
                          
                          
                          MACRO FUNCTION CallIt (fn, dr)
                            MACROTEMP oldMOde, dSize
                            DIM OldMOde AS LONG, dsize AS QUAD
                          
                            oldMOde = SetErrorMode (%SEM_FAILCRITICALERRORS OR %SEM_NOOPENFILEERRORBOX)
                          
                            dSize   =  fn (dr)
                          
                            SetErrorMode OldMOde
                          
                          END MACRO = dsize
                          
                          
                          FUNCTION TestDiskMacro () AS LONG
                          
                               LOCAL dFree AS QUAD, dSize AS QUAD
                          
                               dFree = Callit (DISKFREE, "A")  ' works with "A" or "C"
                               
                               dsize = Callit (DISKSIZE, "A")
                               
                               
                               MSGBOX USING$ ("Size #   Free #", dSize, dFree)
                               
                               
                              
                          END FUNCTION

                          MCM
                          Last edited by Michael Mattias; 21 Feb 2008, 08:49 AM.
                          Michael Mattias
                          Tal Systems (retired)
                          Port Washington WI USA
                          [email protected]
                          http://www.talsystems.com

                          Comment


                          • #14
                            Got the same error here using a german W2KPro SP4 and all patches applied. Compiler used: PB/CC 4.04. Both attempts throw an exeption messagebox.

                            Code:
                            Function PBMain()
                            Local DiskBytes As Quad
                             
                            ' First approach using Try/EndTry
                            Try
                               DiskBytes = DiskSize("a")
                            Catch
                               StdOut "Drive error or no disk in drive."
                            Finally
                               StdOut "> Size of disk "+ Format$(DiskBytes, "#,###")
                            End Try
                            
                            Try
                               DiskBytes = DiskFree("a")
                            Catch
                               StdOut "Drive error or no disk in drive."
                            Finally
                               StdOut "> Free bytes " + Format$(DiskBytes, "#,###") 
                            End Try
                            
                             
                            ' Second approach using on error
                            On Error GoTo ErrHandler
                            
                            DiskBytes = DiskSize("a")
                            StdOut "> Size of disk "+ Format$(DiskBytes, "#,###")
                            
                            DiskBytes = DiskFree("a")
                            StdOut "> Free bytes " + Format$(DiskBytes, "#,###") 
                            
                            Exit Function
                            
                            ErrHandler:
                               StdOut "Drive error or no disk in drive."
                               ErrClear
                               Resume Next
                            
                            End Function
                            '------------------/PBMain
                            The output is
                            Code:
                            > Size of disk 0
                            > Free bytes 0
                            > Size of disk 0
                            > Free bytes 0
                            The helpfile notes under "Disk errors"
                            Disk and I/O errors are always trapped at run-time by PowerBASIC. If a run-time Disk or I/O error is detected, the error code is placed in the ERR system variable. If ON ERROR is enabled, code execution will branch to the designated local error handler.
                            The help file for #DEBUG ERROR states that...
                            Disk I/O errors are always caught, regardless of the state of #DEBUG ERROR.
                            I nonetheless thought I give it a try, but the exception still shows up.

                            Comment


                            • #15
                              More DiskFree Woes

                              I have a PB Windows 7.04 application which is in use by a number of clients and one client has two PC's one a Dell XPS-Z running Windows 2000 and the other is a Channel Partner Solutions 510D which I think is a "white box" Dell and is running Windows XP. The Windows 2000 PC consistently reports zero Disk Freespace using the PB DISKFREE function. I made a small test program for him which used both the PB DISKFREE function and the GetDiskFreeSpaceEx API function and the PB DISKFREE function always gave a zero but the GetDiskFreeSpaceEx always gave the correct answer.

                              The following test program shows that I was using a register variable as the reference folder (not the one I was really using) but I don't think that should have been a problem. Any ideas? In the meantime I will steer clear of the PB DISKFREE function.

                              Code:
                              #COMPILE EXE
                              #DIM ALL
                              
                              #INCLUDE "Win32Api.INC"
                              
                              $RegisterString1 = "Software\Microsoft\Windows\CurrentVersion\Run"
                              $RegisterString2 = "Default"
                              
                              '_____________________________________________________________
                              FUNCTION GetReg(BYVAL hLocation AS DWORD, _
                                              BYVAL sSubKeys AS STRING, _
                                              BYVAL sValueName AS STRING, _
                                              BYVAL sDefault AS STRING) AS STRING
                               
                                LOCAL hKey AS DWORD, zRegVal AS ASCIIZ * 1024
                               
                                zRegVal = sDefault
                                IF (RegOpenKeyEx(hLocation, TRIM$(sSubKeys, "\"), 0, %KEY_READ, hKey) = %ERROR_SUCCESS) THEN
                                   CALL RegQueryValueEx(hKey, BYCOPY sValueName, 0, _
                                                     %REG_SZ, zRegVal, SIZEOF(zRegVal))
                                   RegCloseKey hKey
                                END IF
                                FUNCTION = zRegVal
                               
                              END FUNCTION
                              '_____________________________________________________________
                              FUNCTION sSpecialFolder() AS STRING
                               
                                LOCAL sFolder AS STRING
                               
                                sFolder = GetReg(%HKEY_CURRENT_USER, $RegisterString1, $RegisterString2, "")
                               
                                IF TRIM$(sFolder) = "" THEN FUNCTION = "": EXIT FUNCTION
                               
                                IF RIGHT$(sFolder, 1) <> "\" THEN
                                  sFolder = sFolder & "\"
                                END IF
                               
                                FUNCTION = sFolder
                              
                              END FUNCTION 
                              '_____________________________________________________________
                              FUNCTION DiskFreeAPI (BYREF Dir AS ASCIIZ) AS QUAD  
                              
                                LOCAL lpFreeBytesAvailableToCaller AS QUAD, _
                                      lpTotalNumberOfBytes         AS QUAD, _
                                      lpTotalNumberOfFreeBytes     AS QUAD
                              
                                GetDiskFreeSpaceEx( _
                                                   Dir,_
                                                   BYVAL VARPTR(lpFreeBytesAvailableToCaller), _
                                                   BYVAL VARPTR(lpTotalNumberOfBytes), _
                                                   BYVAL VARPTR(lpTotalNumberOfFreeBytes)_
                                                  )
                                FUNCTION = lpFreeBytesAvailableToCaller
                                
                              END FUNCTION
                              '_____________________________________________________________
                              FUNCTION PBMAIN
                                
                                LOCAL Free1 AS SINGLE, Free2 AS SINGLE
                                
                                Free1 = DISKFREE   (sSpecialFolder)/2^20
                                Free2 = DiskFreeAPI(sSpecialFolder)/2^20
                              
                                MSGBOX "PB  Disk Free = " & $TAB & FORMAT$(Free1, "#,###.0") & " MB" & $CRLF & _
                                       "API Disk Free = " & $TAB & FORMAT$(Free2, "#,###.0") & " MB" & $CRLF, &h51000, "Disk Free0092t"
                              
                              END FUNCTION
                              '_____________________________________________________________
                              Last edited by Bob Scott; 19 Apr 2008, 12:35 PM.

                              Comment


                              • #16
                                Code:
                                  Free1 = DISKFREE   (sSpecialFolder)/2^20
                                DISKFREE wants a DRIVE not a DIRECTORY.

                                At least it does in my help file.
                                Michael Mattias
                                Tal Systems (retired)
                                Port Washington WI USA
                                [email protected]
                                http://www.talsystems.com

                                Comment


                                • #17
                                  Michael,

                                  That is indeed a possiblity and I have a test program version which includes just the drive waiting for the client to test it. However, since I see no problem with Windows XP then maybe it's a function of Windows 2000 but I would suspect that PB DISKFREE is based upon GetDiskFreeSpaceEx which allows for a directory name.

                                  Maybe someone who is running Windows 2000 could run the test file from the link and report the results:

                                  Link: http://www.box.net/shared/8qd9p6akg0

                                  ~Bob

                                  Comment


                                  • #18
                                    Originally posted by Bob Scott View Post
                                    Maybe someone who is running Windows 2000 could run the test file from the link and report the results:
                                    Run on Windows 2000 SP4, home dir is a remote server drive (1TB):



                                    No run time exceptions occurred.

                                    Regards
                                    Albert
                                    „Let the machine do the dirty work.“
                                    The Elements of Programming Style, Brian W. Kernighan, P. J. Plauger 1978

                                    Comment


                                    • #19
                                      Albert,

                                      Thank you very much for testing.

                                      I wrote a little program which can obtain Disk Freespace information from any desired registry item using both the DDT DISKFREE and the API GetDiskFreeSpaceEx and gets Disk Freespace using the entire Registry data and also just the drive portion. It appears that using the entire Registry data works *some* of the time but as Michael pointed out the drive is what is required. Interestingly enough although the help for the GetDiskFreeSpaceEx leads one to believe that a folder (directory) might be used it also only really works for drives. The difference between the DDT DISKFREE and the API GetDiskFreeSpaceEx is that the GetDiskFreeSpaceEx requires the colon after the drive letter and the DDT DISKFREE does not.

                                      Code:
                                      #PBFORMS CREATED
                                      #COMPILE EXE
                                      #DIM ALL
                                       
                                      '_____________________________________________________________
                                      '   ** Includes **
                                      '_____________________________________________________________
                                      #PBFORMS BEGIN INCLUDES
                                      #IF NOT %DEF(%WINAPI)
                                        #INCLUDE "WIN32API.INC"
                                      #ENDIF
                                      #INCLUDE "PBForms.INC"
                                      #PBFORMS END INCLUDES
                                      '_____________________________________________________________
                                       
                                      '_____________________________________________________________
                                      '   ** Constants **
                                      '_____________________________________________________________
                                      #PBFORMS BEGIN CONSTANTS
                                      %IDD_DIALOG1            = 101
                                      %RegistryPart1Label     = 1001
                                      %RegistryPart1Text      = 1002
                                      %RegistryPart2Label     = 1003
                                      %RegistryPart2Text      = 1004
                                      %DiskFreeRegLabel       = 1005
                                      %DiskFreeRegText        = 1006
                                      %DiskFreeRegDriveLabel  = 1007
                                      %DiskFreeRegDriveText   = 1008
                                      %DiskFreeApiRegLabel    = 1009
                                      %DiskFreeApiRegText     = 1010
                                      %DiskFreeApiDriveLabel  = 1011
                                      %DiskFreeApiDriveText   = 10s.st%GetFreespaceButton     = 1013
                                      %RegistryDataLabel      = 1014
                                      %RegistryDataText       = 1015
                                      %Option_Does_Work       = 1016
                                      %Option_Does_Not_Work   = 1017
                                      #PBFORMS END CONSTANTS
                                      '_____________________________________________________________
                                       
                                      $DoesNotWorkPart1 = "Software\Microsoft\Internet Explorer\Main"
                                      $DoesNotWorkPart2 = "Local Page"
                                       
                                      $DoesWorkPart1    = "Software\Microsoft\Internet Explorer\Main"
                                      $DoesWorkPart2    = "Save Directory"
                                       
                                      '_____________________________________________________________
                                      '   ** Declarations **
                                      '_____________________________________________________________
                                      DECLARE CALLBACK FUNCTION ShowDIALOG1Proc()
                                      DECLARE FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
                                      #PBFORMS DECLARATIONS
                                      '_____________________________________________________________
                                       
                                      '_____________________________________________________________
                                      FUNCTION GetReg(BYVAL hLocation AS DWORD, _
                                                      BYVAL sSubKeys AS STRING, _
                                                      BYVAL sValueName AS STRING, _
                                                      BYVAL sDefault AS STRING) AS STRING
                                       
                                        LOCAL hKey AS DWORD, zRegVal AS ASCIIZ * 1024
                                       
                                        zRegVal = sDefault
                                        IF (RegOpenKeyEx(hLocation, TRIM$(sSubKeys, "\"), 0, %KEY_READ, hKey) = %ERROR_SUCCESS) THEN
                                           CALL RegQueryValueEx(hKey, BYCOPY sValueName, 0, _
                                                             %REG_SZ, zRegVal, SIZEOF(zRegVal))
                                           RegCloseKey hKey
                                        END IF
                                        FUNCTION = zRegVal
                                       
                                      END FUNCTION
                                      '_____________________________________________________________
                                      FUNCTION SpecialFolder(hDlg AS DWORD) AS STRING
                                       
                                        LOCAL sFolder AS STRING, RegisteryString1 AS STRING, RegisteryString2 AS STRING
                                       
                                        CONTROL GET TEXT hDlg, %RegistryPart1Text TO RegisteryString1
                                        CONTROL GET TEXT hDlg, %RegistryPart2Text TO RegisteryString2
                                       
                                        sFolder = TRIM$(GetReg(%HKEY_CURRENT_USER, RegisteryString1, RegisteryString2, ""))
                                       
                                        FUNCTION = sFolder
                                       
                                      END FUNCTION
                                      '_____________________________________________________________
                                      FUNCTION DiskFreeAPI (BYREF Dir AS ASCIIZ) AS QUAD
                                       
                                        LOCAL lpFreeBytesAvailableToCaller AS QUAD, _
                                              lpTotalNumberOfBytes         AS QUAD, _
                                              lpTotalNumberOfFreeBytes     AS QUAD
                                       
                                        GetDiskFreeSpaceEx( _
                                                           Dir,_
                                                           BYVAL VARPTR(lpFreeBytesAvailableToCaller), _
                                                           BYVAL VARPTR(lpTotalNumberOfBytes), _
                                                           BYVAL VARPTR(lpTotalNumberOfFreeBytes)_
                                                          )
                                        FUNCTION = lpFreeBytesAvailableToCaller
                                       
                                      END FUNCTION
                                      '_____________________________________________________________
                                      SUB UpdateFreespace(hDlg AS DWORD)
                                       
                                        LOCAL Free1 AS QUAD, Free2 AS QUAD, Free3 AS QUAD, Free4 AS QUAD
                                        LOCAL sSpecialFolder AS STRING, Drive AS STRING
                                       
                                        sSpecialFolder = SpecialFolder(hDlg)
                                        Drive   = LEFT$(sSpecialFolder, 1)        ' Drive does not need a colon
                                       
                                        Free1 = DISKFREE   (sSpecialFolder)
                                        Free2 = DISKFREE   (Drive)
                                       
                                        Free3 = DiskFreeAPI(BYCOPY sSpecialFolder)
                                        Free4 = DiskFreeAPI(BYCOPY Drive & ":")   ' Drive needs a colon
                                       
                                        CONTROL SET TEXT hDlg, %RegistryDataText, sSpecialFolder
                                       
                                        CONTROL SET TEXT hDlg, %DiskFreeRegText,      FORMAT$(Free1, "#,###")
                                        CONTROL SET TEXT hDlg, %DiskFreeRegDriveText, FORMAT$(Free2, "#,###")
                                       
                                        CONTROL SET TEXT hDlg, %DiskFreeApiRegText,   FORMAT$(Free3, "#,###")
                                        CONTROL SET TEXT hDlg, %DiskFreeApiDriveText, FORMAT$(Free4, "#,###")
                                       
                                      END SUB
                                      '_____________________________________________________________
                                      FUNCTION PBMAIN()
                                        ShowDIALOG1 %HWND_DESKTOP
                                      END FUNCTION
                                      '____________________________________________________________
                                       
                                      '____________________________________________________________
                                      '   ** CallBacks **
                                      '____________________________________________________________
                                      CALLBACK FUNCTION ShowDIALOG1Proc()
                                       
                                        SELECT CASE CBMSG
                                          CASE %WM_INITDIALOG
                                            CONTROL SET CHECK CBHNDL,%Option_Does_Not_Work, 1
                                            CONTROL SET TEXT  CBHNDL, %RegistryPart1Text, $DoesNotWorkPart1
                                            CONTROL SET TEXT  CBHNDL, %RegistryPart2Text, $DoesNotWorkPart2
                                            UpdateFreespace  (CBHNDL)
                                       
                                          CASE %WM_COMMAND
                                            SELECT CASE CBCTL
                                              CASE %DiskFreeRegText
                                              CASE %DiskFreeApiRegText
                                       
                                              CASE %DiskFreeRegDriveText
                                              CASE %DiskFreeApiDriveText
                                       
                                              CASE %GetFreespaceButton
                                                IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
                                                    CONTROL SET CHECK CBHNDL, %Option_Does_Work, 0
                                                    CONTROL SET CHECK CBHNDL, %Option_Does_Not_Work, 0
                                                    UpdateFreespace(CBHNDL)
                                                END IF
                                       
                                              CASE %Option_Does_Work
                                                IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
                                                    CONTROL SET CHECK CBHNDL, %Option_Does_Not_Work, 0
                                                    CONTROL SET TEXT  CBHNDL, %RegistryPart1Text, $DoesWorkPart1
                                                    CONTROL SET TEXT  CBHNDL, %RegistryPart2Text, $DoesWorkPart2
                                                    UpdateFreespace(CBHNDL)
                                                END IF
                                       
                                              CASE %Option_Does_Not_Work
                                                IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
                                                    CONTROL SET CHECK CBHNDL, %Option_Does_Work, 0
                                                    CONTROL SET TEXT  CBHNDL, %RegistryPart1Text, $DoesNotWorkPart1
                                                    CONTROL SET TEXT  CBHNDL, %RegistryPart2Text, $DoesNotWorkPart2
                                                    UpdateFreespace(CBHNDL)
                                                END IF
                                       
                                            END SELECT
                                        END SELECT
                                       
                                      END FUNCTION
                                      '____________________________________________________________
                                       
                                      '____________________________________________________________
                                      '   ** Dialogs **
                                      '____________________________________________________________
                                      FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
                                        LOCAL lRslt AS LONG
                                      #PBFORMS BEGIN DIALOG %IDD_DIALOG1->->
                                        LOCAL hDlg AS DWORD
                                        LOCAL hFont1 AS DWORD
                                       
                                       
                                       
                                        DIALOG NEW hParent, "Disk Free Test", 253, 75, 440, 149, _
                                          %WS_POPUP OR %WS_BORDER OR %WS_DLGFRAME OR %WS_SYSMENU _
                                          OR %WS_MINIMIZEBOX OR %WS_CLIPSIBLINGS OR %WS_VISIBLE _
                                          OR %DS_MODALFRAME OR %DS_3DLOOK OR %DS_NOFAILCREATE OR _
                                          %DS_SETFONT, %WS_EX_WINDOWEDGE OR %WS_EX_CONTROLPARENT _
                                          OR %WS_EX_LEFT OR %WS_EX_LTRREADING OR _
                                          %WS_EX_RIGHTSCROLLBAR, TO hDlg
                                        CONTROL ADD LABEL, hDlg, %RegistryPart1Label, "Registry " + _
                                          "Part 1", 10, 10, 280, 10, %WS_CHILD OR %WS_VISIBLE OR _
                                          %SS_CENTER, %WS_EX_LEFT OR %WS_EX_LTRREADING
                                        CONTROL ADD TEXTBOX, hDlg, %RegistryPart1Text, _
                                          "", 10, 20, _
                                          280, 13, %WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP OR _
                                          %ES_CENTER OR %ES_AUTOHSCROLL, %WS_EX_CLIENTEDGE OR _
                                          %WS_EX_LEFT OR %WS_EX_LTRREADING OR _
                                          %WS_EX_RIGHTSCROLLBAR
                                        CONTROL ADD LABEL, hDlg, %RegistryPart2Label, "Registry " + _
                                          "Part 2", 300, 10, 130, 10, %WS_CHILD OR %WS_VISIBLE OR _
                                          %SS_CENTER, %WS_EX_LEFT OR %WS_EX_LTRREADING
                                        CONTROL ADD TEXTBOX, hDlg, %RegistryPart2Text, "", _
                                          300, 20, 130, 13, %WS_CHILD OR %WS_VISIBLE OR _
                                          %WS_TABSTOP OR %ES_CENTER OR %ES_AUTOHSCROLL, _
                                          %WS_EX_CLIENTEDGE OR %WS_EX_LEFT OR %WS_EX_LTRREADING _
                                          OR %WS_EX_RIGHTSCROLLBAR
                                       
                                        CONTROL ADD LABEL, hDlg, %RegistryDataLabel, "Registry " + _
                                          "Data", 10, 40, 420, 10, %WS_CHILD OR %WS_VISIBLE OR _
                                          %SS_CENTER, %WS_EX_LEFT OR %WS_EX_LTRREADING
                                        CONTROL ADD TEXTBOX, hDlg, %RegistryDataText, "", 10, 50, _
                                          425, 13, %WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP OR _
                                          %ES_CENTER OR %ES_AUTOHSCROLL, %WS_EX_CLIENTEDGE OR _
                                          %WS_EX_LEFT OR %WS_EX_LTRREADING OR _
                                          %WS_EX_RIGHTSCROLLBAR
                                       
                                        CONTROL ADD LABEL, hDlg, %DiskFreeRegLabel, "DDT DISKFREE " + _
                                          "Freespace (Reg)", 10, 75, 150, 10, %WS_CHILD OR _
                                          %WS_VISIBLE OR %SS_CENTER, %WS_EX_LEFT OR _
                                          %WS_EX_LTRREADING
                                        CONTROL ADD TEXTBOX, hDlg, %DiskFreeRegText, "", 10, 85, _
                                          140, 13, %WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP OR _
                                          %ES_CENTER OR %ES_AUTOHSCROLL, %WS_EX_CLIENTEDGE OR _
                                          %WS_EX_LEFT OR %WS_EX_LTRREADING OR _
                                          %WS_EX_RIGHTSCROLLBAR
                                        CONTROL ADD LABEL, hDlg, %DiskFreeRegDriveLabel, "DDT " + _
                                          "DISKFREE Freespace (Drive)", 10, 110, 155, 10, _
                                          %WS_CHILD OR %WS_VISIBLE OR %SS_CENTER, %WS_EX_LEFT OR _
                                          %WS_EX_LTRREADING
                                        CONTROL ADD TEXTBOX, hDlg, %DiskFreeRegDriveText, "", 10, _
                                          120, 145, 13, %WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP _
                                          OR %ES_CENTER OR %ES_AUTOHSCROLL, %WS_EX_CLIENTEDGE OR _
                                          %WS_EX_LEFT OR %WS_EX_LTRREADING OR _
                                          %WS_EX_RIGHTSCROLLBAR
                                        CONTROL ADD LABEL, hDlg, %DiskFreeApiRegLabel, _
                                          "DiskFreeApi Freespace (Reg)", 170, 75, 140, 10, _
                                          %WS_CHILD OR %WS_VISIBLE OR %SS_CENTER, %WS_EX_LEFT OR _
                                          %WS_EX_LTRREADING
                                        CONTROL ADD TEXTBOX, hDlg, %DiskFreeApiRegText, "", 170, _
                                          85, 130, 13, %WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP OR _
                                          %ES_CENTER OR %ES_AUTOHSCROLL, %WS_EX_CLIENTEDGE OR _
                                          %WS_EX_LEFT OR %WS_EX_LTRREADING OR _
                                          %WS_EX_RIGHTSCROLLBAR
                                        CONTROL ADD LABEL, hDlg, %DiskFreeApiDriveLabel, _
                                          "DiskFreeApi Freespace (Drive)", 175, 110, 130, 10, _
                                          %WS_CHILD OR %WS_VISIBLE OR %SS_CENTER, %WS_EX_LEFT OR _
                                          %WS_EX_LTRREADING
                                        CONTROL ADD TEXTBOX, hDlg, %DiskFreeApiDriveText, "", 175, _
                                          120, 130, 13, %WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP _
                                          OR %ES_CENTER OR %ES_AUTOHSCROLL, %WS_EX_CLIENTEDGE OR _
                                          %WS_EX_LEFT OR %WS_EX_LTRREADING OR _
                                          %WS_EX_RIGHTSCROLLBAR
                                       
                                        CONTROL ADD BUTTON, hDlg, %GetFreespaceButton, "User Entry Get " + _
                                          "Freespace", 320, 120, 120, 15
                                       
                                        CONTROL ADD OPTION, hDlg, %Option_Does_Work, "Registry " + _
                                          "Works", 315, 85, 80, 10
                                        CONTROL ADD OPTION, hDlg, %Option_Does_Not_Work, "Registry " + _
                                          "Does Not Work", 315, 100, 120, 10
                                       
                                        hFont1 = PBFormsMakeFont("MS Sans Serif", 8, 700, %FALSE, %FALSE, %FALSE, %ANSI_CHARSET)
                                       
                                        CONTROL SEND hDlg, %RegistryPart1Label, %WM_SETFONT, hFont1, 0
                                        CONTROL SEND hDlg, %RegistryPart1Text, %WM_SETFONT, hFont1, 0
                                        CONTROL SEND hDlg, %RegistryPart2Label, %WM_SETFONT, hFont1, 0
                                        CONTROL SEND hDlg, %RegistryPart2Text, %WM_SETFONT, hFont1, 0
                                        CONTROL SEND hDlg, %DiskFreeRegLabel, %WM_SETFONT, hFont1, 0
                                        CONTROL SEND hDlg, %DiskFreeRegText, %WM_SETFONT, hFont1, 0
                                        CONTROL SEND hDlg, %DiskFreeRegDriveLabel, %WM_SETFONT, hFont1, 0
                                        CONTROL SEND hDlg, %DiskFreeRegDriveText, %WM_SETFONT, hFont1, 0
                                        CONTROL SEND hDlg, %DiskFreeApiRegLabel, %WM_SETFONT, hFont1, 0
                                        CONTROL SEND hDlg, %DiskFreeApiRegText, %WM_SETFONT, hFont1, 0
                                        CONTROL SEND hDlg, %DiskFreeApiDriveLabel, %WM_SETFONT, hFont1, 0
                                        CONTROL SEND hDlg, %DiskFreeApiDriveText, %WM_SETFONT, hFont1, 0
                                        CONTROL SEND hDlg, %RegistryDataLabel, %WM_SETFONT, hFont1, 0
                                        CONTROL SEND hDlg, %RegistryDataText, %WM_SETFONT, hFont1, 0
                                        CONTROL SEND hDlg, %GetFreespaceButton, %WM_SETFONT, hFont1, 0
                                        CONTROL SEND hDlg, %Option_Does_Work, %WM_SETFONT, hFont1, 0
                                        CONTROL SEND hDlg, %Option_Does_Not_Work, %WM_SETFONT, hFont1, 0
                                       
                                      #PBFORMS END DIALOG
                                       
                                        DIALOG SHOW MODAL hDlg, CALL ShowDIALOG1Proc TO lRslt
                                       
                                        DeleteObject hFont1
                                       
                                        FUNCTION = lRslt
                                      END FUNCTION
                                      '____________________________________________________________

                                      Comment


                                      • #20
                                        I'm trying to figure out why you are using the registry at all.

                                        If you are trying to get the free space on the current drive, CURDIR$ returns that as the first character ("C", "E", "K") or two (":") or three ("\").

                                        So does GetCurrentDirectory Windows call.

                                        I suspect CURDIR$ ends up calling GetCurrentDirectory, and GetCurrentDirectory may in fact be reading the registry; regardless, using CURDIR$ or GetCurrentDirectory seems a lot "cleaner" than reading the registry yourself.
                                        Michael Mattias
                                        Tal Systems (retired)
                                        Port Washington WI USA
                                        [email protected]
                                        http://www.talsystems.com

                                        Comment

                                        Working...
                                        X