Is there a built-in way in AHK to obtain the size of a given data type, like "int", "short", "float", "ptr", etc. ?
If not, I suppose we could write it by hand.
Are those data types always the same size independently of the version of AHK (32 or 64 bits)?
Is "int" always 4 bytes?
What about "ptr"?
In 32-bit it's 4 bytes, but in 64-bit I believe it's 8 bytes.
Getting the size of a data type
- LinearSpoon
- Posts: 156
- Joined: 29 Sep 2013, 22:55
Re: Getting the size of a data type
char: 1
short: 2
int: 4
int64: 8
float: 4
double: 8
ptr: A_PtrSize (built in variable)
Unsigned types are the same size as above, the only difference is that they represent a different range of values. These aren't going to change since AHK defines their sizes. Presumably if there is ever a 128 bit version of AHK, something like "int128" would be added, or whatever a suitable alternative name would be.
short: 2
int: 4
int64: 8
float: 4
double: 8
ptr: A_PtrSize (built in variable)
Unsigned types are the same size as above, the only difference is that they represent a different range of values. These aren't going to change since AHK defines their sizes. Presumably if there is ever a 128 bit version of AHK, something like "int128" would be added, or whatever a suitable alternative name would be.
Re: Getting the size of a data type
How does this affect DllCall in 32 vs 64 bit ??
When a DLL function takes as input an Integer, is it up to us to detect whether we are in a 32 or 64 bit environment and give the appropriate "int" or "int64" ?
Also, what happens in the case when you have to pass a pointer to a structure of integers.
For example the RECT structure which has 4 longs.
Do we have to detect the word size of the OS and use "int" or "int64" accordingly when calling NumPut?
When a DLL function takes as input an Integer, is it up to us to detect whether we are in a 32 or 64 bit environment and give the appropriate "int" or "int64" ?
Also, what happens in the case when you have to pass a pointer to a structure of integers.
For example the RECT structure which has 4 longs.
Do we have to detect the word size of the OS and use "int" or "int64" accordingly when calling NumPut?
Re: Getting the size of a data type
No Int will always be Int sized.When a DLL function takes as input an Integer, is it up to us to detect whether we are in a 32 or 64 bit environment and give the appropriate "int" or "int64" ?
If an Int changes it size from 32 to 64 bit on the corresponding system it is a pointer so can just use Ptr.
Sadly structures change heavily from 32 to 64 bit.Also, what happens in the case when you have to pass a pointer to a structure of integers.
http://en.wikipedia.org/wiki/Data_structure_alignment
This Code works for both 64 and 32 bit:Also, what happens in the case when you have to pass a pointer to a structure of integers.
For example the RECT structure which has 4 longs.
Code: Select all
VarSetCapacity(RECT,16)
Loop 4
NumPut(A_Index,RECT,A_Index*4-4,"Int")
DllCall(Rectfunc,"Ptr",&RECT)
The Word size is the Ptr size therefore you can use Ptr in that case.Do we have to detect the word size of the OS and use "int" or "int64" accordingly when calling NumPut?
Recommends AHK Studio
Re: Getting the size of a data type
Thanks for your answers, nnnik and HotKeyIt.
If I undestood all correctly, I can conclude the following:
If I undestood all correctly, I can conclude the following:
- The only variable-sized data type in the Windows API is the pointer type. All other primitive types are always the same size irrespectively of the system's word size , as shown here: http://msdn.microsoft.com/en-us/library ... 83751.aspx
- The size and layout of structures are only affected if they contain pointers (handles, addresses, etc.), in which case the global constant A_PtrSize holds the size of pointers for the current environment.
Re: Getting the size of a data type
There is alsoGetfree wrote:The only variable-sized data type in the Windows API is the pointer type.
- TCHAR,TBYTE, Ansi 1 Byte / Unicode 2 Bytes A_IsUnicode+1Script Compatibility wrote:; 8-bit/ANSI strings: size_of_char=1 type_of_char="Char"
; 16-bit/UTF-16 strings: size_of_char=2 type_of_char="UShort" - HALF_PTR WORD on 32-bit and INT on 64-bit A_PtrSize/2
Re: Getting the size of a data type
Here is a list Bentschi did
Data type <--> AHK type
Data type <--> AHK type
[AHK] v2.0.5 | [WIN] 11 Pro (Version 22H2) | [GitHub] Profile
Re: Getting the size of a data type
Here are some corrections including String types AStr, WStr, Str:
BOOL uint INT
HRESULT ptr INT
LANGID short USHORT
LPCSTR ptr ASTR
LPCTSTR ptr STR
LPCWSTR ptr WSTR
LPSTR ptr ASTR
LPTSTR ptr STR
LPWSTR ptr WSTR
LRESULT ptr UINT
PCSTR ptr ASTR
PCTSTR ptr STR
PCWSTR ptr WSTR
PSTR ptr ASTR
PTSTR ptr STR
PWSTR ptr WSTR
WCHAR short USHORT
Re: Getting the size of a data type
Maybe bentschi's page should also be hosted on ahkscript.
@HotKeyIt these changes apply to Bentschi's page?
@HotKeyIt these changes apply to Bentschi's page?
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]
Re: Getting the size of a data type
hosted here: http://ahkscript.org/ursrc/Windows_Data_Types.html
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]
Re: Getting the size of a data type
Referring to WinApi Datatypes:
CALLBACK is not a data type. It is an alias for a keyword which can be applied to a function.
The secondary type listed for LRESULT, "ptr*" is incorrect. It is not a pointer to a pointer sized integer. It is a pointer sized integer (LONG_PTR) with meaning dependent on which message it is used with.
PBOOL's secondary type should be int* rather than uint*, although it won't matter if the value is always TRUE or FALSE.
PDWORDLONG's secondary type should be uint64*, not ushort*.
PDWORD_PTR's and PSIZE_T's secondary type should be uptr*, not ptr*. They are unsigned.
The table row for PDWORD32 has too many columns.
PLCID's secondary type should be uint*, not ptr*.
There are probably other errors, but I've lost interest.
CALLBACK is not a data type. It is an alias for a keyword which can be applied to a function.
CONST is not a data type either, but the list kind of reflects this (the AHK type column is blank).#define CALLBACK __stdcall
The secondary type listed for LRESULT, "ptr*" is incorrect. It is not a pointer to a pointer sized integer. It is a pointer sized integer (LONG_PTR) with meaning dependent on which message it is used with.
PBOOL's secondary type should be int* rather than uint*, although it won't matter if the value is always TRUE or FALSE.
PDWORDLONG's secondary type should be uint64*, not ushort*.
PDWORD_PTR's and PSIZE_T's secondary type should be uptr*, not ptr*. They are unsigned.
The table row for PDWORD32 has too many columns.
PLCID's secondary type should be uint*, not ptr*.
There are probably other errors, but I've lost interest.
Re: Getting the size of a data type
Nothing new (joke =)lexikos wrote:... but I've lost interest.
the more documented (finished) information => its easier to work with
Original Page:
Windows Data Types
Data Type Ranges
[AHK] v2.0.5 | [WIN] 11 Pro (Version 22H2) | [GitHub] Profile
Who is online
Users browsing this forum: Dewi Morgan and 377 guests