Enhanced SizeOf Utility with Sample Application and WinAPI Tutorial Demo & Tests
Roland Smith provides a free code sample (named "SizeOf") on his TopWizProgramming.com website for calculating the size of a structure. The calculation logic is contained within a single non-visual object that was originally authored many years ago by Rui Cruz. Roland enhanced the original object to handle the datatypes added to PB in version 12.6. With Roland's permission, I've coded several additional enhancements to the object to address some features needed for the 64-bit environment and I'm making the enhanced version available to the Appeon Community. These enhancements include:
[br]
- It recognizes the process bitness and uses that value as the default to determine member and structure size.
- Either bitness can be optionally requested prior to requesting a SizeOf calculation on a structure. A sample application is included that uses this feature to display the size of several types of structures for 32-bit and 64-bit.
- It can determine boundary alignment for structure members and nested structures using either the progma_pack( 8 ) or progma_pack( 1 ) rules and includes padding bytes in the size calculations to address alignment issues when needed.
- It can calculate member and structure size for either Unicode or ANSI characters/strings.
- It can produce a report that describes the layout of a structure in memory, including nested structures.
The sample application also can perform several test suites related to a four-part tutorial titled "Interfacing PB Applications with the Windows API", which will soon be published in the Appeon Community "Articles & Blogs" section.[br]
The enhanced SizeOf non-visual object and the Structure Layout sample application were developed using PB 2017 R2 and can be compiled into either a 32-bit or 64-bit executable. It has been successfully migrated and tested in PB 2019 R2.
This message has an attachment file.
Please log in or register to see it.
Please Log in or Create an account to join the conversation.
No prob! Handy tool you have there.
Please Log in or Create an account to join the conversation.
Lawrence -
You have a very sharp eye! Yes, you are correct on both of the issues you pointed out. I will correct the structures, review the app, add some WinAPI structures, and re-submit the corrected app for review in the very near future. Thank you for catching these issues and bringing them to my attention!
Please Log in or Create an account to join the conversation.
for s_startupinfow, lpReserved2 is a LPBYTE, shouldn't that be a longptr, not a ulong?
https://stackoverflow.com/questions/66157098/byte-packing-for-winapi-startupinfo-64-bit-qb64
* this generates another padding entry
for s_choosefontw, lptr_nsizemin & lptr_nsizelong should be long not longptr
https://learn.microsoft.com/en-au/windows/win32/api/commdlg/ns-commdlg-choosefontw
Last Edit: 1 day 10 hours ago by Lawrence Sim .
Please Log in or Create an account to join the conversation.