DllCall a memory address - what is it doing? pStream and ObjRelease() Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
iseahound
Posts: 1451
Joined: 13 Aug 2016, 21:04
Contact:

DllCall a memory address - what is it doing? pStream and ObjRelease()

08 Nov 2017, 20:35

Code: Select all

DllCall(NumGet(NumGet(pStream + 0, 0, "uptr") + (A_PtrSize * 2), 0, "uptr"), "ptr",pStream)

Code: Select all

DllCall(NumGet(NumGet(1*pStream)+8), "uint", pStream)

Code: Select all

r:=dllcall(numget(numget(p+0)+3*a_ptrsize), "ptr",pStream, "ptr",&b, "uint",8192, "ptr*",c)
There's a few variants, and all of them deal with pointers to stream objects. I've commented it out, and there seems to be no effect. I'm guessing that this is some sort of compatibility code for 32 bit systems.

What is this code doing?

ALso what is the "correct" and "proper" version?
Last edited by iseahound on 24 Nov 2018, 15:12, edited 1 time in total.
User avatar
LinearSpoon
Posts: 156
Joined: 29 Sep 2013, 22:55

Re: DllCall a memory address - what is it doing?

09 Nov 2017, 04:00

I'd guess pStream is pointing to a C++ object which has a vtable. The inner numget loads the vtable address, and the outer numget loads a particular function pointer from the vtable. You can read about virtual tables on wikipedia: https://en.wikipedia.org/wiki/Virtual_method_table

I would prefer the first style, since it should work on either 32 or 64 bit AHK and is the most explicit about types.
iseahound
Posts: 1451
Joined: 13 Aug 2016, 21:04
Contact:

Re: DllCall a memory address - what is it doing?

22 Nov 2018, 16:35

I still have no idea what these DllCall are doing. Here is some context:

Code: Select all

 DllCall( "GlobalUnlock", UInt,hData )
 DllCall( NumGet( NumGet( 1*pStream ) + 8 ), UInt,pStream )
 DllCall( "GlobalFree", UInt,hData )
from https://autohotkey.com/board/topic/8552 ... etobuffer/

Can I replace DllCall( NumGet( NumGet( 1*pStream ) + 8 ), UInt,pStream ) with ObjRelease(pStream)?
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: DllCall a memory address - what is it doing?  Topic is solved

23 Nov 2018, 08:50

Can I replace DllCall( NumGet( NumGet( 1*pStream ) + 8 ), UInt,pStream ) with ObjRelease(pStream)?
The release method would be at offset a_ptrsize*2, so that will call addref on 64 bit. DllCall( NumGet( NumGet( 1*pStream ) + a_ptrsize*2 ), "ptr", pStream ) would be compatible with both 32 and 64. You should call objrelease instead.

Cheers.
iseahound
Posts: 1451
Joined: 13 Aug 2016, 21:04
Contact:

Re: DllCall a memory address - what is it doing? pStream and ObjRelease()

24 Nov 2018, 15:20

Thank you. Am I correct in assuming that the above is legacy code left over from when AutoHotkey did not have ObjRelease() implemented? Also I was recently made aware of the fact that AutoHotkey objects are COM objects, so is there any website/reference to the virtual tables underlying COM objects? Anyways, I really appreciate that a year old question has been answered!

For future readers:
DllCall(NumGet(NumGet(pStream + 0, 0, "uptr") + (A_PtrSize * 2), 0, "uptr"), "ptr",pStream) and DllCall( NumGet( NumGet( 1*pStream ) + a_ptrsize*2 ), "ptr", pStream ) are both are legacy equivalents for ObjRelease(pStream).

Also a question about when to call ObjRelease() before DllCall("GlobalUnlock", "ptr",hData) or after, or it doesn't matter? Also does calling ObjRelease() automatically call GlobalUnlock and GlobalFree if CreateStreamOnHGlobal's second parameter fDeleteOnRelease is true?
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: DllCall a memory address - what is it doing? pStream and ObjRelease()

25 Nov 2018, 06:29

I do not know when objrelease was implemented.
Also does calling ObjRelease() automatically call GlobalUnlock and GlobalFree if CreateStreamOnHGlobal's second parameter fDeleteOnRelease is true?
Objrelease does not call GlobalUnlock or GlobalFree, it calls the Release() method, what the Release() method for this specific object does I do not know.
I guess you could call GlobalSize after objRelease and see if the handle is still valid,
GlobalSize wrote:If the specified handle is not valid or if the object has been discarded, the return value is zero. To get extended error information, call GetLastError.
Cheers.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: DllCall a memory address - what is it doing? pStream and ObjRelease()

25 Nov 2018, 09:23

- I have some info here: INTERFACES: GET METHOD LIST.
jeeswg's objects tutorial - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=7&t=29232
- The first 3 methods for interfaces always seems to be: QueryInterface, AddRef, Release, in that order.

- I found some info for IStream:
IStream | Microsoft Docs
https://docs.microsoft.com/en-gb/window ... dl-istream
- And 'typedef struct IStreamVtbl', here (file available after installing Visual Studio):
C:\Program Files (x86)\Windows Kits\8.1\Include\um\ObjIdl.h

- According to this list, ObjRelease has been available since the first release of AutoHotkey_L (AHK v1.1). It was not available in AutoHotkey Basic (last version: v1.0.48.05).
list of every command/function/variable from across all versions - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 42#p131642
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
iseahound
Posts: 1451
Joined: 13 Aug 2016, 21:04
Contact:

Re: DllCall a memory address - what is it doing? pStream and ObjRelease()

25 Nov 2018, 21:32

Great information! Thanks for the help Helgef and jeeswg.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], mikeyww, Spawnova and 350 guests