从线程调用 GetFocusedElement 时崩溃

问题描述 投票:0回答:1

我有一个 Electron 应用程序,其中包含用 C++ 编写的本机节点模块,使用 MSVC 编译器构建并使用 CMakeJS 链接。

节点模块在单独的线程中安装了钩子回调(

SetWindowsHookEx
),用于鼠标单击(
WH_MOUSE_LL
)或按键(
WH_KEYBOARD_LL
)。每当用户单击或按下某个键时,它都会调用
GetFocusedElement
。如果返回码为
Sleep(10)
,则调用会重试 3 次,并带有
UIA_E_ELEMENTNOTAVAILABLE

我需要强制执行

GetFocusedElement
以避免这种致命崩溃的任何特定先决条件吗?我检查了文档,但没有找到任何这样的前提条件。我宁愿避免任何致命的崩溃,即使这意味着找不到任何聚焦的元素。

错误跟踪:

OS Version: Windows 10.0.19044 (3086)
Report Version: 104

Crashed Thread: 10164

Application Specific Information:
Fatal Error: EXCEPTION_ACCESS_VIOLATION_READ / 0xffffffffffffffff

Thread 10164 Crashed:
0   uiautomationcore.dll            0x7fffb46cdfe2      LocalUiaNodeProxy::RealRemoteNodeFromProviderEntryPoint
1   uiautomationcore.dll            0x7fffb46fb1fb      LocalUiaNodeProxy::RemoteNodeFromProviderEntryPoint
2   uiautomationcore.dll            0x7fffb46fb15e      LocalUiaNodeProxy::RemoteNodeFromProviderEntryPoint
3   uiautomationcore.dll            0x7fffb47267c5      UiaNodeFactory::InProcProxyFromHwnd
4   uiautomationcore.dll            0x7fffb471a47a      ClientProxyManager::InternalGetProxyProvider
5   uiautomationcore.dll            0x7fffb471a087      ClientProxyManager::GetProxyProvider
6   uiautomationcore.dll            0x7fffb4709767      UiaNodeFactory::CompleteNodeInfo
7   uiautomationcore.dll            0x7fffb4708289      UiaNodeFactory::FromPartialNodeInfo
8   uiautomationcore.dll            0x7fffb472643c      UiaNodeFactory::FromLocalProvider
9   uiautomationcore.dll            0x7fffb472654f      UiaNodeFactory::FromLocalProvider
10  uiautomationcore.dll            0x7fffb46e8b4f      UiaNode::ProviderDrillForPointOrFocus
11  uiautomationcore.dll            0x7fffb46e84e4      UiaNode::ProviderDrillForPointOrFocusInternal
12  uiautomationcore.dll            0x7fffb46e83f1      InProcClientAPIStub::UiaNode_DrillForPointOrFocus
13  uiautomationcore.dll            0x7fffb46c60fd      ComInvoker::CallTarget
14  uiautomationcore.dll            0x7fffb46fa998      InProcClientAPIStub::InvokeInProcAPI
15  uiautomationcore.dll            0x7fffb46be327      UiaNode::CrossProcess_DrillForPointOrFocus
16  uiautomationcore.dll            0x7fffb4778d7b      CUIAutomation::GetFocusedElement
17  nativeapp.node                  0x7fffdec1187d      GetFocusedElementRetry (iohook.cc:182)
18  nativeapp.node                  0x7fffdec1432f      focusChangeHandler (iohook.cc:304)
19  nativeapp.node                  0x7fffdec0fbfa      <lambda>::operator() (iohook.cc:779)
20  nativeapp.node                  0x7fffdec0c70d      [inlined] std::invoke (type_traits:1564)
21  nativeapp.node                  0x7fffdec0c70d      std::thread::_Invoke<T> (thread:55)
22  ucrtbase.dll                    0x7fffe3b91bb1      thread_start<T>
23  KERNEL32.DLL                    0x7fffe48d7613      BaseThreadInitThunk
24  ntdll.dll                       0x7fffe63c26f0      RtlUserThreadStart
winapi microsoft-ui-automation
1个回答
0
投票

当结构化对象没有获得正确的内存地址并且无法作为完整的结构化对象读取时,总是会发生 EXCEPTION_ACCESS_VIOLATION_READ 错误 在这种情况下,请检查参数 IUIAutomationElement **element 并确保它已正确生成。

© www.soinside.com 2019 - 2024. All rights reserved.