Since the function's return value is utilized for error message, how do the functions return the necessary information back to the caller?
For example: IDirect3D9::CreateDevice method
So if you take a look at that link you'll notice that it has some parameters marked Out
this is important because this denotes what will be returned to the caller.
HRESULT CreateDevice(
[in] UINT Adapter,
[in] D3DDEVTYPE DeviceType,
[in] HWND hFocusWindow,
[in] DWORD BehaviorFlags,
[in, out] D3DPRESENT_PARAMETERS *pPresentationParameters,
[out, retval] IDirect3DDevice9 **ppReturnedDeviceInterface
);
In the above sample (copied and pasted from the MSDN link), you'll notice a parameter ppReturnedDeviceInterface
is marked as being **
or a pointer to a pointer, the caller would pass in a the address of their pointer and would be returned a pointer at that address. Also the D3DPRESENT_PARAMETERS
structure passed in to pPresentationParameters
will be updated on return, as noted by the out
annotation.
Ex:
IDirect3DDevice9 *pDevice = NULL;
HRESULT hr = pD3D->CreateDevice(
D3DADAPTER_DEFAULT,
D3DDEVTYPE_HAL,
hwnd,
pPresentationParams,
&pDevice);
if(SUCCEEDED(hr))
{
//pDevice should be non null at this point
}