[Accessibility] Newbie question: help with BSTR arrays

Brian Cragun cragun at us.ibm.com
Mon Feb 22 14:44:01 PST 2010


Thanks for your interest and patience.   The following code seems to be 
working.  It shows a CLIENT fragment that calls for the key bindings and 
then pulls them off for processing.   The SERVER snippet shows how I am 
building a simple three element BSTR array.    Please advise if you see 
any stupid errors being made.

Thanks!

Brian

CLIENT:
                        res = 
m_spAccessible2->QueryInterface(IID_IAccessibleAction,(void
**)&m_spAccessibleAction);
                        long nActions = 0L;
                        res = m_spAccessibleAction->nActions(&nActions);
                        if(SUCCEEDED(res)){
                                BSTR name;
                                BSTR description;
                                for (int iAction=0 ; iAction<nActions; 
iAction++){
                                        res = 
m_spAccessibleAction->get_name(iAction, &name);
                                        if(SUCCEEDED(res)){
                                                Process(name);  // Process 
the name and free the string
                                        }
                                        res = 
m_spAccessibleAction->get_description(iAction, &description);
                                        if(SUCCEEDED(res)){
                                                Process(description); // 
Process the name and free the string
                                        }

                                        BSTR *aKeyBindings;
                                        long aNumMaxBinding = 10;
                                        long aNumBindings;
                                        res = 
m_spAccessibleAction->get_keyBinding(iAction, aNumMaxBinding, 
&aKeyBindings, &aNumBindings);
                                        if(SUCCEEDED(res)){
                                                for (int jBind=0; 
jBind<aNumBindings; jBind++){
 Process(aKeyBindings[jBind]); // Process the name and free the string
                                                }
 CoTaskMemFree(aKeyBindings);
                                        }

                                }
                        }

SERVER:
STDMETHODIMP AccServer::get_keyBinding(long aActionIndex, long 
aNumMaxBinding,
                                  BSTR **aKeyBinding,
                                  long *aNumBinding)
{

    *aKeyBinding = static_cast<BSTR*>(CoTaskMemAlloc((aNumMaxBinding) * 
sizeof(BSTR*)));
        if (!*aKeyBinding) return E_OUTOFMEMORY;

                *aKeyBinding[0] = ::SysAllocString(OLESTR("0 key binding"
));
//                if (!*(aKeyBinding[0])) return E_OUTOFMEMORY;
                (*aKeyBinding)[1] = ::SysAllocString(OLESTR("1 key 
binding"));
//                if (!*(aKeyBinding[1])) return E_OUTOFMEMORY;
                (*aKeyBinding)[2] = ::SysAllocString(OLESTR("2 key 
binding"));
//                if (!*(aKeyBinding[2])) return E_OUTOFMEMORY;
        *aNumBinding = 3L;
  return S_OK;
}



Brian Cragun
IBM AbilityLab Consultant
Human Ability & Accessibility Center
www.ibm.com/able & w3.ibm.com/able
W:(720)-663-2801    H:(507)288-2437

Subscribe to RSS feed and contribute toAccessibility News communityon 
Connections
IBM Accessibility on Facebook ▼ IBMAccess on Twitter ▼ IBM Accessibility 
on LinkedIn




From:
Brian Cragun/Rochester/IBM at IBMUS
To:
accessibility at lists.linux-foundation.org
Date:
02/22/2010 01:52 PM
Subject:
[Accessibility] Newbie question: help with BSTR arrays
Sent by:
accessibility-bounces at lists.linux-foundation.org



I'm struggling to understand how a BSTR array is properly allocated and 
content is added to it.   Also how the BSTRs in the array are retrieved. 
Does anyone have any simple examples? 

The information at 
http://accessibility.freestandards.org/a11yspecs/ia2/docs/html/_generalinfo.html#_arrayConsideration 
is useful but not quite enough for me. 
I assume I need to allocation the memory with CoTaskMemAlloc and release 
it with CoTaskMemFree.   

Thanks! 

- Brian 

Brian Cragun 
IBM AbilityLab Consultant
Human Ability & Accessibility Center
www.ibm.com/able & w3.ibm.com/able 
W:(720)-663-2801    H:(507)288-2437 
_______________________________________________
Accessibility mailing list
Accessibility at lists.linux-foundation.org
https://lists.linux-foundation.org/mailman/listinfo/accessibility

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.linux-foundation.org/pipermail/accessibility/attachments/20100222/467fe9cb/attachment-0001.htm 


More information about the Accessibility mailing list