<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>North Atlanta Web Design &#187; C++</title>
	<atom:link href="http://www.northatlantawebdesign.com/index.php/category/c/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.northatlantawebdesign.com</link>
	<description>Programming Examples, Samples, and Tutorials</description>
	<lastBuildDate>Fri, 09 Jul 2010 13:08:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Microsoft Active Accessibility Methods and Inconsistent Implementations</title>
		<link>http://www.northatlantawebdesign.com/index.php/2009/08/12/microsoft-active-accessibility-methods-and-inconsistent-implementations/</link>
		<comments>http://www.northatlantawebdesign.com/index.php/2009/08/12/microsoft-active-accessibility-methods-and-inconsistent-implementations/#comments</comments>
		<pubDate>Wed, 12 Aug 2009 21:04:32 +0000</pubDate>
		<dc:creator>Jeff Gibeau</dc:creator>
				<category><![CDATA[Accessibility]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[get_accRole]]></category>
		<category><![CDATA[get_accState]]></category>
		<category><![CDATA[IAccessible]]></category>
		<category><![CDATA[Microsoft Active Accessibility]]></category>
		<category><![CDATA[MSAA]]></category>

		<guid isPermaLink="false">http://www.northatlantawebdesign.com/?p=143</guid>
		<description><![CDATA[The C++ IAccessible interface offers a handful of methods that allow you to gather information or perform actions on an object. Each of these methods are well documented on MSDN, but it is up to the creator of an object to implement them correctly. In this article, I&#8217;ll be talking about a couple of the [...]]]></description>
			<content:encoded><![CDATA[<!-- sphereit start --><p>The C++ IAccessible interface offers a handful of methods that allow you to gather information or perform actions on an object.  Each of these methods are well <a title="IAccessible Interface Documentation MSDN" href="http://msdn.microsoft.com/en-us/library/dd318466%28VS.85%29.aspx">documented on MSDN</a>, but it is up to the creator of an object to implement them correctly.  In this article, I&#8217;ll be talking about a couple of the inconsistencies you may run into when using these methods due to improper implementations and a lack of restrictions on how they should be implemented.<br />
<span id="more-143"></span></p>
<h3>IAccessible::get_accRole</h3>
<p>In the documentation for this method, it is clearly stated that it accepts two parameters.  The first is the accessible objects child id.  This variant is either equal to CHILDID_SELF, which defines that you are seeking information about the current object, or the child ID, which will get the role of the defined child.  This parameter should be of variant type VT_I4.  The second parameter is a variant pointer that will return the accessibility role of the object.  In the documentation this is stated as being an <a title="Object Role Constants MSDN" href="http://msdn.microsoft.com/en-us/library/dd373608%28VS.85%29.aspx">object role constant</a> such as ROLE_SYSTEM_WINDOW or ROLE_SYSTEM_CLIENT.  This parameter is where I have run into problems with how get_accRole has been implemented by the creator of the object.</p>
<p>In addition to stating the second parameter should return an object role constant, it also states that the variant type MUST be of type VT_I4.  This does not seem to be enforced though.  I have run into numerous situations (developing in Microsoft Office) where the variant type is VT_BSTR.  A string is considered invalid for this variant and can cause quite a headache when unexpected.  This occurs in a Microsoft product none the less, the creators of MSAA.  This is just one case that I have run into where the value is invalid, and it begs the question, what other variant types might this return?  That is totally up to the developer implemented get_accRole in his object.  The simple solution to this problem is to always check the variant type that is returned before doing any operations on it to avoid errors.</p>
<h3>IAccessible::get_accState</h3>
<p>After research into the get_accRole method, it came as no surprise the get_accState suffers from the same issues.  As with get_accRole, get_accState takes two parameters.  The first is the child id, and the second is the out variable to hold the state constant.  The <a title="IAccessible get_accState MSDN Documentation" href="http://msdn.microsoft.com/en-us/library/dd318487%28VS.85%29.aspx">documentation for get_accState</a> states that the second argument will return a variant type of VT_I4 that corresponds to one of the <a title="Object State Constants MSDN" href="http://msdn.microsoft.com/en-us/library/dd373609%28VS.85%29.aspx">object state constants</a>.  Though in using the accState with Microsoft Office and Lotus Notes I have run into times where the state is of variant type VT_BSTR (string).  Again the solution is to always check the variant type that is returned before using it in any operations.</p>
<p>&#8212;&#8211;</p>
<p>As I continue to dive deeper into the world of MSAA, I&#8217;ll keep this blog up to date with the inconsistencies I find.  If you have any that you have come across in working with MSAA tell me about them.  I&#8217;ll be glad to look into them to see if there is a workaround or a clean way to handle them.  I&#8217;ll leave with you with a code snippet that shows how to get the accRole and compare it with an object role constant.</p>
<p>Compare accessibility role:</p>
<pre class="brush: cpp;">
//Code below assumes that IAccessible object and ChildID are both passed in parameters.
bool CompareAccRole(IAccessible* pIAccessible, VARIANT childID, LONG objectRoleConstant)
{
	VARIANT accObjectRole;
	HRESULT hr = pIAccessible-&gt;get_accRole(childID, &amp;accObjectRole);
	if(hr == S_OK &amp;&amp; accObjectRole.vt == VT_I4)
	{
		if(accObjectRole.lVal &amp; objectRoleConstant)
			return true;
	}
	return false;
}
</pre>
<p>Useful Links:</p>
<ul>
<li><a title="IAccessible MSDN Documentation" href="http://msdn.microsoft.com/en-us/library/dd318466%28VS.85%29.aspx">IAccessible MSDN Documentation</a></li>
<li><a title="IAccessible::get_accRole MSDN Documentation" href="http://msdn.microsoft.com/en-us/library/dd318485%28VS.85%29.aspx">IAccessible::get_accRole MSDN Documentation</a></li>
<li><a title="Object Role Constants MSDN" href="http://msdn.microsoft.com/en-us/library/dd373608%28VS.85%29.aspx">Object Role Constants MSDN</a></li>
<li><a title="IAccessible::get_accState MSDN Documentation" href="http://msdn.microsoft.com/en-us/library/dd318487%28VS.85%29.aspx">IAccessible::get_accState MSDN Documentation</a></li>
<li><a title="Object State Constants" href="http://msdn.microsoft.com/en-us/library/dd373609%28VS.85%29.aspx">Object State Constants MSDN</a></li>
</ul>
<!-- sphereit end --><span style="margin-bottom:40px; border-bottom:none;"><a class="iconsphere" title="Sphere: Related Content" onclick="return Sphere.Widget.search('http://www.northatlantawebdesign.com/index.php/2009/08/12/microsoft-active-accessibility-methods-and-inconsistent-implementations/')" href="http://www.sphere.com/search?q=sphereit:http://www.northatlantawebdesign.com/index.php/2009/08/12/microsoft-active-accessibility-methods-and-inconsistent-implementations/">Sphere: Related Content</a></span><br/><br/>]]></content:encoded>
			<wfw:commentRss>http://www.northatlantawebdesign.com/index.php/2009/08/12/microsoft-active-accessibility-methods-and-inconsistent-implementations/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Automating Excel 2007 in C++ by Importing the Excel 2007 Type Library</title>
		<link>http://www.northatlantawebdesign.com/index.php/2009/07/21/automating-excel-2007-in-c-by-importing-the-excel-2007-type-library/</link>
		<comments>http://www.northatlantawebdesign.com/index.php/2009/07/21/automating-excel-2007-in-c-by-importing-the-excel-2007-type-library/#comments</comments>
		<pubDate>Tue, 21 Jul 2009 16:58:51 +0000</pubDate>
		<dc:creator>Jeff Gibeau</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[Microsoft Excel 2007]]></category>
		<category><![CDATA[Microsoft Office 2007]]></category>
		<category><![CDATA[Visual Studio 2008]]></category>
		<category><![CDATA[Automating]]></category>
		<category><![CDATA[COM]]></category>
		<category><![CDATA[Excel 2007]]></category>
		<category><![CDATA[Type Library]]></category>
		<category><![CDATA[VS2008]]></category>

		<guid isPermaLink="false">http://www.northatlantawebdesign.com/?p=119</guid>
		<description><![CDATA[When I started trying to write automations for Excel 2007 using C++, I ran into problems right up front. I was trying to use #import to get to the type library for Excel 2007, and was importing what I thought was the correct file. The following was written for a C++ application in Visual Studio [...]]]></description>
			<content:encoded><![CDATA[<!-- sphereit start --><p>When I started trying to write automations for <a type="amzn">Excel 2007</a> using <a type="amzn">C++</a>, I ran into problems right up front.  I was trying to use #import to get to the type library for Excel 2007, and was importing what I thought was the correct file.  The following was written for a C++ application in <a type="amzn">Visual Studio 2008</a> (VS2008), automating Excel 2007.<br />
<span id="more-119"></span></p>
<ol>
<li>The Excel Type Library is not contained in XL5EN32.OLB as you might expect, it is contained in excel.exe</li>
<li>
Error #2: Even importing the correct file, errors were being raised.</p>
<pre class="brush: cpp;">
//The Following Import gives you the error Error	1	error C2504: '_IMsoDispObj' : base class undefined
#import &quot;C:\Program Files\Microsoft Office\Office12\EXCEL.EXE&quot;
</pre>
<p>To correctly import the Excel type library, two more references are needed: MSO.DLL and VBE6EXT.OLB</p>
<pre class="brush: cpp;">
#import &quot;C:\Program Files\Common Files\Microsoft Shared\OFFICE12\mso.dll&quot; no_implementation raw_interfaces_only
#import &quot;C:\Program Files\Common Files\Microsoft Shared\VBA\VBA6\VBE6EXT.OLB&quot; no_implementation raw_interfaces_only
#import &quot;C:\Program Files\Microsoft Office\OFFICE12\excel.exe&quot; no_implementation raw_interfaces_only
</pre>
</li>
<li>While this solved the problem of the _IMsoDispObj, it raised a few more issues.
<pre class="brush: cpp;">
warning C4003: not enough actual parameters for macro 'RGB'
warning C4003: not enough actual parameters for macro 'DialogBoxW'
</pre>
<p>Finally I had the solution, renaming the objects in question that seemed to be redefined elsewhere.</p>
<pre class="brush: cpp;">
#import &quot;C:\Program Files\Common Files\Microsoft Shared\OFFICE12\MSO.DLL&quot; no_implementation rename(&quot;RGB&quot;, &quot;ExclRGB&quot;) rename(&quot;DocumentProperties&quot;, &quot;ExclDocumentProperties&quot;) rename(&quot;SearchPath&quot;, &quot;ExclSearchPath&quot;)
#import &quot;C:\Program Files\Common Files\Microsoft Shared\VBA\VBA6\VBE6EXT.OLB&quot; no_implementation
#import &quot;D:\Program Files\Microsoft Office\OFFICE12\EXCEL.EXE&quot; rename(&quot;DialogBox&quot;, &quot;ExclDialogBox&quot;) rename(&quot;RGB&quot;, &quot;ExclRGB&quot;) rename(&quot;CopyFile&quot;, &quot;ExclCopyFile&quot;) rename(&quot;ReplaceText&quot;, &quot;ExclReplaceText&quot;)
</pre>
</li>
</ol>
<p>So in conclusion, in order to import the Excel 2007 Type Library in C++ and use it in your automations, 3 files must be imported, MSO.DLL, VBE6EXT.OLB, and EXCEL.EXE.  On top of those three files, various objects must be renamed due to already being defined.  In my case it was the DialogBox and RGB, though it may differ on each project depending on what is defined.  Here is the final code needed to import the type library.</p>
<pre class="brush: cpp;">
#import &quot;C:\Program Files\Common Files\Microsoft Shared\OFFICE12\MSO.DLL&quot; no_implementation rename(&quot;RGB&quot;, &quot;ExclRGB&quot;) rename(&quot;DocumentProperties&quot;, &quot;ExclDocumentProperties&quot;) rename(&quot;SearchPath&quot;, &quot;ExclSearchPath&quot;)
#import &quot;C:\Program Files\Common Files\Microsoft Shared\VBA\VBA6\VBE6EXT.OLB&quot; no_implementation
#import &quot;D:\Program Files\Microsoft Office\OFFICE12\EXCEL.EXE&quot; rename(&quot;DialogBox&quot;, &quot;ExclDialogBox&quot;) rename(&quot;RGB&quot;, &quot;ExclRGB&quot;) rename(&quot;CopyFile&quot;, &quot;ExclCopyFile&quot;) rename(&quot;ReplaceText&quot;, &quot;ExclReplaceText&quot;)
</pre>
<p>Useful Links:</p>
<ul>
<li><a href="http://groups.google.com/group/microsoft.public.vc.language/msg/d82ee4d7b85fbed1">Reading a cell from an Excel Worksheet</a></li>
<li><a href="http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/1de6c74f-6cf0-4d91-a5a9-e85853b867f6">Using Excel Type Library in VS 2005</a></li>
</ul>
<!-- sphereit end --><span style="margin-bottom:40px; border-bottom:none;"><a class="iconsphere" title="Sphere: Related Content" onclick="return Sphere.Widget.search('http://www.northatlantawebdesign.com/index.php/2009/07/21/automating-excel-2007-in-c-by-importing-the-excel-2007-type-library/')" href="http://www.sphere.com/search?q=sphereit:http://www.northatlantawebdesign.com/index.php/2009/07/21/automating-excel-2007-in-c-by-importing-the-excel-2007-type-library/">Sphere: Related Content</a></span><br/><br/>]]></content:encoded>
			<wfw:commentRss>http://www.northatlantawebdesign.com/index.php/2009/07/21/automating-excel-2007-in-c-by-importing-the-excel-2007-type-library/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
