The safecall
calling safecall
is simply a HResult
return type HResult
. If the function returns a failure (something other than S_OK
or S_False
, as a rule), it throws an exception and throws it (or turns into a reSafeCallError
time error if SysUtils is not used anywhere). See System._CheckAutoResult
.
Similarly, if you implement the safecall function, any exception is caught and converted to the value HResult
( E_Unexpected
, unless TObject.SafeCallException
is redefined to return something else). See System._HandleAutoException
how this works.
You can return the procedure back to the function returning HResult
if you want. The calling convention in this case should be stdcall
. Using your example:
function DoSomething(const id: WideString; State: Integer): HResult; stdcall;
source share