<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE></TITLE>
<META content=text/html;charset=ISO-2022-JP http-equiv=Content-Type>
<META name=GENERATOR content="MSHTML 8.00.6001.18876"></HEAD>
<BODY bgColor=#ffffff text=#000000>
<DIV dir=ltr align=left><SPAN class=515261415-24022010><FONT color=#0000ff
size=2 face=Arial>Brian,</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=515261415-24022010><FONT color=#0000ff
size=2 face=Arial></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=515261415-24022010><FONT color=#0000ff
size=2 face=Arial>On the client side, you need more error checking. You don't
check the value of res after some calls. And you don't check to make sure the
returned out parameters are valid. Any one of these things can go wrong. And you
never know what you'll get back from someone else's code.</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=515261415-24022010><FONT color=#0000ff
size=2 face=Arial></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=515261415-24022010><FONT color=#0000ff
size=2 face=Arial>Likewise, on the server side, you don't check the input
parameters to make sure they're non-null. And you don't check to make sure that
the user hasn't requested fewer key bindings than you
provide.</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=515261415-24022010><FONT color=#0000ff
size=2 face=Arial></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=515261415-24022010><FONT color=#0000ff
size=2 face=Arial>There is at least one case when you don't initialize a local
variable, which you should always do, even when you're passing that variable to
a function using it as an out parameter. That allows you to be more confident in
correct checking of the return value of the parameter.</FONT></SPAN></DIV>
<DIV><FONT color=#0000ff size=2 face=Arial></FONT> </DIV>
<DIV><SPAN class=515261415-24022010><FONT color=#0000ff size=2 face=Arial>Also,
if I were doing this, I would not free the BSTR's in the Process function. It's
easy to lose track of allocating and freeing memory. So, I would have Process
take a const wchar_t*, and have the function that requested the actions free
each BSTR in turn. That way, you can clearly see where the memory was allocated
(in the call to get the actions) and where it is freed. This will give less
responsibility to the Process function, and make the memory allocation and
deallocation easier for the next person to understand.</FONT></SPAN></DIV>
<DIV align=left><FONT size=2 face=Arial></FONT> </DIV>
<DIV align=left><FONT size=2 face=Arial>Thanks,</FONT></DIV>
<DIV align=left><FONT size=2 face=Arial>RG</FONT></DIV>
<DIV align=left> </DIV>
<DIV> </DIV><BR>
<DIV dir=ltr lang=en-us class=OutlookMessageHeader align=left>
<HR tabIndex=-1>
<FONT size=2 face=Tahoma><B>From:</B>
accessibility-ia2-bounces@lists.linuxfoundation.org
[mailto:accessibility-ia2-bounces@lists.linuxfoundation.org] <B>On Behalf Of
</B>Pete Brunet<BR><B>Sent:</B> Tuesday, February 23, 2010 6:43 PM<BR><B>Cc:</B>
accessibility@lists.linux-foundation.org; IA2 List<BR><B>Subject:</B> Re:
[Accessibility-ia2] [Accessibility] Newbie question: help withBSTR
arrays<BR></FONT><BR></DIV>
<DIV></DIV><FONT face="Helvetica, Arial, sans-serif">Hi Brian, I suspect there
are some important readers that don't watch this list. I'm cc'ing it to
the IA2 list. -Pete</FONT><BR><BR>Brian Cragun wrote:
<BLOCKQUOTE
cite=mid:OF75731433.B228C337-ON852576D2.007C49AF-862576D2.007CE14F@us.ibm.com
type="cite"><FONT size=2>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.</FONT>
<BR><BR><FONT size=2>Thanks!</FONT> <BR><BR><FONT size=2>Brian</FONT>
<BR><BR><FONT size=2>CLIENT:</FONT> <BR><FONT size=2>
res =
m_spAccessible2->QueryInterface(IID_IAccessibleAction,(</FONT><FONT
color=blue size=2>void</FONT><FONT
size=2>**)&m_spAccessibleAction);</FONT> <BR><FONT size=2>
</FONT><FONT color=blue size=2>long</FONT><FONT size=2> nActions = 0L;</FONT>
<BR><FONT size=2>
res =
m_spAccessibleAction->nActions(&nActions);</FONT> <BR><FONT
size=2>
</FONT><FONT color=blue size=2>if</FONT><FONT
size=2>(SUCCEEDED(res)){</FONT> <BR><FONT size=2>
BSTR name;</FONT> <BR><FONT size=2>
BSTR description;</FONT> <BR><FONT size=2>
</FONT><FONT color=blue size=2>for</FONT><FONT size=2> (</FONT><FONT
color=blue size=2>int</FONT><FONT size=2> iAction=0 ; iAction<nActions;
iAction++){</FONT> <BR><FONT size=2>
res = m_spAccessibleAction->get_name(iAction,
&name);</FONT> <BR><FONT size=2>
</FONT><FONT color=blue size=2>if</FONT><FONT
size=2>(SUCCEEDED(res)){</FONT> <BR><FONT size=2>
Process(name);
</FONT><FONT color=#008000 size=2>// Process the name and free the
string</FONT> <BR><FONT size=2>
}</FONT> <BR><FONT size=2>
res =
m_spAccessibleAction->get_description(iAction, &description);</FONT>
<BR><FONT size=2>
</FONT><FONT color=blue size=2>if</FONT><FONT
size=2>(SUCCEEDED(res)){</FONT> <BR><FONT size=2>
Process(description); </FONT><FONT color=#008000 size=2>// Process the name
and free the string</FONT> <BR><FONT size=2>
}</FONT> <BR><BR><FONT size=2>
BSTR *aKeyBindings;</FONT> <BR><FONT
size=2>
</FONT><FONT color=blue size=2>long</FONT><FONT size=2> aNumMaxBinding =
10;</FONT> <BR><FONT size=2>
</FONT><FONT color=blue size=2>long</FONT><FONT size=2>
aNumBindings;</FONT> <BR><FONT size=2>
res =
m_spAccessibleAction->get_keyBinding(iAction, aNumMaxBinding,
&aKeyBindings, &aNumBindings);</FONT> <BR><FONT size=2>
</FONT><FONT color=blue
size=2>if</FONT><FONT size=2>(SUCCEEDED(res)){</FONT> <BR><FONT size=2>
</FONT><FONT color=blue size=2>for</FONT><FONT size=2> (</FONT><FONT
color=blue size=2>int</FONT><FONT size=2> jBind=0; jBind<aNumBindings;
jBind++){</FONT> <BR><FONT size=2>
Process(aKeyBindings[jBind]); </FONT><FONT color=#008000 size=2>// Process the
name and free the string</FONT> <BR><FONT size=2>
}</FONT>
<BR><FONT size=2>
CoTaskMemFree(aKeyBindings);</FONT>
<BR><FONT size=2>
}</FONT> <BR><BR><FONT size=2>
}</FONT>
<BR><FONT size=2>
}</FONT> <BR><BR><FONT size=2>SERVER:</FONT>
<BR><FONT size=2>STDMETHODIMP AccServer::get_keyBinding(</FONT><FONT
color=blue size=2>long</FONT><FONT size=2> aActionIndex, </FONT><FONT
color=blue size=2>long</FONT><FONT size=2> aNumMaxBinding,</FONT> <BR><FONT
size=2>
BSTR **aKeyBinding,</FONT>
<BR><FONT size=2>
</FONT><FONT
color=blue size=2>long</FONT><FONT size=2> *aNumBinding)</FONT> <BR><FONT
size=2>{</FONT> <BR><BR><FONT size=2> *aKeyBinding = </FONT><FONT
color=blue size=2>static_cast</FONT><FONT
size=2><BSTR*>(CoTaskMemAlloc((aNumMaxBinding) * </FONT><FONT color=blue
size=2>sizeof</FONT><FONT size=2>(BSTR*)));</FONT> <BR><FONT size=2>
</FONT><FONT color=blue size=2>if</FONT><FONT size=2>
(!*aKeyBinding) </FONT><FONT color=blue size=2>return</FONT><FONT size=2>
E_OUTOFMEMORY;</FONT> <BR><BR><FONT size=2>
*aKeyBinding[0] = ::SysAllocString(OLESTR(</FONT><FONT
color=#a11f12 size=2>"0 key binding"</FONT><FONT size=2>));</FONT> <BR><FONT
color=#008000 size=2>//
if (!*(aKeyBinding[0])) return E_OUTOFMEMORY;</FONT> <BR><FONT
size=2>
(*aKeyBinding)[1] = ::SysAllocString(OLESTR(</FONT><FONT color=#a11f12
size=2>"1 key binding"</FONT><FONT size=2>));</FONT> <BR><FONT color=#008000
size=2>// if
(!*(aKeyBinding[1])) return E_OUTOFMEMORY;</FONT> <BR><FONT size=2>
(*aKeyBinding)[2] =
::SysAllocString(OLESTR(</FONT><FONT color=#a11f12 size=2>"2 key
binding"</FONT><FONT size=2>));</FONT> <BR><FONT color=#008000 size=2>//
if
(!*(aKeyBinding[2])) return E_OUTOFMEMORY;</FONT> <BR><FONT size=2>
*aNumBinding = 3L;</FONT> <BR><FONT size=2>
</FONT><FONT color=blue size=2>return</FONT><FONT size=2> S_OK;</FONT>
<BR><FONT size=2>}</FONT> <BR><BR><BR><BR><FONT size=2 face=Arial>Brian
Cragun</FONT> <BR><FONT size=2 face=Arial>IBM AbilityLab Consultant<BR>Human
Ability & Accessibility Center</FONT><FONT color=blue size=2
face=Arial><U><BR></U></FONT><A href="http://www.ibm.com/able"
moz-do-not-send="true"><FONT color=blue size=2
face=Arial><U>www.ibm.com/able</U></FONT></A><FONT size=2 face=Arial> &
</FONT><A href="http://w3.ibm.com/able" moz-do-not-send="true"><FONT
color=blue size=2 face=Arial><U>w3.ibm.com/able</U></FONT></A> <BR><FONT
size=2 face=Arial>W:(720)-663-2801 H:(507)288-2437</FONT>
<BR><BR><FONT size=2 face=Arial><B><I>Subscribe to RSS feed and contribute
to</I></B></FONT><A
href="http://w3.ibm.com/connections/communities/service/html/communityview?communityUuid=136047f0-6cda-4a2a-9a90-2188047a542a"
moz-do-not-send="true"><FONT color=blue size=2 face=Arial><B><I>Accessibility
News community</I></B></FONT></A><FONT size=2 face=Arial><B><I>on
Connections</I></B></FONT> <BR><A
href="http://www.facebook.com/IBMAccessibility" moz-do-not-send="true"><FONT
color=blue size=2 face="Palatino Linotype"><U>IBM
Accessibility</U></FONT></A><FONT size=2 face="Palatino Linotype"> on Facebook
</FONT><FONT size=2 face=Arial>$B"'(B</FONT><FONT size=2 face=Arial> </FONT><A
href="http://twitter.com/IBMAccess" moz-do-not-send="true"><FONT color=blue
size=2 face="Palatino Linotype"><U>IBMAccess</U></FONT></A><FONT size=2
face="Palatino Linotype"> on Twitter </FONT><FONT size=2
face=Arial>$B"'(B</FONT><FONT size=2 face=Arial> </FONT><A
href="http://www.linkedin.com/e/vgh/2419815/" moz-do-not-send="true"><FONT
color=blue size=2 face="Palatino Linotype"><U>IBM
Accessibility</U></FONT></A><FONT size=2 face="Palatino Linotype"> on
LinkedIn</FONT><FONT size=2 face=Arial><BR></FONT><BR><BR><BR>
<TABLE width="100%">
<TBODY>
<TR vAlign=top>
<TD><FONT color=#5f5f5f size=1 face=sans-serif>From:</FONT> </TD>
<TD><FONT size=1 face=sans-serif>Brian Cragun/Rochester/IBM@IBMUS</FONT>
</TD></TR>
<TR vAlign=top>
<TD><FONT color=#5f5f5f size=1 face=sans-serif>To:</FONT> </TD>
<TD><FONT size=1 face=sans-serif><A class=moz-txt-link-abbreviated
href="mailto:accessibility@lists.linux-foundation.org">accessibility@lists.linux-foundation.org</A></FONT>
</TD></TR>
<TR vAlign=top>
<TD><FONT color=#5f5f5f size=1 face=sans-serif>Date:</FONT> </TD>
<TD><FONT size=1 face=sans-serif>02/22/2010 01:52 PM</FONT> </TD></TR>
<TR vAlign=top>
<TD><FONT color=#5f5f5f size=1 face=sans-serif>Subject:</FONT> </TD>
<TD><FONT size=1 face=sans-serif>[Accessibility] Newbie question: help
with BSTR arrays</FONT> </TD></TR>
<TR vAlign=top>
<TD><FONT color=#5f5f5f size=1 face=sans-serif>Sent by:</FONT> </TD>
<TD><FONT size=1 face=sans-serif><A class=moz-txt-link-abbreviated
href="mailto:accessibility-bounces@lists.linux-foundation.org">accessibility-bounces@lists.linux-foundation.org</A></FONT></TD></TR></TBODY></TABLE><BR>
<HR noShade>
<BR><BR><BR><FONT size=2 face=sans-serif>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?</FONT><FONT size=3> <BR></FONT><FONT size=2 face=sans-serif><BR>The
information at </FONT><A
href="http://accessibility.freestandards.org/a11yspecs/ia2/docs/html/_generalinfo.html#_arrayConsideration"
moz-do-not-send="true"><FONT color=blue size=2
face=sans-serif><U>http://accessibility.freestandards.org/a11yspecs/ia2/docs/html/_generalinfo.html#_arrayConsideration</U></FONT></A><FONT
size=2 face=sans-serif> is useful but not quite enough for me.</FONT><FONT
size=3> </FONT><FONT size=2 face=sans-serif><BR>I assume I need to allocation
the memory with </FONT><FONT size=3><B>CoTaskMemAlloc</B> </FONT><FONT size=2
face=sans-serif>and release it with </FONT><FONT size=3><B>CoTaskMemFree.
</B><BR><B><BR>Thanks!</B> <BR><B><BR>- Brian</B> <BR></FONT><FONT
size=2 face=Arial><BR>Brian Cragun</FONT><FONT size=3> </FONT><FONT size=2
face=Arial><BR>IBM AbilityLab Consultant<BR>Human Ability & Accessibility
Center</FONT><FONT color=blue size=3><U><BR></U></FONT><A
href="http://www.ibm.com/able" moz-do-not-send="true"><FONT color=blue size=2
face=Arial><U>www.ibm.com/able</U></FONT></A><FONT size=2 face=Arial> &
</FONT><A href="http://w3.ibm.com/able" moz-do-not-send="true"><FONT
color=blue size=2 face=Arial><U>w3.ibm.com/able</U></FONT></A><FONT size=3>
</FONT><FONT size=2 face=Arial><BR>W:(720)-663-2801
H:(507)288-2437</FONT><FONT size=3> <BR></FONT><TT><FONT
size=2>_______________________________________________<BR>Accessibility
mailing list<BR><A class=moz-txt-link-abbreviated
href="mailto:Accessibility@lists.linux-foundation.org">Accessibility@lists.linux-foundation.org</A><BR></FONT></TT><A
href="https://lists.linux-foundation.org/mailman/listinfo/accessibility"
moz-do-not-send="true"><TT><FONT
size=2>https://lists.linux-foundation.org/mailman/listinfo/accessibility</FONT></TT></A><TT><FONT
size=2><BR></FONT></TT><BR><PRE wrap=""><HR SIZE=4 width="90%">
_______________________________________________
Accessibility mailing list
<A class=moz-txt-link-abbreviated href="mailto:Accessibility@lists.linux-foundation.org">Accessibility@lists.linux-foundation.org</A>
<A class=moz-txt-link-freetext href="https://lists.linux-foundation.org/mailman/listinfo/accessibility">https://lists.linux-foundation.org/mailman/listinfo/accessibility</A>
</PRE></BLOCKQUOTE><BR>
<DIV class=moz-signature>-- <BR><FONT color=#0060a0 size=1
face="Arial, sans-serif"><B>Pete Brunet</B></FONT><BR><FONT color=#0060a0><SPAN
style="TEXT-DECORATION: line-through">
</SPAN></FONT><BR><FONT color=#333333 size=1
face="Arial, sans serif">a11ysoft - Accessibility Architecture and
Development<BR>(512) 238-6967 (work), (512) 689-4155 (cell)<BR>Skype:
pete.brunet<BR>IM: ptbrunet (AOL, Google), <A class=moz-txt-link-abbreviated
href="mailto:ptbrunet@live.com">ptbrunet@live.com</A> (MSN)<BR><A
class=moz-txt-link-freetext
href="http://www.a11ysoft.com/about/">http://www.a11ysoft.com/about/</A><BR>Ionosphere:
WS4G <BR></FONT></DIV></BODY></HTML>