No announcement yet.

PB Wishlist - UDT Packing?

  • Filter
  • Time
  • Show
Clear All
new posts

  • PB Wishlist - UDT Packing?

    How about adding additional options to specify the packing used
    for UDTs? Something like VC++'s 'pragma pack N' option.

    I'm currently moving a VB program to PB and it needs to call a
    DLL written in VC++, but the DLL has been built with the
    'pragma pack 1' option for VB compatibility. So I now have the
    fun task of porting about 600 lines of UDTs to figure out the
    padding needed for PB to call the DLL.

    (I think this has been mentioned before, though I didn't find it
    in a search. If it has, please add another tick!)


    Mark Newman
    Mark Newman

  • #2
    Mark --

    Have you tried using the alignment options that are part of the TYPE syntax?...

    -- Eric

    Perfect Sync: Perfect Sync Development Tools
    Email: mailto:[email protected][email protected]</A>
    "Not my circus, not my monkeys."


    • #3
      Eric -

      I'm aware of the current TYPE alignment options, but I don't think
      that they'll work in this instance of talking to the "VB-friendly"

      From reading the PB docs and the BBS it appears that the only way
      to do this is to manually pad out the PB UDT to match what the
      DLL expects for alignement, in this case the famous/infamous VB
      "Natural" aligment.

      Use a pure BYTE-based UDT would also work, but it'd be WAY too
      much work to manually wrap & unwrap the UDT every time, as I have
      multiple data types and UDTs within UDTs to deal with.

      Hence my selfish wish to PB

      Mark Newman
      Mark Newman


      • #4
        That brings up the question, since VC++6 now packs structures
        on 8-byte alignment(_Win32) as the default, how would PB relate to
        this packing alignment (double type)?



        [This message has been edited by Cecil Williams (edited January 05, 2001).]


        • #5
          If the DLL was built with #pragma pack 1, it's already fully
          compatible with PowerBASIC, which uses BYTE packing by default.

          Note that VC++ uses the same curious half-packed "natural" alignment
          scheme as VB, so the current VC++ default eight-byte alignment
          doesn't leave as much empty space in a structure as you might guess.
          Most Windows structures are built of LONGs, DWORDs, and pointers,
          all 32-bit types that automatically fall into alignment in these

          Yes, support for "natural" alignment is on the PowerBASIC wish list.

          Tom Hanlin
          PowerBASIC Staff


          • #6

            Thanks a lot for clarifing the 8-byte alignment scheme. I ran
            into this when AutoCAD 2000 became a full blown Windows program.
            All the headers now come with 8-byte declaration in the front
            end of the file. I only use VC++6 for ARX apps running inside
            of the cad program, and BTW, can ONLY be compiled with VC6. The
            Borland compiler can't handle the funky function decorations
            (aka mangling) used by VC++.

            Previous versions used the "/Zp1" compiler switch which was
            BYTE alignment. It's also interesting to note that a lot of the
            core functions are now exported thru DLLs along with the EXE
            file which now is a resounding 6.6Mb. If enough of the functions
            reach DLL hood, then you can be sure that a PB interface
            to AutoCAD WILL soon become available.



            [This message has been edited by Cecil Williams (edited January 09, 2001).]


            • #7
              For a DLL to do the pack/unpack of UDT alignment for Visual Basic 4.0 through 6.0 check out this site:

              and download The zip file contains the dll, help file, and a VB Project to demonstrate how to use the DLL.

              Joe Murphy



              • #8
                I've used that DLL from SoftCircuits for some VB stuff, it's
                handy at times.

                The problem that led to the original post was that I'm porting
                an app from VB to PB that uses some include-type files. I have
                the VB versions and the C header files, so between the two I was
                able to build up the PB versions of the include files; time
                consuming but not hard.

                But if PB had native support for the MS "Natural" alignment I
                could have zapped it in no time. Whine Whine Whine

                The good news is that it's on the wishlist.

                (Tom H: The thing about the 'pragma pack' option that threw me
                was that it was set to 1, not 4 as I'd expect for VB usage. It
                turns out that the DLL author aligned everything on 4-byte
                boundaries by manipulating the structure def, so in truth the
                'pragma pack' option could have used 1, 2 or 4 with the same

                Mark Newman
                Mark Newman