2

I need to get fullDescription property of a UI element using get_CurrentFullDescription method of UIAutomation library of c++ windows.

Issue is I have element as IUIAutomationElement instead of IUIAutomationElement6, get_CurrentFullDescription can only be invoked on element with IUIAutomationElement6 type.

How can I convert IUIAutomationElement to IUIAutomationElement6?

I am using HandlePropertyChangedEvent method to listen on changes in UI, which returns:

HRESULT HandlePropertyChangedEvent(
  [in] IUIAutomationElement *sender,
  [in] PROPERTYID           propertyId,
  [in] VARIANT              newValue
);

https://learn.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationpropertychangedeventhandler-handlepropertychangedevent

Here, I need to access FullDescription property of sender element coming from HandlePropertyChangedEvent function.

AtiqGauri
  • 1,483
  • 13
  • 26
  • 1
    [`QueryInterface`](https://learn.microsoft.com/en-us/windows/win32/api/unknwn/nf-unknwn-iunknown-queryinterface(refiid_void)). – IInspectable Dec 10 '22 at 14:58
  • @IInspectable thanks, can you give me a slight idea of how to use QueryInterface? like what will be REFIID & ppvObject in this case? Thanks in advance, means a lot!! – AtiqGauri Dec 10 '22 at 15:02

1 Answers1

1

@IInspectable mentioned QueryInterface hint in comments, based on that here is answer:

CComPtr<IUIAutomationElement> pElement;
// Code to initialize pElement goes here
CComPtr<IUIAutomationElement6> pElement6;
HRESULT hr = pElement->QueryInterface(&pElement6);
if (SUCCEEDED(hr))
{
    // Use the pElement6 object here
}
AtiqGauri
  • 1,483
  • 13
  • 26