list of structs with parameters (sizes and types)

Helpful script writing tricks and HowTo's
User avatar
jeeswg
Posts: 1700
Joined: 19 Dec 2016, 01:58
Location: UK

list of structs with parameters (sizes and types)

13 Apr 2017, 00:37

I am collecting structs with parameter types and sizes for quick reference. This list will expand in time (to at least 100), plus I will provide some code for generating these struct summaries. Do post any requests for structs that you would like to see on this list, or notify of any incorrect information.

The basic rules are the same for both x64 and x32. In general: an n-byte parameter must start at an n-byte offset, and the overall size of the struct must be divisible by the size of the biggest parameter. Note: because of these alignment rules can you actually get a fair number of gaps in a struct, including at the end of the struct.

Some items are misleading, a RECT has size 16, but is treated as 4 consecutive Ints, it starts at an offset divisible by 4.

Ints and UInts start at offsets divisible by 4.
In x32, Ptrs have size 4, so start at offsets divisible by 4.
In x64, Ptrs have size 8, so start at offsets divisible by 8.

notes:
- * - if an asterisk is present, then that normally means the parameter is a Ptr type
- []; - a parameter can have a value in square brackets, e.g. '[3]' means that parameter appears 3 times, e.g. '[MAX_PATH]' means that parameter appears 260 times, you get an 'array' of parameters
- union - 'A union is a user-defined type in which all members share the same memory location.'

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus


Links:
Window Data Types (Compact 2013)
https://msdn.microsoft.com/en-us/library/ee504522.aspx
Hungarian Notation
https://msdn.microsoft.com/en-us/library/aa260976(v=vs.60).aspx

Note: around 20 of the structs have '[CHECK]' underneath them, which are ones I will add information to.

Note: some parameters/structs can differ depending on the operating system, architecture (x32/x64), or whether the program is ANSI/Unicode. E.g. TBYTE/TCHAR depend on whether the program is ANSI/Unicode.

Note: in the structs below we assume that TCHAR refers to a Unicode character, and is thus a UShort of size 2.

Note: if a struct refers to another type of struct, then that struct is also in the list below.

HELP: It would be useful if someone could confirm LVITEM (x64). I am not sure as to whether parameters can overlap an #endif.

The information is presented in the way it is, to do things like:

Code: [Select all] [Download] GeSHi © Codebox Plus

vSize := (A_PtrSize=8?48:32)
MsgBox, % NumGet(MENUBARINFO, A_PtrSize=8?40:28, "Int") ;fBarFocused / fFocused

STRUCT=SizeInBytesX64:SizeInBytesX32

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



I struct gold.
Last edited by jeeswg on 18 Apr 2017, 16:26, edited 22 times in total.
User avatar
Drugwash
Posts: 212
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania
Contact:

Re: list of structs with parameters (sizes and types)

13 Apr 2017, 04:00

For a long time now my dream has been a fully fledged struct parser that would have its own (complete) database of structures retrieved from old and new MSDN versions, so that it would provide the user with a struct list and by choosing the desired item it would return any and all possible information and code (usable in both AHK 1.0 and 1.1+) about it.
That combined with a user defined-struct builder would be an excellent tool for those that make extensive use of DllCall() and not only.
EDIT:
Of good help could be the WinStructs project together with _Struct() and Ahk-SizeOf-Checker, and maybe useful additions would make these scripts for GUID/UUID manipulation here and here.
/EDIT
Until recently I had no knowledge about structure alignment so some of my scripts may be buggy in this regard, most certainly in an x64 environment.

I know someone here might jump in with a "do it yourself!" statement so to make it clear: I'm not asking for things to be done - just speaking my mind. And maybe the scripts I pointed to could be useful for the current task.
just me
Posts: 4440
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: list of structs with parameters (sizes and types)

13 Apr 2017, 09:07

AFAIK, AHK_H Struct() doesn't have built-in support for
  • non-default alignment
  • creating 32-bit structures on AHK x64 and vice versa.
User avatar
jeeswg
Posts: 1700
Joined: 19 Dec 2016, 01:58
Location: UK

Re: list of structs with parameters (sizes and types)

13 Apr 2017, 10:11

@Drugwash
Haha 'do it yourself'. I think people should ask a lot, and give a lot, simples.

Also, I know if I'm expert in something I can save someone else a lot of time, when learning something new, and vice versa. A bit like 'comparative advantage'. A bit of help at the beginning is really useful, just to get a foothold.

I think that struct parsers/builders would be good too, although even if we did get one, I think it's important to have some hardcoded lists to confirm that the parsers/builders work, and to guarantee accuracy for common structures. Some attempts that I know of are: _Struct.ahk and sizeof.ahk.

Actually, also of use would be a (fairly) comprehensive list of parameter types and parameter/struct sizes, I have been working on those, and used them to make this list, and will be sharing these in due course.

I will also do some lists for DllCall.

I've basically done all the structs I intended to do. If ever I come across a new one, I might add it in. If there are any other structs that people think should be added to the list just post all the ones that *theoretically* you would like added to the list, and I might get round to adding some/all of them in. Don't be shy about posting a very long list, and don't worry about removing items from your list that overlap with the list above.

==================================================

@guest3456 and just me
Interesting re. AHK_H.

Nice list of data types here:
Built-in Structure types
https://hotkeyit.github.io/v2/docs/StructTypes.htm
User avatar
nnnik
Posts: 2080
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: list of structs with parameters (sizes and types)

13 Apr 2017, 10:53

Actually, also of use would be a (fairly) comprehensive list of parameter types and parameter/struct sizes, I have been working on those, and used them to make this list, and will be sharing these in due course.
That one already exists. Bentschi did one once.
Recommends AHK Studio
guest3456
Posts: 1997
Joined: 09 Oct 2013, 10:31

Re: list of structs with parameters (sizes and types)

13 Apr 2017, 10:57

just me wrote:AFAIK, AHK_H Struct() doesn't have built-in support for
  • non-default alignment
  • creating 32-bit structures on AHK x64 and vice versa.


i dont know...

HotKeyIt wrote:ping

HotKeyIt
Posts: 1423
Joined: 29 Sep 2013, 18:35
Contact:

Re: list of structs with parameters (sizes and types)

13 Apr 2017, 15:30

just me wrote:AFAIK, AHK_H Struct() doesn't have built-in support for
  • non-default alignment
  • creating 32-bit structures on AHK x64 and vice versa.

  • I think you should be able to use Bit Fields for non default alignment. Do we have an example where it would be required?
  • Of course one would need 32-bit exe for 32-bit and 64-bit for 64-bit structures. Why would you need that? It would be easy to implement but I don't think it makes sense, it would just lead to errors and confusion.
just me
Posts: 4440
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: list of structs with parameters (sizes and types)

14 Apr 2017, 01:50

  • Code: [Select all] [Expand] [Download] (CommCtrl.h)GeSHi © Codebox Plus

  • Inter-process communication.
User avatar
nnnik
Posts: 2080
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: list of structs with parameters (sizes and types)

14 Apr 2017, 01:53

HotKeyIt wrote:
just me wrote:AFAIK, AHK_H Struct() doesn't have built-in support for
  • non-default alignment
  • creating 32-bit structures on AHK x64 and vice versa.

  • I think you should be able to use Bit Fields for non default alignment. Do we have an example where it would be required?
  • Of course one would need 32-bit exe for 32-bit and 64-bit for 64-bit structures. Why would you need that? It would be easy to implement but I don't think it makes sense, it would just lead to errors and confusion.
Saving to files/ sending acorss the internet in a format that requires that requires it's structures to be aligned in a certain way that follows the 64/32 bit norm.
Recommends AHK Studio
HotKeyIt
Posts: 1423
Joined: 29 Sep 2013, 18:35
Contact:

Re: list of structs with parameters (sizes and types)

14 Apr 2017, 02:16

nnnik wrote:aligned in a certain way that follows the 64/32 bit norm.
With certain you mean non-default, right? Do you have an example?
User avatar
nnnik
Posts: 2080
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: list of structs with parameters (sizes and types)

14 Apr 2017, 02:55

HotKeyIt wrote:
nnnik wrote:aligned in a certain way that follows the 64/32 bit norm.
With certain you mean non-default, right? Do you have an example?

Yeah I was using your Struct lib to send some data over a Socket but didn't get any good results ( the binaries were encoded in base64 then send as text ). That was because I was sending from a 64-bit Version to a non 64 bit Version of AutoHotkey.
And yes with certain I mean default.
Recommends AHK Studio
just me
Posts: 4440
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: list of structs with parameters (sizes and types)

14 Apr 2017, 05:15

Another interesting structure:

Code: [Select all] [Expand] [Download] (shellapi.h)GeSHi © Codebox Plus


Note:

Code: [Select all] [Download] (shellapi.h)GeSHi © Codebox Plus

// line 48 ff
#if !defined(_WIN64)
#include <pshpack1.h>
#endif
// line 255
typedef WORD FILEOP_FLAGS;
User avatar
Drugwash
Posts: 212
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania
Contact:

Re: list of structs with parameters (sizes and types)

14 Apr 2017, 08:05

Working with structures is not that simple.
While some of the structures are simple buffers that may have been allocated (in AHK) a size larger than required, others require that the exact size of the buffer be entered in a special field (usually first field of the structure).
This size may depend on the OS version, OS type, API version and/or other criteria. And while some API versions may (?) accept a wrong struct size, most would error out.

Therefore it all depends on the target OS range of the script. Simply choosing largest size according to the #if directives in the original MS headers and separating by ANSI/Unicode won't always cut it for older systems like 2000/XP, not to mention the 9x and NT4 line. Since I'm primarily a 9x user I know how this goes. I've tried hard for some recent scripts to be compatible with at least 98/ME and XP - nothing else to test on, currently - and it took a lot of work. First OS version has to be determined and ideally certain API versions too, such as those in common controls for Toolbar/Rebar/etc and maybe RichEdit too, then use the appropriate struct sizes according to that info. Something new coders wouldn't bother with - "either you use Win10 or you're toast", they say.

So, how do we stand…?
User avatar
jeeswg
Posts: 1700
Joined: 19 Dec 2016, 01:58
Location: UK

Re: list of structs with parameters (sizes and types)

14 Apr 2017, 08:35

I have been writing some functions which I hope to post soon, that get/set the text for various control types on internal/external GUI windows. AHK might be x32/x64, the external program might be x32/x64, if a struct is required, such as LVITEM or TVITEM, we usually have to prepare it in the same 'bitness' as the external program.
User avatar
Drugwash
Posts: 212
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania
Contact:

Re: list of structs with parameters (sizes and types)

20 Apr 2017, 04:17

Yes, a combination of 32bit application on 64bit Windows can be misleading so a proper detection system should be created and used.
I've built some helper functions that retrieve OS version or compare current version to a given one (see func_GetOSver.ahk and func_OStest.ahk in my LLB's lib folder) and used them in building the REBARBANDINFO structure, for example in the Rebar wrapper func_Rebar.ahk, which I believe is still not x64-safe due to (mis)alignment.

Structures like i.e. TBBUTTON or TBBUTTONINFO are tricky. Current MSDN information is worthless when dealing with 2000/XP (or older) so messages like TB_SETBUTTONINFO or TB_GETBUTTONINFO would fail on those systems because struct size for TBBUTTONINFO is different for pre/post-Vista OS. (just noticed that in func_Toolbar.ahk --> TB_BtnSet() where the comparison is buggy because it doesn't do "is Vista or later" but only "is Vista")

Structures like those in iphlpapi.dll (see my NetMeterEx) may be much trickier since they may have variable sizes and certain fields may hold different contents according to OS version (I've noticed differences betweeen 98SE and XP) such as APIs returning ANSI string although MSDN states it should return Unicode or some DWORD index field returning either one or two WORDs depending on OS version.

Therefore not only calculating correct structure size may be a problem but also the commands/functions used to retrieve info from the struct fields should be adjusted according to all those criteria. Yeah, working out structures in a flawless way is an extremely difficult task.

Return to “Tutorials”

Who is online

Users browsing this forum: Delta Pythagorean and 2 guests