Method ITcUnknown:TcQueryInterface

Query of an interface pointer with regard to an interface that is given by interface ID (IID).

Syntax

HRESULT TcQueryInterface(RITCID iid, PPVOID pipItf )

Method ITcUnknown:TcQueryInterface 1: Return value

If successful, S_OK ("0") or another positive value will be returned, cf. Return values. Extended messages refer in particular to the column HRESULT in ADS Return Codes.

If the demanded interface is not available, the method returns ADSERR_DEVICE_NOINTERFACE.

Parameter

Name

Type

Description

iid

RITCID

Interface IID.

pipItf

PPVOID

Pointer to interface pointer. Is set when the requested interface type is available from the corresponding instance.

Description

Query of the reference to an implemented interface via the IID. It is recommended to use Smart Pointers to initialize and hold interface pointers.

Variant 1:

HRESULT GetTraceLevel(ITcUnkown* ip, TcTraceLevel& tl)
{
HRESULT hr = S_OK;
if (ip != NULL)
{
ITComObjectPtr spObj;
hr = ip->TcQueryInterface(spObj.GetIID(), &spObj);
if (SUCCEEDED(hr))
{
hr = spObj->TcGetObjPara(PID_TcTraceLevel, &tl, sizeof(tl));
}
return hr;
}
}


The interface ID associated with the Smart Pointer can be used as a parameter in TcQueryInterface. The "&" operator will return the pointer to the internal interface pointer member variable of the Smart Pointer. Variant 1 assumes that the interface pointer is initialized when TcQueryInterface indicates success. If the range remains, then the destructor of the Smart Pointer spObj releases the reference.

Variant 2:


HRESULT GetTraceLevel(ITcUnkown* ip, TcTraceLevel& tl)
{
HRESULT hr = S_OK;
ITComObjectPtr spObj = ip;
if (spObj != NULL)
{
spObj->TcGetObjParam(PID_TcTraceLevel, &tl);
}
else
{
hr = ADS_E_NOINTERFACE;
}
return hr;
}

If the interface pointer ip is assigned to the Smart Pointer spObj, then the TcQueryInterface method is called implicitly with IID_ITComObject on the instance to which ip refers. This results in a shorter code, but the original return code of TcQueryInterface is lost.