key dll issues: calls and structs

Get help with using AutoHotkey and its commands and hotkeys
User avatar
jeeswg
Posts: 6718
Joined: 19 Dec 2016, 01:58
Location: UK

Re: key dll issues: calls and structs

11 Jan 2017, 22:41

I've been doing tests by building structures:
I am getting the same sizeof values for x64 and x32,
(although I am getting correct individual parameter size values e.g. for HICON 8/4 (x64/x32),)
which suggests that the x64 exe is using x32 alignment rules:

NOTE: I think I'm starting to understand 1/2/4/8-byte structs, but sizes like 3/6/10/16 are presenting further difficulties (see the code at the bottom).

[updated: 2017-01-23]
EXAMPLE STRUCT SIZES WHEN PARAMETERS OF SPECIFIC SIZES ARE CHOSEN
with a C++ code example
e.g.
CHAR (1), SHORT (2), INT (4), INT64 (8),
ITEMIDLIST (3), ACCEL (6), PANOSE (10), RECT (16)

Code: Select all

==================================================
e.g. C++ code (cpp code):

#define UNICODE 1
#include <iostream>
#include <windows.h>
#include <Winuser.h>
// #include <CommCtrl.h>
// #include <Richedit.h>
#include <Shlwapi.h>
// #include <WinInet.h>
// #include <TlHelp32.h>
// #include <ShlObj.h>
// #include <DbgHelp.h>
// #include <In6addr.h>

struct MYSTRUCT {
CHAR v1;
SHORT v2;
INT v3;
INT64 v4;
RECT v5;
};

int main()
{
	std::cout << sizeof(MYSTRUCT) << std::endl;
	return 0;
}
==================================================

;alignment and padding for structs in x32

1	CHAR [1]
2	SHORT [2]
4	INT [4]
8	INT64 [8]

3	ITEMIDLIST [3] ;#include <Shlwapi.h>
6	ACCEL [6]
10	PANOSE [10]
16	RECT [16]

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

3	CHAR CHAR CHAR [1 1 1]
4	SHORT CHAR [2 1(+1)]
4	SHORT CHAR CHAR [2 1 1]
6	SHORT CHAR SHORT [2 1(+1) 2]
4	CHAR SHORT [1(+1) 2]
6	CHAR SHORT CHAR [1(+1) 2 1(+1)]
20	INT INT INT INT INT [4 4 4 4 4]
24	INT INT INT INT INT CHAR [4 4 4 4 4 1(+3)]
24	INT INT INT INT INT CHAR CHAR CHAR CHAR [4 4 4 4 4 1 1 1 1]
28	INT INT INT INT INT CHAR CHAR CHAR CHAR CHAR [4 4 4 4 4 1 1 1 1 1(+3)]
16	INT INT64 [4(+4) 8]
24	INT INT64 INT64 [4(+4) 8 8]
16	INT64 INT [8 4(+4)]
24	INT64 INT INT64 [8 4(+4) 8]
16	INT64 INT INT [8 4 4]
16	CHAR SHORT INT INT64 [1(+1) 2 4 8]
16	INT64 INT SHORT CHAR [8 4 2 1(+1)]

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

20	INT RECT [4 16]
24	INT RECT INT [4 16 4]
28	INT RECT INT INT [4 16 4 4]
32	INT RECT INT INT INT [4 16 4 4 4]
36	INT RECT INT INT INT INT [4 16 4 4 4 4]
32	INT RECT INT64 [4(+4) 16 8]
40	INT RECT INT64 INT64 [4(+4) 16 8 8]
48	INT RECT INT64 INT64 INT [4(+4) 16 8 8 4(+4)]
48	INT RECT INT64 INT64 INT INT [4(+4) 16 8 8 4 4]
48	INT RECT INT64 INT64 INT64 [4(+4) 16 8 8 8]
24	INT64 RECT [8 16]
24	RECT INT64 [16 8]
32	CHAR SHORT INT INT64 RECT [1(+1) 2 4 8 16]
32	RECT INT64 INT SHORT CHAR [16 8 4 2 1(+1)]

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

2	CHAR CHAR [1 1]
4	SHORT CHAR [2 1(+1)]
4	ITEMIDLIST CHAR [3 1]
8	INT CHAR [4 1(+3)]
8	ACCEL CHAR [6 1(+1)] ACCEL wants overall struct size 2n?
16	INT64 CHAR [8 1(+7)]
11	PANOSE CHAR [10 1] PANOSE wants overall struct size n?
20	RECT CHAR [16 1(+3)] RECT wants overall struct size 4n?

4	CHAR SHORT [1(+1) 2]
4	SHORT SHORT [2 2]
6	ITEMIDLIST SHORT [3(+1) 2]
8	INT SHORT [4 2(+2)]
8	ACCEL SHORT [6 2]
16	INT64 SHORT [8 2(+6)]
12	PANOSE SHORT [10 2]
20	RECT SHORT [16 2(+2)] RECT wants overall struct size 4n?

4	CHAR ITEMIDLIST [1 3]
6	SHORT ITEMIDLIST [2 3(+1)]
6	ITEMIDLIST ITEMIDLIST [3 3]
8	INT ITEMIDLIST [4 3(+1)]
10	ACCEL ITEMIDLIST [6 3(+1)] ACCEL wants overall struct size 2n?
16	INT64 ITEMIDLIST [8 3(+5)]
13	PANOSE ITEMIDLIST [10 3]
20	RECT ITEMIDLIST [16 3(+1)] RECT wants overall struct size 4n?

8	CHAR INT [1(+3) 4]
8	SHORT INT [2(+2) 4]
8	ITEMIDLIST INT [3(+1) 4]
8	INT INT [4 4]
12	ACCEL INT [6(+2) 4]
16	INT64 INT [8 4(+4)]
16	PANOSE INT [10(+2) 4]
20	RECT INT [16 4]

8	CHAR ACCEL [1(+1) 6] ACCEL wants start 2n?
8	SHORT ACCEL [2 6]
10	ITEMIDLIST ACCEL [3(+1) 6]
12	INT ACCEL [4 6(+2)]
12	ACCEL ACCEL [6 6]
16	INT64 ACCEL [8 6(+2)]
16	PANOSE ACCEL [10 6]
24	RECT ACCEL [16 6(+2)]

16	CHAR INT64 [1(+7) 8]
16	SHORT INT64 [2(+6) 8]
16	ITEMIDLIST INT64 [3(+5) 8]
16	INT INT64 [4(+4) 8]
16	ACCEL INT64 [6(+2) 8]
16	INT64 INT64 [8 8]
24	PANOSE INT64 [10(+6) 8]
24	RECT INT64 [16 8]

11	CHAR PANOSE [1 10] PANOSE wants start n?
12	SHORT PANOSE [2 10]
13	ITEMIDLIST PANOSE [3 10]
16	INT PANOSE [4 10(+2)]
16	ACCEL PANOSE [6 10]
24	INT64 PANOSE [8 10(+6)]
20	PANOSE PANOSE [10 10]
28	RECT PANOSE [16 10(+2)]

20	CHAR RECT [1(+3) 16]
20	SHORT RECT [2(+2) 16]
20	ITEMIDLIST RECT [3(+1) 16]
20	INT RECT [4 16]
24	ACCEL RECT [6(+2) 16]
24	INT64 RECT [8 16]
28	PANOSE RECT [10(+2) 16]
32	RECT RECT [16 16]

==================================================
2 more useful links found by using multiple struct names as search keywords:

[lots of struct details]
Structure.htm
http://tokovalue.jp/Structure.htm

[lots of struct/parameter names]
winwords.txt
http://katahiromz.web.fc2.com/win32/winwords.txt

[EDIT]
Please see my previous post which considers:

c++ - Why does the structure size differ in 32-bit and 64-bit program? - Stack Overflow
http://stackoverflow.com/questions/2783 ... it-program

Windows aligns doubles on 8 byte boundaries, even on 32 bit machines.

c++ - Double alignment - Stack Overflow
http://stackoverflow.com/questions/1110 ... -alignment

Windows uses 64-bit alignment of double values even in 32-bit mode
Last edited by jeeswg on 22 Jan 2017, 22:48, edited 5 times in total.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
jeeswg
Posts: 6718
Joined: 19 Dec 2016, 01:58
Location: UK

Re: key dll issues: calls and structs

13 Jan 2017, 16:15

After checking 66 dll functions relating to creating GUIs:

what do P/LP/LPC mean? (pointer + long pointer?)
(via sizeof, all 3 always seems to be pointer-sized i.e. 8 or 4 bytes)
e.g. parameters of the form P'STRUCT' LP'STRUCT' LPC'STRUCT', e.g. PMENUBARINFO
[EDIT:] In LP/LPC, most likely P is pointer, C is constant, see:
Windows Data Types (Windows)
https://msdn.microsoft.com/en-gb/librar ... s.85).aspx

what is const (constant?)
e.g. what is its significance here:
RtlMoveMemory routine (Windows Drivers)
https://msdn.microsoft.com/en-us/librar ... s.85).aspx

if no parameter type is specified,
do you assume Int or Ptr or something else?
e.g.
LOGFONTA structure (Windows)
https://msdn.microsoft.com/en-us/librar ... s.85).aspx
LOGFONTW structure (Windows)
https://msdn.microsoft.com/en-us/librar ... s.85).aspx

what is the parameter type for WINOLEAPI, is it int?
CreateStreamOnHGlobal function (Windows)
https://msdn.microsoft.com/en-us/librar ... s.85).aspx
com - What is the C# data type for WINOLEAPI? - Stack Overflow
http://stackoverflow.com/questions/4921 ... -winoleapi
pinvoke.net: createstreamonhglobal (ole32)
http://www.pinvoke.net/default.aspx/ole ... monhglobal

should the parameter types LOGFONT, SHFILEINFO, WNDCLASS here
actually start with L/LP/LPC or end with *?
CreateFontIndirect function (Windows)
https://msdn.microsoft.com/en-us/librar ... s.85).aspx
SHGetFileInfo function (Windows)
https://msdn.microsoft.com/en-us/librar ... s.85).aspx
RegisterClass function (Windows)
https://msdn.microsoft.com/en-us/librar ... s.85).aspx

I have been retrieving parameter lists by downloading and parsing structs from html,
is it possible to reliably parse these structs (so far it has been around 95% accurate)?
e.g. to parse this struct and retrieve 'VOID VOID SIZE_T (VOID)':
(can you put a struct into C++ and output the parameter type names?)
RtlMoveMemory routine (Windows Drivers)
https://msdn.microsoft.com/en-us/librar ... s.85).aspx

Thanks for reading!!

Btw, my current parameter lookup table:
where '?' means the parameter is probably correct,
and '??' means there is some uncertainty or issue.
Note: it is often possible to confirm that a parameter
is Ptr-sized (i.e. Ptr or UPtr) by using C++ and sizeof in x32 and x64,
but there is then uncertainty over which one.

Btw 2: please upvote my questions on Stack Overflow,
to restore my question-asking privileges there,
so that I can ask about dll/struct issues etc there also!
At the moment I can only ask a question there every SIX MONTHS!
http://stackoverflow.com/users/6437863/ ... sort=votes

Code: Select all

;parameter types MSDN to AHK
HALF_PTR=Int(64)/Short(32)
PHALF_PTR=Int(64)/Short(32)
PUHALF_PTR=UInt(64)/UShort(32)
UHALF_PTR=UInt(64)/UShort(32)
TBYTE=UShort(U)/UChar(A)
TCHAR=UShort(U)/Char(A)
ATOM=UShort
BOOL=Int
BOOLEAN=UChar
BYTE=UChar
CCHAR=Char
CHAR=Char
COLORREF=UInt
DWORD=UInt
DWORDLONG=Int64
DWORD_PTR=UPtr
DWORD32=UInt
DWORD64=Int64
FLOAT=Float
HACCEL=Ptr
HANDLE=Ptr
HBITMAP=Ptr
HBRUSH=Ptr
HCOLORSPACE=Ptr
HCONV=Ptr
HCONVLIST=Ptr
HCURSOR=Ptr
HDC=Ptr
HDDEDATA=Ptr
HDESK=Ptr
HDROP=Ptr
HDWP=Ptr
HENHMETAFILE=Ptr
HFILE=Int
HFONT=Ptr
HGDIOBJ=Ptr
HGLOBAL=Ptr
HHOOK=Ptr
HICON=Ptr
HINSTANCE=Ptr
HKEY=Ptr
HKL=Ptr
HLOCAL=Ptr
HMENU=Ptr
HMETAFILE=Ptr
HMODULE=Ptr
HMONITOR=Ptr
HPALETTE=Ptr
HPEN=Ptr
HRESULT=Int
HRGN=Ptr
HRSRC=Ptr
HSZ=Ptr
HWINSTA=Ptr
HWND=Ptr
INT=Int
INT_PTR=Ptr
INT8=Char
INT16=Short
INT32=Int
INT64=Int64
LANGID=UShort
LCID=UInt
LCTYPE=UInt
LGRPID=UInt
LONG=Int
LONGLONG=Int64
LONG_PTR=Ptr
LONG32=Int
LONG64=Int64
LPARAM=Ptr
LPBOOL=Ptr
LPBYTE=Ptr
LPCOLORREF=Ptr
LPCSTR=Ptr
LPCTSTR=Ptr
LPCVOID=Ptr
LPCWSTR=Ptr
LPDWORD=Ptr
LPHANDLE=Ptr
LPINT=Ptr
LPLONG=Ptr
LPSTR=Ptr
LPTSTR=Ptr
LPVOID=Ptr
LPWORD=Ptr
LPWSTR=Ptr
LRESULT=Ptr
PBOOL=Ptr
PBOOLEAN=Ptr
PBYTE=Ptr
PCHAR=Ptr
PCSTR=Ptr
PCTSTR=Ptr
PCWSTR=Ptr
PDWORD=Ptr
PDWORDLONG=Ptr
PDWORD_PTR=Ptr
PDWORD32=Ptr
PDWORD64=Ptr
PFLOAT=Ptr
PHANDLE=Ptr
PHKEY=Ptr
PINT=Ptr
PINT_PTR=Ptr
PINT8=Ptr
PINT16=Ptr
PINT32=Ptr
PINT64=Ptr
PLCID=Ptr
PLONG=Ptr
PLONGLONG=Ptr
PLONG_PTR=Ptr
PLONG32=Ptr
PLONG64=Ptr
POINTER_32=Int
POINTER_64=Int64
POINTER_SIGNED=Ptr
POINTER_UNSIGNED=UPtr
PSHORT=Ptr
PSIZE_T=Ptr
PSSIZE_T=Ptr
PSTR=Ptr
PTBYTE=Ptr
PTCHAR=Ptr
PTSTR=Ptr
PUCHAR=Ptr
PUINT=Ptr
PUINT_PTR=UPtr
PUINT8=Ptr
PUINT16=Ptr
PUINT32=Ptr
PUINT64=Ptr
PULONG=Ptr
PULONGLONG=Ptr
PULONG_PTR=UPtr
PULONG32=Ptr
PULONG64=Ptr
PUSHORT=Ptr
PVOID=Ptr
PWCHAR=Ptr
PWORD=Ptr
PWSTR=Ptr
QWORD=Int64
SC_HANDLE=Ptr
SC_LOCK=Ptr
SERVICE_STATUS_HANDLE=Ptr
SHORT=Short
SIZE_T=UPtr
SSIZE_T=Ptr
UCHAR=UChar
UINT=UInt
UINT_PTR=UPtr
UINT8=UChar
UINT16=UShort
UINT32=UInt
UINT64=Int64
ULONG=UInt
ULONGLONG=Int64
ULONG_PTR=UPtr
ULONG32=UInt
ULONG64=Int64
USHORT=UShort
USN=Int64
VOID=Ptr
WCHAR=UShort
WORD=UShort
WPARAM=UPtr
LPSECURITY_ATTRIBUTES=?Ptr
HOOKPROC=?Ptr
LPDRAWTEXTPARAMS=?Ptr
LPGLYPHSET=?Ptr
LPPOINT=?Ptr
LPRECT=?Ptr
LPSIZE=?Ptr
LPSTREAM=?Ptr
PMENUBARINFO=?Ptr
PNOTIFYICONDATA=?Ptr
LOGFONT=??Ptr
SHFILEINFO=??Ptr
WNDCLASS=??Ptr
const=ERROR
WINOLEAPI=ERROR
Last edited by jeeswg on 18 Feb 2017, 21:31, edited 1 time in total.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
just me
Posts: 6486
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: key dll issues: calls and structs

13 Jan 2017, 17:16

if no parameter type is specified,
do you assume Int or Ptr or something else?
e.g.
LOGFONTA structure (Windows)
Which types are you missing?
User avatar
jeeswg
Posts: 6718
Joined: 19 Dec 2016, 01:58
Location: UK

Re: key dll issues: calls and structs

13 Jan 2017, 17:28

At the MSDN links for LOGFONTA/LOGFONTW above, for some of the parameters, types are not specified, the column is blank.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
kon
Posts: 1756
Joined: 29 Sep 2013, 17:11

Re: key dll issues: calls and structs

13 Jan 2017, 17:55

They are LONGs, but they are only listed in the 'Members' section.
Not sure why they are omitted from the struct.

Edit: Followed the links in 'Remarks' and found this: https://msdn.microsoft.com/en-us/librar ... s.85).aspx
User avatar
jeeswg
Posts: 6718
Joined: 19 Dec 2016, 01:58
Location: UK

Re: key dll issues: calls and structs

13 Jan 2017, 18:01

Thank you, I found that page also. However, the question remains if there is a convention, for what happens when the parameter is blank, and more specifically what does C++ do when the parameter is blank ... in fact I'll double-check that now.

[EDIT:]
Running by command line, when I tried to leave a blank parameter, the compiling failed.
When I try to run it via Visual Studio, it isn't working nor are my other working scripts!?
The x32 mode returned the blanks as size 4 I believe
(this could be wrong, it might have failed or the given a different number),
however, I cannot test this on x64 anyhow, to see if it treats
blanks as Ptr-sized (8 or 4), or Int-sized (4).
I have an x64 PC, but I believe Visual Studio is only installed in x32 mode,
I don't know if there's an x64 mode available, or if a reinstall/secondary install
is required.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
just me
Posts: 6486
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: key dll issues: calls and structs

14 Jan 2017, 05:04

The MSDN docs aren't always correct.
LOGFONTA structure wrote:Header Dimm.h
Dimm.h wrote:

Code: Select all

typedef /* [public][public][public][public][public][public][public] */ struct __MIDL___MIDL_itf_dimm_0000_0000_0003
    {
    LONG lfHeight;
    LONG lfWidth;
    LONG lfEscapement;
    LONG lfOrientation;
    LONG lfWeight;
    BYTE lfItalic;
    BYTE lfUnderline;
    BYTE lfStrikeOut;
    BYTE lfCharSet;
    BYTE lfOutPrecision;
    BYTE lfClipPrecision;
    BYTE lfQuality;
    BYTE lfPitchAndFamily;
    CHAR lfFaceName[ 32 ];
    } 	LOGFONTA;
User avatar
jeeswg
Posts: 6718
Joined: 19 Dec 2016, 01:58
Location: UK

Re: key dll issues: calls and structs

20 Jan 2017, 01:52

Some simple mathematics, useful for struct sizes:
the size of TVITEM is 56:40 (x64:x32)
so in a script you could write:
vSize := (A_PtrSize=8) ? 56:40
the same result can be achieved by the more succinct:
vSize := 24+4*A_PtrSize

What you do is you keep taking 8 from the 64-bit size,
and 4 from the 32-bit size, until you reach the same number:
0) 56 40
1) 48 36
2) 40 32
3) 32 28
4) 24 24
thus since 4 subtractions were required:
vSize := 24+4*A_PtrSize

Code: Select all

q::
vNum := "56:40"
StringSplit, vNum, vNum, :

Loop, 100000
{
	if (vNum1 = vNum2)
	{
		vCount := A_Index-1
		break
	}
	vNum1 -= 8, vNum2 -= 4
}

if (vCount = 0)
	Clipboard := "vSize := " vNum1
else
	Clipboard := "vSize := " vNum1 "+" vCount "*A_PtrSize"
MsgBox, % Clipboard
return
Last edited by jeeswg on 02 Apr 2017, 21:34, edited 1 time in total.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
jeeswg
Posts: 6718
Joined: 19 Dec 2016, 01:58
Location: UK

Re: key dll issues: calls and structs

22 Jan 2017, 22:39

Above on post 21, the first post on this page,
I created:
'EXAMPLE STRUCT SIZES WHEN PARAMETERS OF SPECIFIC SIZES ARE CHOSEN'

where I created artificial structs with different combinations of:
CHAR (1), SHORT (2), INT (4), INT64 (8),
ITEMIDLIST (3), ACCEL (6), PANOSE (10), RECT (16)
and retrieved the sizeof values to try and work out what the patterns were.
Well I think I've worked out what those patterns are:

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

RULES FOR STRUCTS? (32-bit and 64-bit)
I believe that these are the rules for structs (32-bit, and also possibly 64-bit),
for padding and alignment:

Each parameter of size n, has a special 'multiple number',
(a 'placement number' which is also an 'overall struct size number')
which we can call 'm':

e.g. a RECT parameter, must start at a multiple of 4: e.g. 0, 4, 8, 12, 16, 20
and any struct that contains a RECT must be padded so that its overall size is a multiple of 4,
thus the 'multiple number' for a RECT is 4.

Code: Select all

size / 'multiple number' / e.g. parameter of that size
1	1	CHAR wants an overall struct size 1n (any size) [wants to start at 1p (anywhere)]
2	2	SHORT wants an overall struct size 2n [wants to start at 2p]
(3)	1	ITEMIDLIST wants an overall struct size 1n (any size) [wants to start at 1p (anywhere)]
4	4	INT wants an overall struct size 4n [wants to start at 4p]
(6)	2	ACCEL wants an overall struct size 2n [wants to start at 2p]
8	8	INT64 wants an overall struct size 8n [wants to start at 8p]
(10)	1	PANOSE wants an overall struct size 1n (any size) [wants to start at 1p (anywhere)]
(16)	4	RECT wants an overall struct size 4n [wants to start at 4p]
I believe, but am not definite, that the only difference between 32-bit and 64-bit structs,
is that some of the size 4 parameters are replaced with size 8 parameters,
resulting in bigger structs, but with the EXACT SAME rules of alignment/padding.

My remaining concern is the mathematical relationship between
the size n of a parameter and 'm', its 'multiple number'.

===============
Last edited by jeeswg on 22 Jan 2017, 23:12, edited 1 time in total.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
jeeswg
Posts: 6718
Joined: 19 Dec 2016, 01:58
Location: UK

Re: key dll issues: calls and structs

22 Jan 2017, 23:10

I believe that this should work:

To work out the 'multiple number', 'm', for a parameter 'PARAM',
create a struct with 2 parameters: 'PARAM CHAR',
and then m will be the struct size take away the size of PARAM.

Code: Select all

size	struct			'multiple number'
2	CHAR CHAR [1 1]		2-1 = 1
4	SHORT CHAR [2 1(+1)]	4-2 = 2
4	ITEMIDLIST CHAR [3 1]	4-3 = 1
8	INT CHAR [4 1(+3)]	8-4 = 4
8	ACCEL CHAR [6 1(+1)]	8-6 = 2
16	INT64 CHAR [8 1(+7)]	16-8 = 8
11	PANOSE CHAR [10 1]	11-10 = 1
20	RECT CHAR [16 1(+3)]	20-16 = 4

parameter sizes:
CHAR (1), SHORT (2), INT (4), INT64 (8),
ITEMIDLIST (3), ACCEL (6), PANOSE (10), RECT (16)
[EDIT:]
If the rules I established are correct, then if you have some parameters in a struct,
and you know their sizes and 'multiple numbers', then you could
do a sizeof and return the offsets needed for each parameter in the struct.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
just me
Posts: 6486
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: key dll issues: calls and structs

23 Jan 2017, 05:44

In case you didn't find this link as yet: Structure Alignment
User avatar
jNizM
Posts: 2503
Joined: 30 Sep 2013, 01:33
GitHub: jNizM
Contact:

Re: key dll issues: calls and structs

23 Jan 2017, 05:57

You can find many useful links here under references -> https://autohotkey.com/boards/viewtopic.php?p=44472
[AHK] 1.1.30.03 x64 Unicode | [WIN] 10 Pro (Version 1903) x64 | [GitHub] Profile
Donations are appreciated if I could help you
User avatar
jeeswg
Posts: 6718
Joined: 19 Dec 2016, 01:58
Location: UK

Re: key dll issues: calls and structs

23 Jan 2017, 11:04

@jNizM: Very good selection of links, thanks so much.

@just me: Thanks, that is a good link.
It doesn't make it clear if it's relevant to 32-bit/64-bit,
or what happens with the parameter size isn't 1/2/4/8!

Not sure what the '/Zp option' or '#pragma pack' is all about,
I had wondered if there was a way to set different packing options.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
just me
Posts: 6486
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: key dll issues: calls and structs

23 Jan 2017, 12:05

There's no difference between 32-bit and 64-bit default rules. The most important difference is the size of pointer-sized data types like pointers or handles. It's 4 bytes for 32-bit and 8 bytes for 64-bit.

Also, if structures contains strings (not string pointers) as TCHARs, the size is different for the ANSI and Unicode versions.

The size of plain data types is 1, 2, 4, or 8 bytes. For other sizes you need an array or a structure.

'/Zp option' or '#pragma pack' are used to override the default rules. Also, things like #include <pshpack1.h>. As an example from shtypes.h

Code: Select all

#include <pshpack1.h>
typedef struct _SHITEMID
    {
    USHORT cb;
    BYTE abID[ 1 ];
    } 	SHITEMID;

#include <poppack.h>
which enables byte packing for the SHITEMID structure and restores the previous packing mode afterwards. In many cases I found in the Windows header files the different packing options are only used for 32-bit.
BTW: The size of a SHITEMID structure is variable. It's 2 (USHORT) + cb bytes.

All clear now? ;)
User avatar
jeeswg
Posts: 6718
Joined: 19 Dec 2016, 01:58
Location: UK

Re: key dll issues: calls and structs

23 Jan 2017, 12:20

That's some really good info, many thanks!

[EDIT:]
I think you have given me a clue, that reinforces one of my hunches,
about the rule for parameters with an unusual size, and what their 'multiple number' is,
this basically wraps up everything I wanted to know about dll calls and structs (I think):

ITEMIDLIST (3) would have 'multiple number' 1, if all its parameters are size 1 (complicated, see MSDN, appears to be based on SHITEMID which contains a USHORT, which is 2 bytes in size)
ACCEL (6) would have 'multiple number' 2, if its biggest parameter is size 2 (true)
PANOSE (10) would have 'multiple number' 1, if all its parameters are size 1 (true)
RECT (16) would have 'multiple number' 4, if its biggest parameter is size 4 (true)

Note: this would also suggest that you could have say a parameter of size 4 made up of BYTE parameters, this would then have 'multiple number' 1, and not 4.

Note: there could be parameters that contain parameters that contain parameters ..., this also makes me curious as to whether there is some name for 'standard' parameters versus other parameters.

Note: another point of interest would be if there is an existing term for 'multiple number', and if there is a name for the default alignment rules I have discussed here and above.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

Return to “Ask For Help”

Who is online

Users browsing this forum: Google [Bot] and 210 guests