ARTICLE AD BOX
I am using UIAutomation to grab the URL in the active browsers address bar. I'm starting with Firefox browser.
CUIAutomation is basically a class for working with CUIAutomation object that implements IUIAutomationFocusChangedEventHandler and IUIAutomationEventHandler
CUIAutomation::CUIAutomation() { HRESULT hr = S_OK; hr = pAutomation_.CoCreateInstance(__uuidof(CUIAutomation), NULL, CLSCTX_INPROC_SERVER); pAutomation_->CreateCacheRequest(&propertyCache_); propertyCache_->AddProperty(UIA_NamePropertyId); propertyCache_->AddProperty(UIA_ControlTypePropertyId); propertyCache_->AddProperty(UIA_IsPasswordPropertyId); propertyCache_->AddProperty(UIA_ProcessIdPropertyId); propertyCache_->AddProperty(UIA_AutomationIdPropertyId); propertyCache_->put_AutomationElementMode(AutomationElementMode_None); hr = EnableEvents(); }When I try to add any event handler to my automation object I always get the error E_POINTER
For example the following code fails.
HRESULT STDMETHODCALLTYPE CUIAutomation::QueryInterface(REFIID riid, void** ppInterface) { if (riid == __uuidof(IUnknown)) *ppInterface = static_cast<IUnknown*>(this); else if (riid == __uuidof(IUIAutomationFocusChangedEventHandler)) *ppInterface = static_cast<IUIAutomationFocusChangedEventHandler*>(this); else if (riid == __uuidof(IUIAutomationEventHandler)) *ppInterface = static_cast<IUIAutomationEventHandler*>(this); else { *ppInterface = NULL; return E_NOINTERFACE; } this->AddRef(); return S_OK; } HRESULT STDMETHODCALLTYPE CUIAutomation::HandleFocusChangedEvent(IUIAutomationElement *sender) { HRESULT hr = S_OK; controlTypeId_ = 0; isPassword_ = FALSE; processId_ = 0; logged_ = false; // these work sender->get_CachedControlType(&controlTypeId_); sender->get_CachedIsPassword(&isPassword_); sender->get_CachedProcessId(&processId_); sender->get_CachedName(&name_); sender->get_CachedAutomationId(&automationId_); if (watchedElement_ == NULL) { PROPERTYID watchedProperties_[] = { UIA_ControlTypePropertyId }; if (automationId_ == "urlbar-input") { // this returns E_POINTER hr = pAutomation_->AddAutomationEventHandler(UIA_Text_TextChangedEventId, sender, TreeScope_Element, NULL, this); if (SUCCEEDED(hr)) { watchedElement_ = sender; } } } return S_OK; }I have tried different Tree scopes and also passing in a cache too. I have the same issue with AddPropertyChangedEventHandler
There are only two pointers passed into AddAutomationEventHandler - sender and this.
UPDATE - Under debugger I can confirm that this is valid and QueryInterface is called and a valid IUIAutomationEventHandler* returned. sender must be valid because I can get cached properties.
