WinStructs - Windows Structure definitions for _Struct

Post your working scripts, libraries and tools for AHK v1.1 and older
User avatar
evilC
Posts: 4823
Joined: 27 Feb 2014, 12:30

WinStructs - Windows Structure definitions for _Struct

01 Feb 2015, 14:02

I have started a project under the ahkscript GitHub group as a central repository for definitions of Windows Structures.

With HotkeyIt's excellent _Struct greatly simplifying the process of dealing with the results of DllCall, OnMessage etc, as long as you know how to define the _Struct correctly, it seems wise to have a central repo so we only ever need to correctly transcribe each Structure once ;)

That way, once we build up a decent library, playing around with Windows APIs and Messages becomes a lot more accessible, with less bugs due to incorrect bitwise ops.

GitHub Page
User avatar
joedf
Posts: 8951
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: WinStructs - Windows Structure definitions for _Struct

01 Feb 2015, 14:16

Yes interesting idea!
Image Image Image Image Image
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]
User avatar
evilC
Posts: 4823
Joined: 27 Feb 2014, 12:30

Re: WinStructs - Windows Structure definitions for _Struct

01 Feb 2015, 14:32

Please speak now if you think the name is non-descriptive etc...

I think it works though? I kind of like the allusion to "Instructs" as it would also serve as a reference material, of sorts.

Let me be clear though that I am NOT planning on mass going through Windows and populating this list.
I already have enough huge-scope projects on the boil, I don't need another. This, for me, is more about giving something back to the community after all my API questionings recently ;)

At least then, poor HotkeyIt only gets bugged once about the ins and outs of a particular set of API calls ;)
User avatar
joedf
Posts: 8951
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: WinStructs - Windows Structure definitions for _Struct

01 Feb 2015, 14:36

LibStruct ?
AHKStructs ?
Structs.ahk ?
Image Image Image Image Image
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]
User avatar
evilC
Posts: 4823
Joined: 27 Feb 2014, 12:30

Re: WinStructs - Windows Structure definitions for _Struct

01 Feb 2015, 14:40

joedf wrote:LibStruct ?
Not a lib, just text strings.
joedf wrote:AHKStructs ?
_Struct already has an AHKStructs file for AHK structures, so too confusing.
joedf wrote:Structs.ahk ?
A little too broad maybe?
I think it would be wise to limit the scope to official MS APIs.
If Structs were needed for other APIs, I think they should belong in one project per API. Thoughts?
User avatar
evilC
Posts: 4823
Joined: 27 Feb 2014, 12:30

Re: WinStructs - Windows Structure definitions for _Struct

03 Feb 2015, 09:23

WinStructs now has a new friend!

AHK-SizeOf-Checker
(Requires compiler from Visual Studio)

This library can create and compile C code in order to perform a check that the size of a structure created with _Struct matches the size of the struct in actual C code
ie it checks whether sizeof(SOME_STRUCT) in AHK (ie using the sizeof command that comes with _Struct) equals sizeof(SOME_STRUCT) in a compiled C++ executable (ie using the sizeof() macro in C++)

This way, at least we have some way of vaguely validating that the Struct definitions in WinStructs are correct (And potentially also exposing bugs in _Struct)

Image

So, for example, performing a check on RAWINPUTDEVICE would generate the following C code, compile and execute it:

Code: Select all

#include <iostream>
#include <windows.h>
int main()
{
std::cout << sizeof(RAWINPUTDEVICE) << std::endl;
return 0;
}
Whereas to check HIDP_BUTTON_CAPS, you need to also tell it that HidUsage.h and Hidpi.h are required, which would generate the following code:

Code: Select all

#include <iostream>
#include <windows.h>
#include <HidUsage.h>
#include <Hidpi.h>
int main()
{
std::cout << sizeof(HIDP_BUTTON_CAPS) << std::endl;
return 0;
}
User avatar
evilC
Posts: 4823
Joined: 27 Feb 2014, 12:30

Re: WinStructs - Windows Structure definitions for _Struct

04 Feb 2015, 13:53

IMPORTANT ANNOUNCEMENT

I changed the naming convention back to match exactly as it appears on MSDN.

My rationale, as it appears in the header for the file:
The reasons for this are two-fold.
1) The immediately obvious thing to do is to strip the lower case prefixes, however in some cases this would not be possible.
eg: KBDLLHOOKSTRUCT has vkCode and scanCode - you could not have two properties called "Code".
2) Consistency. Seeing as we cannot achieve consistency by stripping lower case prefixes, the next best solution is to keep them exactly as on MSDN.
Some properties on MSDN have prefixes, some do not. MSDN may not be consistent, be WinStructs is (With MSDN).
Apologies if you were using it for anything and have to make changes, I feel it's best to do it now rather than when it is more painful down the road.
User avatar
evilC
Posts: 4823
Joined: 27 Feb 2014, 12:30

Re: WinStructs - Windows Structure definitions for _Struct

06 Feb 2015, 05:32

I am pleased to announce that it appears HotKeyIt has fixed the issues with _Struct and I am (tentatively) declaring WinStructs to be mature enough to consider using in projects - certainly stable enough to start playing with.

If you are using Windows DLL Calls or OnMessage in existing code, please attempt to convert it to WinStructs. If you need help getting the definitions right, just ask.
The more definitions we get, the more we can be sure _Struct doesn't have any bugs, and with every Structure added to WinStructs, using Windows APIs becomes less and less of an "Advanced" topic.

If you are not using Windows DLL Calls or OnMessage, but are interested, this is a great way to learn. You literally have to just copy and paste some text from the MSDN website, make a few alterations (follow a few simple rules) and you can easily interrogate those results like it were a regular AHK object - No scary NumGet() required! Furthermore, by doing it with WinStructs, as soon as you add the definition, ALL the data becomes visible, so it's quicker and easier to see if you got it right as you have the whole result laid out before you in one fell swoop.

The more structures we add, the more examples there are to copy, the easier subsequent structures become to transpose.
bobc119
Posts: 23
Joined: 10 Jan 2014, 17:02

Re: WinStructs - Windows Structure definitions for _Struct

06 Feb 2015, 21:43

evilC wrote:If you are not using Windows DLL Calls or OnMessage, but are interested, this is a great way to learn. You literally have to just copy and paste some text from the MSDN website, make a few alterations (follow a few simple rules)
I am interested, but how do I use this? A very simple example may help tremendously.

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: No registered users and 128 guests