ObjRelease needed when using ComObjValue+ObjAddRef?
Posted: 09 Oct 2014, 22:24
I was trying to modify jethrow's IsMemberOf function to make it more future-proof. So the question is, do I need to call ObjRelease for pDisp.? Sean (and Lexikos) did mention to release the unwrapped pointer however as per AHK docs:
Here is the function:Docs(ComObjValue) wrote:For instance, if an interface pointer is returned, Release should not be called, but AddRef may be required depending on what the script does with the pointer.
source: ComObjValue
Code: Select all
IsMemberOf(obj, name)
{
pDisp := ComObjValue(obj), ObjAddRef(pDisp) ;// ComObjUnwrap()
GetIDsOfNames := NumGet(NumGet(pDisp + 0), 5*A_PtrSize)
VarSetCapacity(IID_NULL, 16, 0)
r := DllCall(GetIDsOfNames, "Ptr", pDisp, "Ptr", &IID_NULL, "Ptr*", &name, "UInt", 1, "UInt", 1024, "Int*", DISPID)
ObjRelease(pDisp) ;// needed??
return (r == 0) && (DISPID + 1)
}