Is ObjRelease supposed to be equivalent to ComCall(2)? Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
iseahound
Posts: 1444
Joined: 13 Aug 2016, 21:04
Contact:

Is ObjRelease supposed to be equivalent to ComCall(2)?

Post by iseahound » 08 Jul 2021, 10:16

I know that ComCall(2) and ObjRelease both invoke IUnknown::Release, but I'm getting errors with ObjRelease that never happen with ComCall.

Parameter #1 of ObjRelease is invalid.
Specifically: ComValue

While ObjRelease(obj.ptr) does the trick, it's odd because I'm specifically supplying an interface pointer from ComObjQuery.
ObjRelease wrote: (Ptr) An unmanaged object pointer or COM interface pointer.
Last edited by iseahound on 08 Jul 2021, 10:34, edited 1 time in total.

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

Re: Is ObjRelease supposed to be equivalent to ComCall(2)?

Post by iseahound » 08 Jul 2021, 10:32

Code: Select all

req := ComObject("WinHttp.WinHttpRequest.5.1")
req.Open("GET", "https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png")
req.Send()
IStream := ComObjQuery(req.ResponseStream, "{0000000C-0000-0000-C000-000000000046}")
; DllCall("gdiplus\GdipCreateBitmapFromStream", "ptr", IStream, "ptr*", &pBitmap:=0)
;MsgBox ObjRelease(IStream) ; Does not work
;MsgBox ObjRelease(IStream.ptr) ; Works
MsgBox ComCall(2, IStream) ; Works
MsgBox should display 0.

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

Re: Is ObjRelease supposed to be equivalent to ComCall(2)?

Post by iseahound » 08 Jul 2021, 10:43

Note that this issue only affects v2. Equivalent v1 code below.

Code: Select all

req := ComObjCreate("WinHttp.WinHttpRequest.5.1")
req.Open("GET", image)
req.Send()
pStream := ComObjQuery(req.ResponseStream, "{0000000C-0000-0000-C000-000000000046}")
DllCall("gdiplus\GdipCreateBitmapFromStream", "ptr", pStream, "ptr*", pBitmap:=0)
ObjRelease(pStream)

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

Re: Is ObjRelease supposed to be equivalent to ComCall(2)?  Topic is solved

Post by swagfag » 08 Jul 2021, 11:32

yeah, ObjRelease() requires an Integer, while ure trying to pass it IStream which happens to be an object of type ComValue, so u get a type error
the equivalent v2 code is:

Code: Select all

#Requires AutoHotkey v2.0-a138-7538f26f

req := ComObject("WinHttp.WinHttpRequest.5.1")
req.Open("GET", "https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png")
req.Send()
IStream := ComObjQuery(req.ResponseStream, "{0000000C-0000-0000-C000-000000000046}")
DllCall("gdiplus\GdipCreateBitmapFromStream", "ptr", IStream, "ptr*", &pBitmap:=0)
thats it. IStream is automatically released when it goes out of scope(or u overwrite the variable with something else)

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

Re: Is ObjRelease supposed to be equivalent to ComCall(2)?

Post by iseahound » 09 Jul 2021, 12:08

Perhaps the documentation is wrong, and ComObjQuery no longer returns an interface pointer as shown in the yellow box
ComObjQuery wrote: InterfacePointer := ComObjQuery(ComObj, SID, IID)

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

Re: Is ObjRelease supposed to be equivalent to ComCall(2)?

Post by swagfag » 09 Jul 2021, 14:02

it still returns an interface pointer alright. the only difference is, in v2 the pointer is wrapped, while in v1 its not(raw)
https://lexikos.github.io/v2/docs/commands/ComObjQuery.htm#Return_Value does say its gonna be wrapped

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

Re: Is ObjRelease supposed to be equivalent to ComCall(2)?

Post by iseahound » 14 Jul 2021, 16:43

Right, I suppose ObjRelease(ComValue) is releasing the wrapper object itself as opposed to its ptr property.

Post Reply

Return to “Ask for Help (v2)”