function QueryInterface(const IID: TGUID; out Obj): HResult; stdcall;
Returns a reference to a specified interface if the object supports that interface.
- Increments the reference count.
- Sets the Obj parameter so that it points to an instance of the specified interface.
- Returns 0 to indicate success.
If the object does not support the interface, QueryInterface returns a nonzero error code, such as E_NoInterface.
Overriding QueryInterface When Using BCCIOSARM
On Windows, QueryInterface takes a reference to a GUID/IID. The Delphi RTL declares that parameter as const, relying on the fact that the compiler optimizes const records greater than the size of a register by passing them as reference. That optimization is, however, not available on iOS as it is incompatible with the ARM ABI used there. As a result, on iOS, the Delphi version of QueryInterface does not take that parameter as a reference.
In order to write C++ code that works on both Windows and iOS, when overriding QueryInterface in a delphi-style class, do either of the following:
- You can #ifdef your code, as in:
#if defined(_DELPHI_NEXTGEN) && !defined(_WIN32) HRESULT __stdcall QueryInterface(const GUID IID, /* out */ void *Obj); #else HRESULT __stdcall QueryInterface(const GUID &IID, /* out */ void *Obj); #endif
- You can simply use the REFIID typedef, as in:
HRESULT __stdcall QueryInterface(REFIID IID, /* out */ void *Obj);
- REFIID is a reference for the desktop compilers, but is not a reference on iOS, to ease compatibility with Delphi.