我有一个本地插件,可以检测缩放会议窗口并在其中找到一些按钮。
该本机插件是使用 NAPI(node-addon-api) 制作的,当我运行它时,它工作正常......(给我那个按钮名称)。
但是,当我尝试在电子中运行该本地插件时,它会使电子应用程序崩溃。
这是检测元素的本机插件 C++ 代码:
void ListDescendants(IUIAutomationElement* pParent, int indent)
{
if (pParent == NULL)
return;
IUIAutomationTreeWalker* pControlWalker = NULL;
IUIAutomationElement* pNode = NULL;
g_pAutomation->get_ControlViewWalker(&pControlWalker);
if (pControlWalker == NULL)
goto cleanup;
pControlWalker->GetFirstChildElement(pParent, &pNode);
if (pNode == NULL)
goto cleanup;
while (pNode)
{
BSTR sName;
pNode->get_CurrentName(&sName);
//std::wcout << sName << L"\n";
std::wstring strName(sName, SysStringLen(sName));
if (strName.find(L"currently unmuted") != std::string::npos)
{
std::cout<<"####### UNMUTE"<<"\n";
}else if(strName.find(L"currently muted") != std::string::npos){
std::cout<<"####### MUTE"<<"\n";
}
SysFreeString(sName);
ListDescendants(pNode, indent+1);
IUIAutomationElement* pNext;
pControlWalker->GetNextSiblingElement(pNode, &pNext);
pNode->Release();
pNode = pNext;
}
cleanup:
if (pControlWalker != NULL)
pControlWalker->Release();
if (pNode != NULL)
pNode->Release();
return;
}