我正在尝试调用IDispatch-> Invoke调用来获取IDispatch对象的名称,该方法失败,错误为DISP_E_EXCEPTION。 我想要获得的属性是“accName”。 以下是尝试执行此操作的代码:
HRESULT getParentName(IAccessible* pAcc) {
IDispatch *parent;
HRESULT hr;
if ((hr = pAcc->get_accParent(&parent)) == S_OK) {
DISPID dispid;
WCHAR *member = L"accName";
DISPPARAMS dispparams = { NULL, NULL, 0, 0 };
VARIANT result;
result.lVal = CHILDID_SELF;
result.vt = VT_I4;
hr = parent->GetIDsOfNames(IID_NULL, &member, 1, LOCALE_SYSTEM_DEFAULT, &dispid);
if (SUCCEEDED(hr)) {
//OK till now
EXCEPINFO exc;
UINT numErrs;
hr = parent->Invoke(dispid, IID_NULL, LOCALE_SYSTEM_DEFAULT,
DISPATCH_PROPERTYGET, &dispparams, &result, &exc, &numErrs);
if (hr == S_OK) {
MessageBox(NULL, result.bstrVal, L"Got the name", MB_OK);
} else {
//fails with error DISP_E_EXCEPTION
// exception EXCEPINFO return nothing
}
}