DllCall which returns a STRUCT

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
paultibb
Posts: 2
Joined: 03 Apr 2018, 14:30

DllCall which returns a STRUCT

Post by paultibb » 27 Jun 2022, 14:32

Hi, All. I've been struggling with this one for a bit now and after quite a bit of searching, I have still not found an answer.

I have the following C function definition which takes two pointers as inputs and returns a structure.

Code: Select all

typedef struct match_result
{
	int success;
	int should_update;
	int score;
} match_result;

match_result match(void* authenticator, void* args);
How do I form the DllCall function to get the result from the returned structure?

Code: Select all

retval := DllCall( "match.dll\match", "Ptr", authenticator, "Ptr", args, "Cdecl ??????")
Thoughts?

Thanks!

iseahound
Posts: 1444
Joined: 13 Aug 2016, 21:04
Contact:

Re: DllCall which returns a STRUCT

Post by iseahound » 27 Jun 2022, 19:54

:( No one seems to be answering your question

Code: Select all

retval := DllCall( "match.dll\match", "Ptr", authenticator, "Ptr", args, "ptr") ; try "cdecl ptr" if this doesn't work.
Then to retrieve your values,

Code: Select all

struct1 := NumGet(retval+0, 0, "int) ; Note the +0 this is AutoHotkey v1 being really dumb.

Descolada
Posts: 1123
Joined: 23 Dec 2021, 02:30

Re: DllCall which returns a STRUCT

Post by Descolada » 28 Jun 2022, 01:13

Try

Code: Select all

match_result := DllCall( "match.dll\match", "Ptr", authenticator, "Ptr", args, "Ptr")
success := NumGet(match_result+0, 0, "Int")
should_update := NumGet(match_result+0, 4, "Int")
score := NumGet(match_result+0, 8, "Int")
And be sure to check out jeeswg's awesome DllCall tutorial ;)

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: DllCall which returns a STRUCT

Post by swagfag » 28 Jun 2022, 02:13

Code: Select all

VarSetCapacity(match_result, 12)
pmatch_result := DllCall( "match.dll\match", "Ptr", &match_result, "Ptr", authenticator, "Ptr", args, "CDecl Ptr")
success := NumGet(match_result, 0, "Int")
should_update := NumGet(match_result, 4, "Int")
score := NumGet(match_result, 8, "Int")

paultibb
Posts: 2
Joined: 03 Apr 2018, 14:30

Re: DllCall which returns a STRUCT

Post by paultibb » 28 Jun 2022, 07:44

Thank you all for the thoughtful responses.

You win, @swagfag. Is this documented anywhere?

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: DllCall which returns a STRUCT

Post by swagfag » 28 Jun 2022, 08:34

probably, on some page somewhere in the C ANSI standard

lexikos
Posts: 9583
Joined: 30 Sep 2013, 04:07
Contact:

Re: DllCall which returns a STRUCT

Post by lexikos » 28 Jun 2022, 22:25

It's a detail of the x86/64 calling convention, not the C standard. I think I've posted about it before, in more detail.

Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: DllCall which returns a STRUCT

Post by Helgef » 29 Jun 2022, 03:36

There was a related discussion, with links, which might be interesting for reference. See :arrow: Passing structure to function.

Cheers.

Post Reply

Return to “Ask for Help (v1)”