Share via


IRawElementProviderFragment::GetRuntimeId Method

Retrieves the runtime identifier of an element.

Syntax

HRESULT GetRuntimeId(      
    SAFEARRAY *pRetVal
);

Parameters

  • pRetVal
    [out, retval] The address of a SAFEARRAY that receives the unique runtime identifier. This parameter is passed uninitialized.

Return Value

Returns S_OK if successful, or an error value otherwise.

Remarks

Implementations should return NULL for a top-level element that is hosted in a window. Other elements should return an array that contains UiaAppendRuntimeId (defined in Uiautomationcoreapi.h), followed by a value that is unique within an instance of the fragment.

Example

The following implementation for a list item returns a runtime identifier made up of the UiaAppendRuntimeId constant and the index of the item within the list.

HRESULT STDMETHODCALLTYPE ListItemProvider::GetRuntimeId(SAFEARRAY ** pRetVal)
{
    if (pRetVal == NULL) 
    {
        return E_INVALIDARG;
    }
    
    int rId[] = { UiaAppendRuntimeId, m_itemIndex };
    SAFEARRAY *psa = SafeArrayCreateVector(VT_I4, 0, 2);
    if (psa == NULL)
    {
        return E_OUTOFMEMORY;
    }
    
    for (LONG i = 0; i < 2; i++)
    {
        SafeArrayPutElement(psa, &i, (void*)&(rId[i]));
    }
    
    *pRetVal = psa;
    return S_OK;
}   

See Also

IRawElementProviderFragment, Working with Safe Arrays