When you use a structure or structure array as parameters to external function in the older versions of PowerBuilder, the structure member alignment was one byte. However, the default alignment is 8 bytes on Windows platform, which means that most (if not all) Windows standard APIs use this value to align arguments with structure members. This will cause a mismatch between Windows APIs and PB applications in PowerBuilder 12.5 and earlier versions. A well-adopted solution to this issue was to add some bytes within PowerBuilder structures manually to fill those gaps. Such gap filling can be complex and error-prone if involving complex nested structures. And what is worse, this solution fails with the introduction of 64-bit application development in PowerBuilder 12.6 because the number of bytes you have to fill may be different between 64-bit and 32-bit applications. This was the major reason to make this change in PowerBuilder 12.6. With PowerBuilder 12.6 for Windows API and Visual C++ the default structure member alignment is now 8 bytes. The structure member alignment was changed to 8 bytes in PowerBuilder 12.6 for both 64-bit and 32-bit applications. This was an intentional change. Customers can now call Windows API easier and use the same code for both 64-bit and 32-bit applications.

Customers can switch to the old behavior in two ways with PowerBuilder 12.6 build 4058 and above.

1. Check "Use 1-byte structure member alignment in external function" (or set UseZp1=1 in [pb] section, pb.ini, the results are same). The effect is global with this setting changed. To make this work at runtime, please remember to deploy your pb.ini file with your application.

2. Add “progma_pack(1)” external function’s declaration, like this:

FUNCTION int STLAREGIO ( ref struc_kfzrechnerneu struc_kfz ) LIBRARY "KFZ_SS.DLL" alias for "STLAREGIO;Ansi" progma_pack(1)

progma_pack(1) is 1-byte align, progma_pack(8) is 8-bytes align. In this way, the effect is only for external function that is declared with this alignment.

 

1
0