Announcement

Collapse
No announcement yet.

another (one-line) C translation request ...

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

  • another (one-line) C translation request ...

    is this correct? i'm getting an error when i try to access the elements
    of the ss_printinfo udt....

    Code:
    short callback ss_printfunc(hdc hdc, short dcommand, short npagenum, long lappdata, lpss_printinfo lpprintinfo);
    into :

    Code:
    function ss_printfunc%( byval hdc&, byval dcommand%, byval npagenum%, byval lappdata&, lpprintinfo as ss_printinfo)
    more details of my problem in the third party forum : http://www.powerbasic.com/support/pb...ad.php?t=25733



    ------------------
    bernard ertl
    Bernard Ertl
    InterPlan Systems

  • #2
    Bern,

    Where is your declare statement?????????????? Or did I miss
    something here????????

    Cheers,
    Cecil

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

    Comment


    • #3
      Hi Cecil, thanks for the reply.

      There is no declare statement. The Spread DLL has a print
      preview control which can optionally call a callback function
      "SS_PRINTFUNC%" which should draw the headers and footers for
      the output.

      I am defining the SS_PRINTFUNC% function and passing the CODEPTR
      to the DLL. The DLL then calls the function as needed when it
      prepares a page for output.

      The C function declaration which I posted above is the prototype
      for the function as listed in the Spread documentation. My
      translation (posted above) seems to work (ie. no run-time errors)
      as long as I do not try to access the members of the UDT
      (lpPrintInfo). When I try to access the UDT, I get illegal action
      errors.

      Does the CALLBACK keyword have any special significance for the C
      function declaration? It seems to me that something is not "jiving"
      with the passing of the UDT, but I can't see what it is....



      ------------------
      Bernard Ertl
      Bernard Ertl
      InterPlan Systems

      Comment


      • #4
        Bern, have you asked FarPoint?

        Apparently, they have a set of PowerBASIC headers all ready to be used, but you have to ask them directly.

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

        Comment


        • #5
          Hi Lance,

          Yes, I sent them an e-mail this morning. I asked them to
          verify the UDT structure and the parameter passing methods for
          the callback call.

          They are not up to speed yet on PowerBASIC, so I don't expect much
          help from from them in debugging this error.

          I was the one who pushed Farpoint into handling the PB translated
          header file. What I'm trying to do right now is unrelated to the
          header file (assuming that the UDT is correct).

          The Farpoint docs list a prototype for the callback function which
          needs to be created in the user's app (using PB in my case). Their
          prototype claims that their DLL will pass a pointer to the UDT as the
          last parameter. I've tried receiving this pointer three different ways:

          1) FUNCTION SS_PRINTFUNC%( ..., lpPrintInfo AS SS_PRINTINFO)

          2) FUNCTION SS_PRINTFUNC%( ..., BYVAL ptrPrintInfo AS SS_PRINTINFO PTR)

          3) FUNCTION SS_PRINTFUNC%( ..., BYVAL ptrPrintInfo AS DWORD)
          DIM lpPrintInfo AS SS_PRINTINFO PTR
          lpPrintInfo = ptrPrintInfo

          With all three attempts, I get the same result. Everything will work without
          errors until I try to access a member of the SS_PRINTINFO udt.

          Any ideas?



          ------------------
          Bernard Ertl
          Bernard Ertl
          InterPlan Systems

          Comment


          • #6
            Bern,
            Since you asked for ideas, I might take this approach.
            1. Since what is being returned is an address, accept it as a dword/long.
            2. Create a byte pointer and assign the returned address to it.
            3. Scan the returned address byte-by-byte for the length of the SS_PRINTINFO structure.
            4. Transfer the bytes to a string.
            5. Compare the contents with what you expect to receive.
            6. You can always LSET the string contents into a SS_PRINTINFO variable.

            Happy Debugging,

            [This message has been edited by Ian Cairns (edited May 29, 2001).]
            :) IRC :)

            Comment


            • #7
              Just a guess, but are you sure of the alignment that the UDT using? Could it be 8-byte alignment?

              Is a valid address for this UDT being received? Can you look at the 1st 4 or 8 bytes of the pointer target or does that trigger a GPF too?

              If so, then that suggests a parameter order problem, although that looks ok (CALLBACK=SDECL/STDCALL).

              Bizarre!



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

              Comment


              • #8
                Ian has a similar idea to me (we posted at approx the same time!) - look at the target and see if you can figure out the correct UDT format/alignment.

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

                Comment


                • #9
                  Ian, Lance, et al,

                  Thanks for the help. I did as you suggested and checked out what
                  was being received.

                  Apparantly, the DLL calls the callback function four times for every
                  page of output. One time each for each of the four commands:

                  1) Set header length
                  2) Set footer length
                  3) Draw header
                  4) Draw footer

                  When calling to set the header / footer length, the DLL is passing a
                  NULL pointer for the UDT. So, I've got it working now using the following:

                  Code:
                  FUNCTION SS_PRINTFUNC%( BYVAL hDC&, BYVAL dCommand%, BYVAL nPageNum%, BYVAL lAppData&, BYVAL addrPrintInfo AS DWORD)
                  
                  
                     LOCAL hCurrentDC&, CurrentRect AS RECT
                     LOCAL ptrPrintInfo AS SS_PRINTINFO PTR
                     LOCAL szTemp AS ASCIIZ * 260
                     DIM hSpreadFont AS LOCAL LONG    'or DWORD
                     DIM tFont       AS LOCAL LOGFONT 'Start with a stock font
                  
                  
                     IF addrPrintInfo > 0 THEN
                        ptrPrintInfo = addrPrintInfo
                        IF @ptrPrintInfo.fIsPreview <> 0 THEN
                           'Output is Preview Control
                           hCurrentDC& = hDC&
                           CurrentRect = @ptrPrintInfo.RectPreview
                           'Get Arial 10 pt
                           hSpreadFont = SSGetFont( @ptrPrintInfo.hWndSpread, 1, 1) 'Get Spread font handle
                           GetObject hSpreadFont, LEN(tFont), BYVAL VARPTR(tFont) 'Get Spread font info
                           tFont.lfHeight = -MulDiv( 10, GetDeviceCaps( hCurrentDC&, %LOGPIXELSY), 72)
                           hMyFont = CreateFontIndirect(tFont) 'Make copy of Spread font with my changes
                        ELSE
                           'Output is Printer Device
                           hCurrentDC& = @ptrPrintInfo.hDCPrinter
                           CurrentRect = @ptrPrintInfo.RectPrinter
                        END IF
                     ELSE
                        'Output is unknown - determine header / footer length
                        hCurrentDC& = hDC&
                     END IF
                  
                  
                     SELECT CASE dCommand%
                        CASE %SS_PRINTCMD_HEADERLEN
                           FUNCTION = 800             
                        CASE %SS_PRINTCMD_FOOTERLEN
                           FUNCTION = 120
                        CASE %SS_PRINTCMD_PRINTHEADER
                           SelectObject hCurrentDC&, hMyFont
                           szTemp = "Is this working?"
                           DrawText hCurrentDC&, szTemp, -1, CurrentRect, %DT_LEFT OR %DT_NOPREFIX OR %DT_WORDBREAK
                           DeleteObject hMyFont
                        CASE %SS_PRINTCMD_PRINTFOOTER
                           DeleteObject hMyFont
                     END SELECT
                  
                  
                  END FUNCTION
                  ------------------
                  Bernard Ertl



                  [This message has been edited by Bern Ertl (edited May 29, 2001).]
                  Bernard Ertl
                  InterPlan Systems

                  Comment


                  • #10
                    Bern,

                    Wow, something else. As a last resort try this:

                    DIM lpPrintInfo as SS_PRINTINFO PTR

                    call the function as:

                    FUNCTION SS_PRINTFUNC%( BYVAL hDC&, BYVAL dCommand%, BYVAL nPageNum%, BYVAL lAppData&, lpPrintInfo)

                    See if this works. Good luck!!!

                    Cheers,
                    Cecil

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

                    Comment

                    Working...
                    X