No announcement yet.

Passing UDT values to DLLs

  • Filter
  • Time
  • Show
Clear All
new posts

    Passing UDT values to DLLs

    Reading the comments about UDTs in the "You Talk..." thread got me thinking about my use of UDTs. Basically I love UDTs and try to use them where ever they make sense. Unfortunately I tend to interface with a lot of 3rd party DLLs and I can't directly pass my UDT data to the DLLs because the DLL is looking for a specific type and that type is not a UDT.

    I end up with duplicate variables or just not using the UDTs. Is there something I can do to get around this?


    Yes. Pass the appropriate member of the UDT.


      Guess I need more explanation as even though the individual member is of the correct type, I get an error back. I don't have any code to show since I never got it to work and thus don't do it that way. Or, if just passing the member is supposed to work, I need to go troubleshoot some more.


        In this case you will have to show failing code, because this works just fine.

        Bottom line, "myudt.member" is a variable, just like "x"
        Michael Mattias
        Tal Systems (retired)
        Port Washington WI USA
        [email protected]



          #COMPILE EXE
          #DIM ALL
          TYPE MyUDT
            x AS LONG
            s AS ASCIIZ * 256
          END TYPE
             MSGBOX STR$(x) & $CRLF & s
          END SUB
             LOCAL t AS MyUDT
             t.x = 3
             t.s = "some text"
             MySub(t.x, t.s)
          END FUNCTION


            Funny you should ask Conrad.
            In the past/present/probably future, I have asked/Answered/Researching the same sort of thing.

            Partly on the side of "Find that elusive error", and partly on "Get that DataType" in the source code forum.

            still a research in work (but fairly complete) and may give you an idea or 2 (or 220 )

            Hey payback is worth it when you gave me an idea for my files I am working on updating to include UDT's ( not take that as an insult I am just challenging you a lil bit to run with what I have not worked on yet )

            Hopefully of some help to spark a lightbulb for you, or to spark a lightbulb for me, or someone else???
            Engineer's Motto: If it aint broke take it apart and fix it

            "If at 1st you don't succeed... call it version 1.0"

            "Half of Programming is coding"....."The other 90% is DEBUGGING"

            "Document my code????" .... "WHYYY??? do you think they call it CODE? "


              In Jose's elegantly simple example, the line that answers your question is:

              MySub(t.x, t.s)

              all the rest is just setup for it.

              The helpfile doesn't have URLs so I can't provide links, but in the PB
              helpfile (ver 9.01), search for this topic:
              Accessing the fields of a User-Defined Type

              There are a number of useful sub-topics, including such as:
              Arrays within User-Defined Types
              Using arrays of User-Defined Types

              Unless I'm missing your point, I think your concerns are addressed pretty well??



                John, they always are- that's why I like this place. No matter how misguided my questions are, something useful always comes back. At this point I'm assuming I simply did something wrong, and next time I have to access my various 3rd party DLLs, I'll try again. Unfortunately I have far less time to wander off and try things at will than I might like, but you can be sure I don't miss much on these forums!


                  One trick, useful with the Windows API functions, is to not actually pass a UDT.

                  How ?

                  By storing the data in a PB string and then passing a pointer to the string data.

                  If a DLL (or API) function is declared with a specific data type (to a variable structure for example) you can simply pass the string pointer using:

                  BYVAL STRPTR(My_UDT_In_a_String$)

                  Some APIs for example can have changing structure, such as an array of members tacked on the end (one member before this will have the number of items). Since the array of items is not fixed, PB can not create this type of UDT. Using the technique you can create almost any size data block within a string.

                  Now when you need to access the data, there are tricks to doing that also.

                  For example if the first part of the data block is a fixed UDT, you can create a TYPE for that, create a local varible which is a pointer to that type and then set the pointer.


                  LOCAL V AS SomeType PTR
                  @V.item1 = 1
                  @V.item2 = 1
                  @V.item3 = 1

                  You see, you are accessing the string data using a fixed TYPE, but via a pointer. The part which is variable though (ie. an array tacked on the end) would need to be accessed without a fixed type.
                  Last edited by Chris Boss; 24 Jul 2009, 10:09 AM.
                  Chris Boss
                  Computer Workshop
                  Developer of "EZGUI"