CUIAutomation — это, по сути, класс для работы с объектом CUIAutomation, который реализует IUIAutomationFocusChangedEventHandler и 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();
}
Например, следующий код завершается с ошибкой.
Код: Выделить всё
HRESULT STDMETHODCALLTYPE CUIAutomation::QueryInterface(REFIID riid, void** ppInterface)
{
if (riid == __uuidof(IUnknown))
*ppInterface = static_cast(this);
else if (riid == __uuidof(IUIAutomationFocusChangedEventHandler))
*ppInterface = static_cast(this);
else if (riid == __uuidof(IUIAutomationEventHandler))
*ppInterface = static_cast(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;
}
У меня та же проблема с AddPropertyChangedEventHandler
В AddAutomationEventHandler передано только два указателя: отправитель и this.
ОБНОВЛЕНИЕ. В отладчике я могу подтвердить, что это действительно и вызывается QueryInterface и возвращается допустимый IUIAutomationEventHandler*.
Код: Выделить всё
senderПодробнее здесь: https://stackoverflow.com/questions/798 ... -e-pointer
Мобильная версия