Announcement

Collapse

Maintenance

The forum could be offline for 30-60 minutes in the very near future for maintenance (said 3pm Pacific). I was behind on getting this notice. I do apologize.
See more
See less

PB/DLL 2.0 Debugging

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

  • PB/DLL 2.0 Debugging

    I am creating a 16 bit DLL using PB/DLL 2.0. This DLL will be
    called from VB 3.0 16 bit. I am receiving an error message when
    trying to compile the DLL for testing. I can compile the DLL for
    use with VB 3.0 and access the DLL and display the File Open Dialog.
    There is a bug that preventing diplay of files. I took most of this
    code from someones previous form post about a 32 bit File Open. I
    need to be able to debug this code to resolve the issue.

    Thanks for any help or suggestions.
    Spencer

    The following is the code:

    PowerBasic Code

    %DEBUG = 1 'set to 0 for no debugging

    $IF %DEBUG
    $DEBUG PBD ON
    $COMPILE DLL
    $INCLUDE "\pbdll60\winapi\WINAPI.INC"
    $INCLUDE "\PBDLL60\WINAPI\COMMDLG.INC"
    $INCLUDE "\PBDLL60\WINAPI\CTL3D.INC"
    DECLARE FUNCTION OpenFilesDialog(BYVAL hWnd AS LONG, _ ' parent window
    Caption AS ASCIIZ, _ ' caption
    Filespec AS ASCIIZ, _ ' filename (input/output)
    InitialDir AS ASCIIZ, _ ' start directory
    Filter AS ASCIIZ, _ ' filename filter
    DefExtension AS ASCIIZ, _ ' default extension
    Flags AS LONG) AS LONG ' flags

    SUB PBDebug () EXPORT
    OPTION EXPLICIT
    Dim returnvalue as long
    Dim sCaption as String
    DIM sFileName AS String
    DIM sPath AS String
    Dim sFilter as String
    Dim sDefExt as String
    DIM lStyle AS LONG
    sCaption = "File Open Dialog Test"
    sFileName = "*.*"
    sPath = CURDIR$
    sFilter = "All Files (*.*)|*.*|Text files (*.TXT, *.BAT)|*.TXT;*.BAT|"
    sDefExt = "*.txt"
    lStyle = %OFN_ALLOWMULTISELECT Or %OFN_FILEMUSTEXIST
    returnvalue = OpenFilesDialog(0, sCaption, sFileName, sPath, sFilter, sDefExt, lStyle)
    END SUB
    $ELSE
    $COMPILE DLL
    $INCLUDE "\pbdll60\winapi\WINAPI.INC"
    $INCLUDE "\PBDLL60\WINAPI\COMMDLG.INC"
    $INCLUDE "\PBDLL60\WINAPI\CTL3D.INC"
    DECLARE FUNCTION OpenFilesDialog(BYVAL hWnd AS LONG, _ ' parent window
    Caption AS ASCIIZ, _ ' caption
    Filespec AS ASCIIZ, _ ' filename (input/output)
    InitialDir AS ASCIIZ, _ ' start directory
    Filter AS ASCIIZ, _ ' filename filter
    DefExtension AS ASCIIZ, _ ' default extension
    Flags AS LONG) AS LONG ' flags

    $ENDIF

    '----------------------------------------------------------
    '- OpenFilesDialog
    '----------------------------------------------------------

    Function OpenFilesDialog( BYVAL hWnd AS LONG, _ ' parent window
    Caption AS ASCIIZ, _ ' caption
    Filespec AS ASCIIZ, _ ' filename (input/output)
    InitialDir AS ASCIIZ, _ ' start directory
    Filter AS ASCIIZ, _ ' filename filter
    DefExtension AS ASCIIZ, _ ' default extension
    Flags AS LONG) EXPORT AS LONG ' flags

    LOCAL sFile AS STRING
    LOCAL Ofn AS OPENFILENAME
    LOCAL zFileTitle AS ASCIIZ * 256
    LOCAL zFilter AS ASCIIZ * 256
    LOCAL zInitialDir AS ASCIIZ * 256
    LOCAL zTitle AS ASCIIZ * 256
    LOCAL zDefExt AS ASCIIZ * 10

    REPLACE "|" WITH CHR$(0) IN Filter

    IF LEN(InitialDir) = 0 THEN
    InitialDir = CURDIR$
    END IF

    zFilter = Filter + CHR$(0)
    zInitialDir = InitialDir + CHR$(0)

    sFile = STRING$(4096,0) 'PLENTY OF ROOM FOR MULTIPLE FILES
    MID$(sFile,1) = FileSpec

    zDefExt = DefExtension + CHR$(0)
    zTitle = Caption + CHR$(0)

    ofn.lStructSize = SIZEOF(ofn)
    ofn.hWndOwner = hWnd
    ofn.lpstrFilter = VARPTR(zFilter)
    ofn.nFilterIndex = 1
    ofn.lpstrFile = STRPTR(sFile)
    ofn.nMaxFile = LEN(sFile)
    ofn.lpstrFileTitle = VARPTR(zFileTitle)
    ofn.nMaxFileTitle = SIZEOF(zFileTitle)
    ofn.lpstrInitialDir = VARPTR(zInitialDir)
    IF LEN(zTitle) THEN
    ofn.lpstrTitle = VARPTR(zTitle)
    END IF
    ofn.Flags = Flags
    ofn.lpstrDefExt = VARPTR(zDefExt)

    FUNCTION = GetOpenFilename(ofn)

    Filespec = RTRIM$(sFile,CHR$(0))
    Flags = ofn.Flags

    END FUNCTION


    Visual Basic 3.0 Code
    Declare Function OpenFilesDialog Lib "jds.DLL" Alias "OpenFilesDialog" (ByVal hWnd As
    Long, ByVal Caption As String, ByVal Filespec As String, ByVal InitialDir As String, ByVal
    Filter As String, ByVal DefExtension As String, Flags As Long) As Long
    'File Open/Save Dialog Flags
    Global Const OFN_READONLY = &H1&
    Global Const OFN_OVERWRITEPROMPT = &H2&
    Global Const OFN_HIDEREADONLY = &H4&
    Global Const OFN_NOCHANGEDIR = &H8&
    Global Const OFN_SHOWHELP = &H10&
    Global Const OFN_NOVALIDATE = &H100&
    Global Const OFN_ALLOWMULTISELECT = &H200&
    Global Const OFN_EXTENSIONDIFFERENT = &H400&
    Global Const OFN_PATHMUSTEXIST = &H800&
    Global Const OFN_FILEMUSTEXIST = &H1000&
    Global Const OFN_CREATEPROMPT = &H2000&
    Global Const OFN_SHAREAWARE = &H4000&
    Global Const OFN_NOREADONLYRETURN = &H8000&
    Dim sCaption As String
    Dim sFileName As String
    Dim sPath As String
    Dim sFilter As String
    Dim sDefExt As String
    Dim lStyle As Long

    sCaption = "File Open Test..."
    sFileName = Space$(4096)
    sFileName = "*.*"
    sPath = CurDir$
    sFilter = "All Files (*.*)|*.*|Text files (*.TXT, *.BAT)|*.TXT;*.BAT|"
    sDefExt = "*.txt"
    lStyle = OFN_ALLOWMULTISELECT Or OFN_FILEMUSTEXIST

    If OpenFilesDialog(Me.hWnd, sCaption, sFileName, sPath, sFilter, sDefExt, lStyle) Then
    'Need to format sFileName
    MsgBox "Directory = " & sFileName
    Else
    MsgBox "No file(s) selected.", MB_OK, "Error"
    End If

  • #2
    You can't pass a dynamic string BYREF to a function expecting an BYREF ASCIIZ - the solution is to pass the strings BYCOPY instead.

    Alternatively, you could override the type-checking by passing address of the string's data BYVAL.

    Confused?

    Examine this simple psuedocode example:
    [code]
    DECLARE Afunction(MyData AS ASCIIZ) AS LONG
    ...
    DIM A$
    X& = Afunction(a$) ' wont work as string types incompatible - you can't pass a string handle to a function that expects the actual data address
    X& = Afunction(BYCOPY a$) ' works fine as the actual data contents of the string is copied to a new location and the address of this data is passed to the function.
    X& = Afunction(a$ + "") ' expressions are always translated to BYCOPY as there is no "address" for an expression, only the result
    X& = Afunction( (a$) ) ' works fine - the parenthesis force the paremeter to be evaluated as an expression (as above)
    X& = Afunction(BYVAL STRPTR(a$)) ' Works fine - we are passing the address of the strings' data to the function - overriding the type checking by using an explicit BYVAL override.

    ------------------
    Lance
    PowerBASIC Support
    mailto:[email protected][email protected]</A>
    Lance
    mailto:[email protected]

    Comment


    • #3
      Thanks Lance,

      Using the above code and taking your suggestion I replaced the
      following line:

      returnvalue = OpenFilesDialog(0, sCaption, sFileName, sPath, sFilter, sDefExt, lStyle)

      with:

      returnvalue = OpenFilesDialog(0, (sCaption), (sFileName), (sPath), (sFilter), (sDefExt), lStyle)

      and I am now able to debug the routine. My code is causing a GPF
      in PBDW right after I select a file and click on Ok. I wonder if
      it is because I am passing to OpenFilesDialog()ASCIIZ (I am using
      ASCIIZ because this DLL will be called from VB when complete)
      strings in the OFN UDT. I think that this might also be the reason
      why the Filter and the Default Extension seem to be ignored by
      this call.

      Thanks for any insight into this problem.
      Spencer



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

      Comment


      • #4
        The GPF problem and the filter being ignored problem is because I
        am passing ASCIIZ to the function. I am doing this because this dll
        is to be called by Visual Basic 3.0. For testing I changed the
        ASCIIZ data type in the prototype and the call to a string data type.
        Once I did this I was able to run the PB/DLL 2.0 debugger without
        a GPF. In addition the file open dialog box understood the filters
        and displayed the appropriate files.

        Now the challange is to figure out how to make this work with VB. I think
        that I will pass ASCIIZ to the function and then copy the strings
        to a string value.

        Any better ideas would be appreciated.
        Thanks...
        Spencer

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

        Comment

        Working...
        X