Announcement

Collapse
No announcement yet.

"AS ANY" ?

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

  • "AS ANY" ?

    I see in the PBDLL6 Help file you can pass a parameter to
    a sub/function "AS ANY" but for the life of me I cant get it
    working
    Something like this is what I am trying to do:

    Function DoSomething(TheData as ANY, DataLen as Long)

    It Just doesnt like the "as any".

    Anyone have any Ideas ?

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

  • #2
    i strongly suspect you will be using that same byte array i was using...

    http://www.powerbasic.com/support/pb...ead.php?t=3902



    ------------------
    scott
    Scott Turchin
    MCSE, MCP+I
    http://www.tngbbs.com
    ----------------------
    True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

    Comment


    • #3
      Thanx Scott. Will have a look at that.

      One thing I did notice is that the following will compile

      function Dosomething(ANY, DataLen as Long) Long


      hmmm.

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

      Comment


      • #4
        Neil --

        Isn't AS ANY part of the Help File description for DECLARE? Not FUNCTION.

        If I'm not mistaken, AS ANY can only be used to DECLARE a parameter in an external module, such as a DLL. It can't be used in a FUNCTION definition.

        Basically AS ANY means that a pointer to some type of (unspecified) data will be passed to the sub or function. It's useful, for example, when the Windows API specifies "a pointer to one of the following eight types of data must be passed to this function".

        > the following will compile
        >
        > function Dosomething(ANY, DataLen as Long) Long

        That may compile, but what can you do with it? There's no variable name for your program to use in the function.

        If you want to accomplish the same thing as AS ANY, all you have to do is use AS DWORD or AS LONG. Then you can use VARPTR or STRPTR to obtain a pointer for any type of data, and pass it to your function. The hard part is figuring out what to do with it, once the function receives the pointer.

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

        Comment


        • #5
          Its a bit vague, help file doesnt state that "as any" can only be
          used with external api's.
          >Isn't AS ANY part of the Help File description for DECLARE? Not FUNCTION.
          >If I'm not mistaken, AS ANY can only be used to DECLARE a parameter in an external module, such as a DLL. It can't be used in a FUNCTION definition.


          > the following will compile
          >
          > function Dosomething(ANY, DataLen as Long) Long

          >That may compile, but what can you do with it? There's no variable name for your program to use in the function.

          Yep I know that (hence the hmmm.)


          Will try the dword or long.

          BTW. its a UDT of unkown type that I want to read and just
          write to a file.

          TA.
          Neil.

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




          [This message has been edited by Neil Hosgood (edited June 21, 2001).]

          Comment


          • #6
            Just about got it, but need a bit more help.
            The following code works (at least for me) only
            if:
            1. All elements of the UDT have data
            2. if any element of the UDT is not a string then only
            elements upto and including that element are got by
            peek$.

            Any Ideas? Pleaseeeee

            #COMPILE EXE

            TYPE MyType 'just an example
            FirstName AS STRING * 20
            LastName AS STRING * 20
            Active AS STRING * 1
            age AS STRING * 3
            OtherStuff AS STRING * 10
            END TYPE

            GLOBAL Current AS MyType

            FUNCTION PutUDT (BYVAL lpData AS DWORD , VarLen AS LONG) AS LONG
            LOCAL Buffer AS STRING

            Buffer = SPACE$(VarLen)

            POKE$ VARPTR(Buffer), PEEK$(VARPTR(lpData), Varlen)

            MSGBOX Buffer,,"Almost any UDT"

            END FUNCTION

            FUNCTION PBMAIN() AS LONG
            LOCAL dwp AS DWORD, DataLen AS LONG

            Current.FirstName = "Joe"
            Current.LastName = "bloggs"
            Current.Active = "Y"
            Current.age = "70"
            Current.OtherStuff = "rogue"

            DataLen = SIZEOF(Current)
            dwp = VARPTR(Current)

            X& = PutUDT(dwp,DataLen)

            END FUNCTION


            [This message has been edited by Neil Hosgood (edited June 22, 2001).]

            Comment


            • #7
              Neil,
              Code:
              ==========================================================
              BTW. its a UDT of unkown type that I want to read and just 
              write to a file.
              ==========================================================
              If all you require is the address of a structure, you can probably
              use a LONG or DWORD as addresses in 32 bit windows are 32 bit in
              size. How you read a UDT of unknown type is another matter. I gather
              you must have some method of reading the correct length so that you
              can save it to file.

              If you knew the layout of the UDT, you may be able to cast the
              address as a pointer and access its members that way.

              Regards,

              [email protected]


              ------------------
              hutch at movsd dot com
              The MASM Forum

              www.masm32.com

              Comment


              • #8
                Steve,

                We must have been posting at the same time ?
                did you see my code, just above you reply ?

                Thats where I am stuck

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

                Comment


                • #9
                  Neil, the MSGBOX statement is probably "tricking" you... it truncates at the first embedded CHR$(0) in Buffer$ before displaying the message. Try testing the length of Buffer$ instead of displaying it's contents.


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

                  Comment


                  • #10
                    If your UDT is truly unknown, that's one thing; but if your UDT is "one of a known number of possibilities", you can use a UNION.

                    MCM


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

                    Comment


                    • #11
                      Lance,
                      Thanx for you reply. Just tried testing length of buffer by
                      adding the following code to PutUDT().

                      BuffLen& = LEN(Buffer)
                      MSGBOX "Buffer Length = " & STR$(BuffLen&),,"Data in Buffer Should Be " & STR$(VarLen)

                      All hell broke loose and GPF's were abundant
                      Funny thing is, I comment out the MSGBOX line and all is well.

                      All I am trying to do is pass any UDT or STRING to a function
                      and write it to a binary file. The function that reads it from
                      the file just returns a string of what ever length is requested
                      by the caller, then its upto the caller to LSET the data into a type .

                      PS. Any comment on my Original question "As ANY" ?
                      ------------------


                      [This message has been edited by Neil Hosgood (edited June 22, 2001).]

                      Comment


                      • #12
                        Michael, the UDT is unkown, consider the PutUDT function
                        as something that wrote ANY UDT to a randon access file
                        (of course I would pass filehandle and index handle and key)
                        The code I have so far works with UDT's that are all strings
                        but seems to be tempramental

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

                        Comment


                        • #13
                          Typically, "unknown" UDT includes, as minimum, one first additional field, let's say VersId, which allows to understand type (and length) of UDT.
                          Good samples - file formats (BMP, ICO and so on - http://www.wotsit.org )

                          ------------------
                          E-MAIL: [email protected]

                          Comment


                          • #14
                            Kewl site Semen

                            However I don't want this function to care what data type
                            is being sent to it. The function gets sent the length of
                            the data and a pointer, all it has to do is grab n bytes from
                            the location provided and write them to disk (in the real app
                            it compresses them before writing)

                            Why is it so hard in PB ?
                            In 1992 using VB1 with a cool DB package calleg Agility/VB it
                            took a one call to throw ANY data into a file (including
                            images, sound and UDT's)

                            Unfortunatly the Agility People have succumed to the MS Machine
                            and havnt re-written their package as a 32bit dll

                            Thats about enough bleats from me.
                            Have fun.

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

                            Comment


                            • #15
                              Neil

                              Buffer is declared as a dynamic string. Shouldn't you be
                              using STRPTR instead of VARPTR to get the address for the Poke$?

                              Mike


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

                              Comment


                              • #16
                                Mike.
                                Will give ite a go.... Nope, even worse

                                >Buffer is declared as a dynamic string. Shouldn't you be
                                >using STRPTR instead of VARPTR to get the address for the Poke$?

                                Have you compiled my source ?
                                It seems to work if all elements are strings and all have data,
                                even if the data id just a space.

                                N.


                                you will have to excuse my typing, it's 1:40am


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


                                [This message has been edited by Neil Hosgood (edited June 22, 2001).]

                                Comment


                                • #17
                                  Neil,

                                  may be I didn't understand the problem. If the matter is to read ANY data at a given address for a given length, it is enough to:

                                  Code:
                                  FUNCTION ReadData( AddressData as DWORD, LengthData as DWORD ) AS LONG
                                  
                                  LOCAL StringData AS STRING
                                  
                                    StringData = PEEK$( AddressData, LengthData )
                                    ........
                                  
                                  END FUNCTION
                                  
                                  FUNCTION PBMAIN AS LONG
                                  
                                  LOCAL AnyUdt AS AnyUdtType
                                  
                                    ReadData VARPTR( AnyUdt ), SIZEOF( AnyUdt )
                                  
                                  END FUNCTION
                                  ------------------

                                  [This message has been edited by Aldo Cavini (edited June 22, 2001).]
                                  Rgds, Aldo

                                  Comment


                                  • #18
                                    So would this apply to my ReadEventLog as well? (See previous post)


                                    ???

                                    ------------------
                                    Scott
                                    Scott Turchin
                                    MCSE, MCP+I
                                    http://www.tngbbs.com
                                    ----------------------
                                    True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

                                    Comment


                                    • #19
                                      Aldo,

                                      Thanx for your input, Just tried your idea and got any empty
                                      string
                                      what am I doing wrong ?

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

                                      Comment


                                      • #20
                                        Neil

                                        This works

                                        Poke$ StrPtr(Buffer), Peek$(lpData, Varlen)

                                        You dont want the address of lpdata since you passed the address
                                        in lpdata.

                                        Aldo's example is functionally the same. Did you setup the udt in
                                        his example?

                                        Mike


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


                                        [This message has been edited by Mike Burns (edited June 22, 2001).]

                                        Comment

                                        Working...
                                        X