Announcement

Collapse
No announcement yet.

Declare statement bug?

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

  • Declare statement bug?

    Is this a bug or there for a reason?

    It seems that if a declare statement has more than 16 arguments
    the compiler will not compile it. I came across this problem
    using the JacommPB interface, trying to access a word statement.

    i used this test program to test my theory

    DECLARE FUNCTION Test (a AS STRING, b AS STRING, c AS STRING, d AS STRING,_
    e AS STRING, f AS STRING, g AS STRING, h AS STRING, _
    i AS STRING, j AS STRING, k AS STRING, l AS STRING, _
    m AS STRING, n AS STRING, m AS STRING, p AS STRING) AS DWORD

    This Compiles fine but if I put one more argument in it doesnt

    DECLARE FUNCTION Test (a AS STRING, b AS STRING, c AS STRING, d AS STRING,_
    e AS STRING, f AS STRING, g AS STRING, h AS STRING, _
    i AS STRING, j AS STRING, k AS STRING, l AS STRING, _
    m AS STRING, n AS STRING, m AS STRING, p AS STRING, q AS STRING) AS DWORD

    This gets an error 414 ")" expected.

    Any Ideas?

    ------------------
    Darren James
    ------------
    TARSC Travel Systems



    [This message has been edited by Darren James (edited May 09, 2001).]

  • #2
    The maximum number of arguments to a PB sub/function is 16, so
    what you're seeing is correct. If you need to pass more than 16
    consider using TYPE or array variables.


    ------------------
    Mark Newman
    Mark Newman

    Comment


    • #3
      I am passing to external source, no option.

      ------------------
      Darren James
      ------------
      TARSC Travel Systems

      Comment


      • #4
        Darren --

        > no option.

        Sure there is!

        Create a TYPE structure that has the same memory layout as the parameters you need to pass, and pass that instead of individual parameters.

        Imagine that the DLL is sitting there expecting two LONG parameters. You could declare the function this way...

        Code:
        DECLARE FUNCTION ExtFunc(Param1 AS LONG, Param2 AS LONG) AS whatever
        ...or this way...

        Code:
        TYPE TwoLongs
            Param1 AS LONG
            Param2 AS LONG
        END TYPE
         
        DECLARE FUNCTION ExtFunc(MyStruct AS TwoLongs) AS whatever
        ...and the external function will never know the difference. As long as the memory structure that is passed to the DLL is correct, everything will work fine.

        Depending on the calling convention you might need to build the TYPE "backwards", but it would still be very easy. And you may need to use pointers for some of the TYPE elements, but again it's fairly straightforward.

        This is NOT a show stopper!

        -- Eric


        ------------------
        Perfect Sync Development Tools
        Perfect Sync Web Site
        Contact Us: mailto:[email protected][email protected]</A>
        "Not my circus, not my monkeys."

        Comment


        • #5
          I shall try this

          Thanks

          ------------------
          Darren James
          ------------
          TARSC Travel Systems

          Comment


          • #6
            PowerBASIC passes UDT's BYREF, not BYVAL, so unless you can change the library being called, that solution probably won't work for you.

            The alternative is to PUSH the parameters onto the stack and call the target DLL function with CALL DWORD. Sorry I don't have any examples of using this method, but I know it has been used successfully.


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

            Comment


            • #7
              Lance --

              I stand corrected. You're right of course, but I'd have sworn that I've actually done that before! Obviously not. Getting old I guess... Like Richard Pryor says, I don't have Alzheimer's, I have Some-Timers...

              -- Eric


              ------------------
              Perfect Sync Development Tools
              Perfect Sync Web Site
              Contact Us: mailto:[email protected][email protected]</A>



              [This message has been edited by Eric Pearson (edited May 09, 2001).]
              "Not my circus, not my monkeys."

              Comment


              • #8
                PowerBASIC passes UDT's BYREF, not BYVAL, so unless you can change the library being called, that solution probably won't work for you.
                Well,if some parameters are BYVAL and some BYREF, you can pass addresses as DWORD UDT members.

                Alternately (and I haven't tried this), if you can pass a QUAD BYVAL, you can effectively get 32 "BYVAL LONG" parameters out of 16 "BYVAL QUADs."

                MCM


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

                Comment


                • #9
                  Originally posted by Michael Mattias:
                  Well,if some parameters are BYVAL and some BYREF, you can pass addresses as DWORD UDT members.
                  I don't follow you here... passing a UDT (BYREF) means that just one 32-bit parameter (a pointer to the UDT) is passed. The content of the UDT is irrelavent as far as the stack frame is concerned (and the stack frame is where the parameters (or their pointers for BYREF's) are placed immediately before the call to the DLL/sub/function.

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

                  Comment


                  • #10
                    What I meant was if there is a structure to be passed by value, followed by additional parameter items to be passed by a mixture of reference and value.

                    However, I just realized the best solution to this situation is to fire the programmer and start over.

                    MCM


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

                    Comment


                    • #11
                      Darren, how many and what type variable are the parameters you need to send?
                      Do you have the declaration/prototype for the external function you are trying to call?

                      Ron

                      Comment


                      • #12
                        This is my codethat I am calling, generated by JacomPB

                        DECLARE FUNCTION COMApplication_PrintOut CDECL(BYVAL pThis AS DWORD, _
                        BYREF Background AS VARIANT, BYREF dApp AS VARIANT, _
                        BYREF Range AS VARIANT, BYREF OutputFileName AS VARIANT, _
                        BYREF dFROM AS VARIANT, BYREF dTO AS VARIANT, _
                        BYREF Item AS VARIANT, BYREF Copies AS VARIANT, _
                        BYREF Pages AS VARIANT, BYREF PageType AS VARIANT, _
                        BYREF PrintToFile AS VARIANT, BYREF dCol AS VARIANT, _
                        BYREF dFile AS VARIANT, BYREF ActivePrinterMacGX AS VARIANT, _
                        BYREF ManualDuplexPrint AS VARIANT, BYREF PrintZoomColumn AS VARIANT, _
                        BYREF PrintZoomRow AS VARIANT, BYREF PrintZoomPaperWidth AS VARIANT, _
                        BYREF PrintZoomPaperHeight AS VARIANT) AS DWORD

                        This is the Print Declaration for Word 2000


                        ------------------
                        Darren James
                        ------------
                        TARSC Travel Systems

                        Comment


                        • #13
                          As an aside, can I ask if you have informed Philippe that JACOM/PB generates PowerBASIC code with more than 16 parameters?

                          Are you intending to use WORD 2000 just for printing? That would make it like the largest resource hogging printer driver in the world, by a huge factor!

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

                          Comment


                          • #14
                            Jesus,

                            What an ugly function, At least M$ know how to use structs to keep their params down.

                            I'd almost go so far as to to call it a bug in the function design, yuk

                            ------------------
                            Paul Dwyer
                            Network Engineer
                            Aussie in Tokyo

                            Comment


                            • #15
                              Lance, I am unaware of Philippe email address.

                              ------------------
                              Darren James
                              ------------
                              TARSC Travel Systems

                              Comment


                              • #16
                                It should be in the JACOMPB doc's, or the About box, etc... You must have emailed him to get hold of JACOMPB, right?

                                Failing that, you can get his email from his site at www.jazzagesoft.com


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

                                Comment


                                • #17
                                  Basically we are trying to provide integration into MS Office
                                  products from our software. We provide a Travel System, in which
                                  users run many reports and Print many Templated letters. We want
                                  to provide this so that our customers can tailor the look and
                                  feel of the reports to their own needs.

                                  Is there a reason why PB only
                                  supports 16 arguments for a Function?

                                  ------------------
                                  Darren James
                                  ------------
                                  TARSC Travel Systems

                                  [This message has been edited by Darren James (edited May 10, 2001).]

                                  Comment


                                  • #18
                                    Following on from what I said above, I have only gone a little
                                    into the Word stuff, without touching Excel. So The limit on the
                                    number of arguments could prove to be a right pain in the neck.


                                    ------------------
                                    Darren James
                                    ------------------
                                    TARSC Travel Systems

                                    Comment


                                    • #19
                                      Have you tried my suggestion of pushing the parameters on the stack and calling the function with !CALL DWORD ?

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

                                      Comment


                                      • #20
                                        After much tinkering I finally got it to work using the call
                                        DWORD Method.

                                        Cheers Lance

                                        ------------------
                                        Darren James
                                        ------------------
                                        TARSC Travel Systems

                                        Comment

                                        Working...
                                        X