Announcement

Collapse
No announcement yet.

Bug or Feature?

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

  • Bug or Feature?

    Hi,

    i need to have declare several versions of an api
    function/sub like this.
    PB will not compile, and returns error 466.
    Is there any workaround?


    #COMPILE EXE

    DECLARE FUNCTION MoveMemory LIB "KERNEL32.DLL" ALIAS "RtlMoveMemory" (lpDest AS ANY, lpSource AS ANY, BYVAL cbMove AS LONG) AS LONG
    DECLARE SUB ZeroMemory LIB "KERNEL32" ALIAS "RtlMoveMemory" (BYVAL lpDest AS LONG, BYVAL numBytes AS LONG)

    FUNCTION PBMAIN

    END FUNCTION


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

  • #2
    Download the latest win32 API file. It contains Movememory wrapped into a CopyMemory function. Currently, you can't declare the same API function name (in quotes after alias more than once so a work-around is necessary.

    Comment


    • #3
      To answer the question, "Bug or Feature?":

      I think it's a "negative feature."

      A negative feature is something which "works as designed" but the design itself is of dubious worth.

      Kinda like Microsoft "Bob."

      MCM
      (And by the way, allowing multiple declarations of same-aliased external functions would be a terrific new feature.)

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

      Comment


      • #4
        Hmmmmmmmm, PB with overloaded function capability? Sounds like
        an outstanding idea.

        Cheers,
        Cecil

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

        Comment


        • #5
          can't you use an #ifdef type idea or do you need to use them both together?




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

          Comment


          • #6
            One workaround - change the second declare of "RtlMoveMemory" to something like "RtlMoveMemor2". Compile, use a hex editor, and rename it back.
            It seems to work fine when I just tested it with Beep(), but I'm not sure if there are any negative implications in doing this.

            Best of luck,
            Wayne


            [This message has been edited by Wayne Diamond (edited October 22, 2001).]
            -

            Comment


            • #7
              can't you use an #ifdef type idea or do you need to use them both together?
              Where the "multiple declarations sharing a single alias" would be most useful is when you have a WinAPI function which accepts a variable number of parameters.

              Code:
              DECLARE Function FooWithOne Lib "WHATEVER" ALIAS "WinApiFunc" (parm1) AS LONG
              DECLARE FUNCTION FooWithTwo Lib "WHATEVER" ALIAS "WinApiFunc" (parm1, Parm2) AS LONG
              
              
                 CALL FooWithOne (X)
                 CALL FooWithTwo (X,Y)
              I forget off the top of my head which functions work like this, but I know there are some. (Wsprintf?)

              Also useful for overriding a datatype..

              Code:
              DECLARE FUNCTION FooLong  Lib "whatever" ALIAS "Foo" (X AS LONG) AS LONG
              DECLARE FUNCTION FooDword Lib "whatever" ALIAS "Foo" (X AS DWORD) AS LONG
              
                Z = FooLong (2&)
                ZZ = FooDword (2???)
              As long as the target routine is only looking for "32-bit anything" either version should work.


              MCM

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

              Comment


              • #8
                Can also do own ZeroMemory, like:
                Code:
                  POKE$ lpDest, STRING$(numBytes, 0)
                Otherwise, maybe possible to place second declare in a separate DLL?


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

                Comment


                • #9
                  A UNION would also be an easy way to do this. Create a UNION with all of the different ways you want to pass values to the API, then change the API declaration to accept a TYPE that contains the UNION.

                  -- 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 October 22, 2001).]
                  "Not my circus, not my monkeys."

                  Comment


                  • #10
                    Why not use "loadlibrary" and define functions the way "You" want them?


                    ------------------
                    Fred
                    mailto:[email protected][email protected]</A>
                    http://www.oxenby.se

                    Fred
                    mailto:[email protected][email protected]</A>
                    http://www.oxenby.se

                    Comment


                    • #11
                      Where the "multiple declarations sharing a single alias" would be most useful is when you have a WinAPI function which accepts a variable number of parameters.
                      Optional parameters are already supported. See the Win32API.inc declare for wsprintf.


                      ------------------
                      Tom Hanlin
                      PowerBASIC Staff

                      Comment

                      Working...
                      X