0

I'm trying to invoke a IDispatch->Invoke call to get the name of the IDispatch object and the method fails with error DISP_E_EXCEPTION. The property I'm trying to get is "accName". Below is the code that tries to do this:

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
        }

    }
Andrei
  • 367
  • 5
  • 18
  • Crystal ball says that you forgot to call CoInitializeEx(), accessibility works a bit too well without it. Get another opinion by using the IAccessible interface directly, much easier to program, and by checking if the provider is okay with the AccCheckUI.exe SDK tool. – Hans Passant Jul 08 '16 at 15:32
  • I'm new to COM programming, so not sure if I made some mistakes, but I'm trying to get the parent of an IAccessible object and get its name: IDispatch *parent; HRESULT hr; if ((hr = pAcc->get_accParent(&parent)) == S_OK) { // do the rest of the code } – Andrei Jul 08 '16 at 15:41
  • I found it works in some cases, but specifically I'm trying to run it on an Excel app and it fails. So, it may be the problem with Excel that throws thix Exception? – Andrei Jul 08 '16 at 15:53
  • Finally I was able to get it working as suggested by Hans - got the IAccessible interface using QueryInterface and used the get_accName instead of Invoke method. – Andrei Jul 08 '16 at 16:34

0 Answers0