This will not work with output variables (there is no really good solution for that).
What are you referring to?
V1 comobjs have no ptr property if I'm not mistaken, I guess you could use comobjvalue instead.
Yes, I meant to relook at this. So ...
Code: Select all
Ptr := IsObject(ComObject) ? ComObject.Ptr : ComObject ;current
Ptr := IsObject(ComObject) ? ComObjValue(ComObject) : ComObject ;your proposal?
Ptr := IsObject(ComObject) ? ComObject(ComObject) : ComObject ;best?
The documentation suggests that ComObject would be better than ComObjValue. Do you agree?
Links:
ComObjValue - Syntax & Usage | AutoHotkey v2
https://lexikos.github.io/v2/docs/commands/ComObjValue.htm
ComObject - Syntax & Usage | AutoHotkey v2
https://lexikos.github.io/v2/docs/commands/ComObject.htm
I would wrap the call to dllcall in try-catch-throw to catch misc. errors which are otherwise silent in v1, but throws in v2.
Do you have any examples of code that would cause such errors.
So I can test it in AHK v2, and copy the error message text.
Minor, comcall will throw if you explicitly specify the return type to hresult and it returns an error code.
I didn't consider that a user would want to specify HRESULT as the return type in AHK v1.
Here's a fix:
Code: Select all
ComCall(Index, ComObject, Params*)
{
local IsHResult, Ptr, Result
Ptr := IsObject(ComObject) ? ComObject.Ptr : ComObject
IsHResult := !(Params.Length() & 1) ;if even number, return type is HRESULT
if (Params.Length() & 1)
&& (Params[Params.Length()] = "HRESULT")
Params.Pop(), IsHResult := 1
Result := DllCall(NumGet(NumGet(Ptr+0)+Index*A_PtrSize), "Ptr",Ptr, Params*)
if IsHResult && (Result < 0)
throw Exception("", -1, Result)
return Result
}
Does this address the problem you mentioned?
Also note that cdecl is allowed for comcall.
Cdecl would appear in the return type.
The return type is omitted or is the last parameter in Params.
Is there some significance re. Cdecl I'm missing?
Thanks for your comments.