<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://msmvps.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Cluebat-man to the rescue : Interoperability</title><link>http://msmvps.com/blogs/vandooren/archive/tags/Interoperability/default.aspx</link><description>Tags: Interoperability</description><dc:language>en</dc:language><generator>CommunityServer 2008.5 SP2 (Build: 40407.4157)</generator><item><title>Using reflection to ease code maintenance</title><link>http://msmvps.com/blogs/vandooren/archive/2008/12/02/using-reflection-to-ease-code-maintenance.aspx</link><pubDate>Tue, 02 Dec 2008 11:35:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1655548</guid><dc:creator>vanDooren</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/vandooren/rsscomments.aspx?PostID=1655548</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/vandooren/commentapi.aspx?PostID=1655548</wfw:comment><comments>http://msmvps.com/blogs/vandooren/archive/2008/12/02/using-reflection-to-ease-code-maintenance.aspx#comments</comments><description>&lt;p style="margin:6pt 0cm 0pt;" class="MsoNormal"&gt;&lt;span style="font-size:small;font-family:Times New Roman;"&gt;Currently I am programming an application for performing code analysis on the software that controls the production process. Apart from the parsing of the code, and iterating across a hierarchical representation of the expression tree, &lt;i style="mso-bidi-font-style:normal;"&gt;all&lt;/i&gt; these rules (verifications) have to be executed against all the code.&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:6pt 0cm 0pt;" class="MsoNormal"&gt;&lt;span style="font-size:small;font-family:Times New Roman;"&gt;I could change the code verifier every time I implemented a new rule, but instead I used reflection to do this for me. Every verification that has to be done is represented by a class that implements the right interface. This interface defines the prototype of the method that performs the verification.&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:6pt 0cm 0pt;" class="MsoNormal"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;mso-no-proof:yes;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;interface&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;IActionVerification&lt;br /&gt;&lt;/span&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;{&lt;br /&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;void&lt;/span&gt; Verify(&lt;span style="color:#2b91af;"&gt;CodeContext&lt;/span&gt; context);&lt;br /&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;}&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:6pt 0cm 0pt;" class="MsoNormal"&gt;&lt;span style="font-size:small;font-family:Times New Roman;"&gt;The context variable contains the complete context of the portion of the code that is being looked at: the current action, step, function block and phase.&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:6pt 0cm 0pt;" class="MsoNormal"&gt;&lt;span style="font-size:small;font-family:Times New Roman;"&gt;When a new code verifier instance is create, it will use reflection to examine the current assembly, and extract all classes that implement this interface.&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:6pt 0cm 0pt;" class="MsoNormal"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;mso-no-proof:yes;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;public&lt;/span&gt; CodeVerifier()&lt;br /&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;{&lt;br /&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;actionVerifications = &lt;span style="color:blue;"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af;"&gt;IActionVerification&lt;/span&gt;&amp;gt;();&lt;br /&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;var&lt;/span&gt; currAssembly = &lt;span style="color:#2b91af;"&gt;Assembly&lt;/span&gt;.GetExecutingAssembly();&lt;br /&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;foreach&lt;/span&gt;(&lt;span style="color:#2b91af;"&gt;Type&lt;/span&gt; t &lt;span style="color:blue;"&gt;in&lt;/span&gt; currAssembly.GetTypes())&lt;br /&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;{&lt;br /&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;if&lt;/span&gt; (&lt;span style="color:blue;"&gt;null&lt;/span&gt; != t.GetInterface(&lt;span style="color:blue;"&gt;typeof&lt;/span&gt;(&lt;span style="color:#2b91af;"&gt;IActionVerification&lt;/span&gt;).Name))&lt;br /&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;actionVerifications.Add(&lt;br /&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(&lt;span style="color:#2b91af;"&gt;IActionVerification&lt;/span&gt;)&lt;br /&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;currAssembly.CreateInstance(t.FullName));&lt;br /&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;}&lt;br /&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;}&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:6pt 0cm 0pt;" class="MsoNormal"&gt;&lt;span style="font-size:small;font-family:Times New Roman;"&gt;This way, it is very easy to populate the list of all verifications to do. The code verification itself is conceptually as simple as this:&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:6pt 0cm;" class="MsoNormal"&gt;&lt;span style="font-size:10pt;color:blue;font-family:&amp;#39;Courier New&amp;#39;;mso-no-proof:yes;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;foreach&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;mso-no-proof:yes;"&gt; (&lt;span style="color:blue;"&gt;var&lt;/span&gt; verification &lt;span style="color:blue;"&gt;in&lt;/span&gt; actionVerifications)&lt;br /&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;verification.Verify(context);&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0cm 0cm 6pt;" class="MsoNormal"&gt;&lt;span style="mso-no-proof:yes;"&gt;&lt;span style="font-size:small;"&gt;&lt;span style="font-family:Times New Roman;"&gt;Implementing a new verification is the as easy as creating a new class and implementing the interface. After that everything will be done automatically. Ading a new verification is as easy as this:&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0cm 0cm 6pt;" class="MsoNormal"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;mso-no-proof:yes;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;ActionExpressionCount&lt;/span&gt; : &lt;span style="color:#2b91af;"&gt;IActionVerification&lt;br /&gt;&lt;/span&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;{&lt;span style="color:gray;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;void&lt;/span&gt; Verify(&lt;span style="color:#2b91af;"&gt;CodeContext&lt;/span&gt; context)&lt;br /&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;{&lt;br /&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;if&lt;/span&gt; (context.Action.ParsedExpression.Count &amp;lt; 1)&lt;br /&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;ActionExpressionCountInvalid&lt;/span&gt;.LogIssue(context);&lt;br /&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;}&lt;br /&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;}&lt;/span&gt;&lt;span style="mso-no-proof:yes;"&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0cm 0cm 6pt;" class="MsoNormal"&gt;&lt;span style="mso-no-proof:yes;"&gt;&lt;span style="font-size:small;"&gt;&lt;span style="font-family:Times New Roman;"&gt;Hip hip hooray for the .NET framework!&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1655548" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/vandooren/archive/tags/Interoperability/default.aspx">Interoperability</category><category domain="http://msmvps.com/blogs/vandooren/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://msmvps.com/blogs/vandooren/archive/tags/.NET/default.aspx">.NET</category></item><item><title>C++ keyword of the day: export</title><link>http://msmvps.com/blogs/vandooren/archive/2008/09/24/c-keyword-of-the-day-export.aspx</link><pubDate>Wed, 24 Sep 2008 10:48:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1648758</guid><dc:creator>vanDooren</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/vandooren/rsscomments.aspx?PostID=1648758</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/vandooren/commentapi.aspx?PostID=1648758</wfw:comment><comments>http://msmvps.com/blogs/vandooren/archive/2008/09/24/c-keyword-of-the-day-export.aspx#comments</comments><description>&lt;p&gt;&lt;span style="font-size:7.5pt;color:black;font-family:Verdana;"&gt;The export keyword is a bit like the Higgs boson of C++. Theoretically it exists, it is described by the standard, and noone has seen it in the wild. :)&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size:7.5pt;color:black;font-family:Verdana;"&gt;Before I get flamed to hell and back: that last part is not entirely true. There is 1 C++ compiler front-end in the world which actually supports it. That is the one made by EDG (Edison Design Group). This is used by Comeau which claim to have the only compiler that is 100% standards compliant and Borland (for which the support of export is a bit vague). I heard that the Intel compiler shipped with it, but I don&amp;rsquo;t know if this is true or not.&lt;/span&gt;&lt;/p&gt;
&lt;h3 style="margin:12pt 0cm 3pt;"&gt;&lt;span style="font-size:medium;font-family:Arial;"&gt;What&amp;rsquo;s all the fuss about?&lt;/span&gt;&lt;/h3&gt;
&lt;p&gt;&lt;span style="font-size:7.5pt;color:black;font-family:Verdana;"&gt;It seems a bit strange that a language should contain a keyword that all compiler makers refuse to implement. Comeau has some &lt;a href="http://www.comeaucomputing.com/iso/promises.html" title="http://www.comeaucomputing.com/iso/promises.html"&gt;interesting content here&lt;/a&gt;&amp;nbsp;as does &lt;a href="http://en.wikipedia.org/wiki/Export_(C%2B%2B)#Standards_compliance" title="http://en.wikipedia.org/wiki/Export_(C%2B%2B)#Standards_compliance"&gt;Wikipedia&lt;/a&gt;.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size:7.5pt;color:black;font-family:Verdana;"&gt;The reason that I believe &amp;#39;export&amp;#39; has never really taken off is that is seems to be an significant effort to implement it, combined with the fact that is doesn&amp;#39;t achieve all that much. The export keyword allows a C++ programmer to declare a template class in a header, and then provide the implementation separately in a cpp file. This is the normal C++ way of doing things. Unfortunately, there&amp;#39;s a snag.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size:7.5pt;color:black;font-family:Verdana;"&gt;Template class implementations cannot be compiled on their own. Template code itself is meaningless without specification of template arguments. Thus it is that a compiler doesn&amp;#39;t know what to do with an implementation until the template class is used somewhere. At that point the template arguments will be known, and the compiler can compile the template class.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size:7.5pt;color:black;font-family:Verdana;"&gt;Since the template is only compiled then, the easiest thing to do would be to do what most compilers do now: demand that the implementation is in scope when it is used somewhere. I.e. the implementation has to be put in a header file, and that header file has to be included by the source file that is being compiled. the reason for this is that the compiler would simply not know where to look for it if the implementation was in a cpp file somewhere.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size:7.5pt;color:black;font-family:Verdana;"&gt;The export keyword would solve this by telling the compiler &amp;#39;Look somewhere else for the implementation&amp;#39;. The compiler would then have to compile the implementation for that class, and save the object code somewhere for that combination of template arguments.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size:7.5pt;color:black;font-family:Verdana;"&gt;The export keyword sounds like a great thing, but it doesn&amp;#39;t solve that many problems.&lt;/span&gt;&lt;/p&gt;
&lt;h3 style="margin:12pt 0cm 3pt;"&gt;&lt;span style="font-size:medium;font-family:Arial;"&gt;Separation of interface and implementation&lt;/span&gt;&lt;/h3&gt;
&lt;p&gt;&lt;span style="font-size:7.5pt;color:black;font-family:Verdana;mso-bidi-font-size:12.0pt;"&gt;The separation of interface and implementation is one of the cornerstones of C++ philosophy. The traditional way is to have the declaration in a header file, and then put the implementation in a cpp file.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size:7.5pt;color:black;font-family:Verdana;mso-bidi-font-size:12.0pt;"&gt;Since a template implementation cannot be compiled anyway, we could just as well put it in a header file.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size:7.5pt;color:black;font-family:Verdana;mso-bidi-font-size:12.0pt;"&gt;And then we could also make 1 header file with just the declarations, and underneath that include the header file(s) containing the implementation. The nice thing is that you can then put specializations in different headers to keep the code comprehensible.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size:7.5pt;color:black;font-family:Verdana;mso-bidi-font-size:12.0pt;"&gt;This way we keep true to the principle of separation without needing the &amp;lsquo;export&amp;rsquo; keyword&lt;/span&gt;&lt;/p&gt;
&lt;h3 style="margin:12pt 0cm 3pt;"&gt;&lt;span style="font-size:medium;font-family:Arial;"&gt;Distribution&lt;/span&gt;&lt;/h3&gt;
&lt;p&gt;&lt;span style="font-size:7.5pt;color:black;font-family:Verdana;mso-bidi-font-size:12.0pt;"&gt;You can&amp;rsquo;t distribute template classes in a binary form, no matter whether export is supported or not.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size:7.5pt;color:black;font-family:Verdana;mso-bidi-font-size:12.0pt;"&gt;Because templates cannot be compiled on their own, you cannot link them into a static or dynamic library. The only thing you can do is to distribute the source code.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size:7.5pt;color:black;font-family:Verdana;mso-bidi-font-size:12.0pt;"&gt;Templates are distributed as source code. The export keyword cannot do anything about that. And if you want to distribute templates, what are you going to do? You can develop your classes using &amp;lsquo;export&amp;rsquo;, but then they will be usable only by a very limited subset of compilers.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size:7.5pt;color:black;font-family:Verdana;mso-bidi-font-size:12.0pt;"&gt;If you develop your classes as if &amp;lsquo;export&amp;rsquo; doesn&amp;rsquo;t exist, then they can be used by all compilers.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size:7.5pt;color:black;font-family:Verdana;mso-bidi-font-size:12.0pt;"&gt;Of course you could do both, and use ugly macro magic to construct your code in such a way that would leave the choice to the client programmer. Some people do this. But that is kind of &lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&lt;/span&gt;ugly and time consuming. Furthermore, it&amp;rsquo;s not like it gets you any more clients, because they will be able to use your code in any case.&lt;/span&gt;&lt;/p&gt;
&lt;h3 style="margin:12pt 0cm 3pt;"&gt;&lt;span style="font-size:medium;font-family:Arial;"&gt;Compiler performance&lt;/span&gt;&lt;/h3&gt;
&lt;p&gt;&lt;span style="font-size:7.5pt;color:black;font-family:Verdana;mso-bidi-font-size:12.0pt;"&gt;It is true that our scheme of using header files is less efficient than using the export keyword. Without &amp;lsquo;export&amp;rsquo;, a template is compiled whenever it is used. You can mitigate this somewhat by including commonly used templates in a precompiled header file. But the impact will only be somewhat lessened.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size:7.5pt;color:black;font-family:Verdana;mso-bidi-font-size:12.0pt;"&gt;And whenever an implementation detail changes, every source file which includes the template has to be recompiled. This can be a real pain in large projects.&lt;/span&gt;&lt;/p&gt;
&lt;h3 style="margin:12pt 0cm 3pt;"&gt;&lt;span style="font-size:medium;font-family:Arial;"&gt;Conclusion&lt;/span&gt;&lt;/h3&gt;
&lt;p&gt;&lt;span style="font-size:7.5pt;color:black;font-family:Verdana;mso-bidi-font-size:12.0pt;"&gt;&amp;lsquo;export&amp;rsquo; is facing the chicken or the egg dilemma.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size:7.5pt;color:black;font-family:Verdana;mso-bidi-font-size:12.0pt;"&gt;&amp;lsquo;export&amp;rsquo; is neglected by most compiler vendors because it is not an important language feature -&amp;gt; You cannot use it in code that has to be portable (which is ironic, since it is a standard keyword) -&amp;gt; it is not used in many scenarios -&amp;gt; there is no large codebase depending on support for &amp;lsquo;export&amp;rsquo; -&amp;gt; there is little incentive for compiler vendors to start supporting it.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size:7.5pt;color:black;font-family:Verdana;mso-bidi-font-size:12.0pt;"&gt;Make no mistake: I would appreciate it if I could use &amp;lsquo;export&amp;rsquo;, if only because it allows me to organize my template implementations in a standard manner, but I don&amp;rsquo;t think it&amp;rsquo;ll happen soon. &lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1648758" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/vandooren/archive/tags/Interoperability/default.aspx">Interoperability</category><category domain="http://msmvps.com/blogs/vandooren/archive/tags/C_2B002B00_/default.aspx">C++</category></item><item><title>Extending a native C++ project with managed code</title><link>http://msmvps.com/blogs/vandooren/archive/2008/09/03/extending-a-native-c-project-with-managed-code.aspx</link><pubDate>Wed, 03 Sep 2008 09:59:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1646601</guid><dc:creator>vanDooren</dc:creator><slash:comments>5</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/vandooren/rsscomments.aspx?PostID=1646601</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/vandooren/commentapi.aspx?PostID=1646601</wfw:comment><comments>http://msmvps.com/blogs/vandooren/archive/2008/09/03/extending-a-native-c-project-with-managed-code.aspx#comments</comments><description>&lt;p style="margin:0cm 0cm 6pt;" class="MsoNormal"&gt;&lt;span style="font-size:small;font-family:Calibri;"&gt;One question that comes up from time to time in the newsgroups is &amp;lsquo;I have a native C++ project and I want to extend it with Managed code (e.g. Windows Forms). What do I do?&amp;rsquo;&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0cm 0cm 6pt;" class="MsoNormal"&gt;&lt;span style="font-size:small;font-family:Calibri;"&gt;The answer is not so complex. It is fairly easy to extend native projects with managed code. In this article I&amp;rsquo;ll explain how.&lt;/span&gt;&lt;/p&gt;
&lt;h2 style="margin:10pt 0cm 0pt;"&gt;&lt;span style="font-size:medium;color:#17365d;font-family:Calibri;"&gt;What NOT to do&lt;/span&gt;&lt;/h2&gt;
&lt;p style="margin:0cm 0cm 6pt;" class="MsoNormal"&gt;&lt;span style="font-size:small;font-family:Calibri;"&gt;To quote &lt;/span&gt;&lt;a href="http://www.gregcons.com/kateblog/"&gt;&lt;span style="font-size:small;font-family:Calibri;"&gt;Kate Gregory&lt;/span&gt;&lt;/a&gt;&lt;span style="font-size:small;font-family:Calibri;"&gt; &amp;lsquo;In the name of all that is good and right: Do not set /CLR for the entire project&amp;rsquo;.&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0cm 0cm 6pt;" class="MsoNormal"&gt;&lt;span style="font-size:small;font-family:Calibri;"&gt;/CLR tells the compiler that it should compile a source file as C++/CLI code in which it finds both native and managed C++ code. Theoretically you could specify this for the whole project, but this has some serious consequences.&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0cm 0cm 6pt;" class="MsoNormal"&gt;&lt;span style="font-size:small;font-family:Calibri;"&gt;Apart from the fact that it is possible for the compiled output size to explode, there can be significant problems with COM and CRT initialization. I am no interop expert in the matter like &lt;/span&gt;&lt;a href="http://www.heege.net/blog/default.aspx"&gt;&lt;span style="font-size:small;font-family:Calibri;"&gt;Marcus Heege&lt;/span&gt;&lt;/a&gt;&lt;span style="font-size:small;font-family:Calibri;"&gt; or Kate, but I am willing to take their word for it.&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0cm 0cm 6pt;" class="MsoNormal"&gt;&lt;span style="font-size:small;font-family:Calibri;"&gt;Furthermore, your existing project is possibly validated by QA en unit tested 7 days from Sunday. You don&amp;rsquo;t want to travel that road again if you can prevent it.&lt;/span&gt;&lt;/p&gt;
&lt;h2 style="margin:10pt 0cm 0pt;"&gt;&lt;span style="font-size:medium;color:#17365d;font-family:Calibri;"&gt;What to do&lt;/span&gt;&lt;/h2&gt;
&lt;p style="margin:0cm 0cm 6pt;" class="MsoNormal"&gt;&lt;span style="font-size:small;font-family:Calibri;"&gt;You want to add managed stuff to your project while impacting the rest of the code as little as humanly possible. To achieve this you have to compartmentalize the managed stuff and give it a native interface that you can use in the native parts of you projects without any hassle.&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0cm 0cm 6pt;" class="MsoNormal"&gt;&lt;span style="font-size:small;font-family:Calibri;"&gt;I think I can best explain this with a practical example.&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0cm 0cm 6pt;" class="MsoNormal"&gt;&lt;span style="font-size:small;font-family:Calibri;"&gt;For the sake of this example I have a native DLL project that exports a function that returns an integer value. Perhaps this function got that integer value previously through an MFC interface, and now that value has to come from a Windows Forms interface.&lt;/span&gt;&lt;/p&gt;
&lt;h3 style="margin:10pt 0cm 0pt;"&gt;&lt;span style="font-size:small;color:#17365d;font-family:Calibri;"&gt;Add the windows form to your project&lt;/span&gt;&lt;/h3&gt;
&lt;p style="margin:0cm 0cm 6pt;" class="MsoNormal"&gt;&lt;span style="font-size:small;font-family:Calibri;"&gt;This is the first and also the easiest step of the process. Rightclick your project and select &amp;lsquo;Add&amp;hellip;-&amp;gt;New Item&amp;rsquo; and select &amp;lsquo;UI-&amp;gt;Windows Form&amp;rsquo; in the Visual C++ dialog.&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0cm 0cm 6pt;" class="MsoNormal"&gt;&lt;span style="font-size:small;font-family:Calibri;"&gt;You will then get a message box, telling you that your project will be converted to a managed project. Here you click &amp;lsquo;yes&amp;rsquo;. Even though you don&amp;rsquo;t want to compile your project with /clr, Visual Studio itself needs to know that you are doing managed stuff in your project. This is not necessary for compiling your project, but if you want to have the benefit of working with the forms designer and other .NET related things, then it would be a good idea. And you cannot add the form if you choose &amp;lsquo;No&amp;rsquo; so it&amp;rsquo;s not like you have much choice anyway.&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0cm 0cm 6pt;" class="MsoNormal"&gt;&lt;span style="font-size:small;font-family:Calibri;"&gt;Now you have a .NET Windows Form in your code. You can verify the file specific settings if you want, but the cpp file will be compiled with the /clr flag set, and without the use of precompiled headers. Not using precompiled headers is important, because the default precompiled header is compiled without /clr set, and this would lead to conflicts.&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0cm 0cm 6pt;" class="MsoNormal"&gt;&lt;span style="font-size:small;font-family:Calibri;"&gt;Of course, if you need to, you can create a copy of StdAfx.h/cpp cpp files called &amp;lsquo;StdAfxClr.h/cpp&amp;rsquo; add them to your project, and configure them to create a managed precompiled header, which you could then use for all files that are compiled with /clr. This is not necessary for small projects, but it could be a useful optimization in large projects.&lt;/span&gt;&lt;/p&gt;
&lt;h3 style="margin:10pt 0cm 0pt;"&gt;&lt;span style="font-size:small;"&gt;&lt;span style="color:#17365d;"&gt;&lt;span style="font-family:Calibri;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&lt;/span&gt;The interface layer&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;p style="margin:0cm 0cm 6pt;" class="MsoNormal"&gt;&lt;span style="font-size:small;font-family:Calibri;"&gt;At this point you can compile and link the entire project, but your native code isn&amp;rsquo;t yet using the new managed functionality. And because the native code will not be compiled with /clr, it will never do so. In order to make that happen, you will need a thin layer between the native and managed code. This layer will have a native C or C++ interface which can be called by the native code, and a managed implementation that will do all the .NET stuff.&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0cm 0cm 6pt;" class="MsoNormal"&gt;&lt;span style="font-size:small;font-family:Calibri;"&gt;In our example, the interface is 1 simple C style function in Interface.h:&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0cm 0cm 6pt;" class="MsoNormal"&gt;&lt;span style="font-size:10pt;color:blue;font-family:&amp;#39;Courier New&amp;#39;;mso-no-proof:yes;"&gt;int&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;mso-no-proof:yes;"&gt; &lt;span style="color:blue;"&gt;__stdcall&lt;/span&gt; DoManagedStuff(&lt;span style="color:blue;"&gt;void&lt;/span&gt;);&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0cm 0cm 6pt;" class="MsoNormal"&gt;&lt;span style="font-size:small;font-family:Calibri;"&gt;And this function has a simple implementation in Interface.cpp:&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0cm 0cm 6pt;" class="MsoNormal"&gt;&lt;span style="font-size:10pt;color:blue;font-family:&amp;#39;Courier New&amp;#39;;mso-no-proof:yes;"&gt;int&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;mso-no-proof:yes;"&gt; &lt;span style="color:blue;"&gt;__stdcall&lt;/span&gt; DoManagedStuff(&lt;span style="color:blue;"&gt;void&lt;/span&gt;)&lt;br /&gt;{&lt;br /&gt;&lt;span style="mso-tab-count:1;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;DemoForm ^df = &lt;span style="color:blue;"&gt;gcnew&lt;/span&gt; DemoForm();&lt;br /&gt;&lt;span style="mso-tab-count:1;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;df-&amp;gt;ShowDialog();&lt;br /&gt;&lt;span style="mso-tab-count:1;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;return&lt;/span&gt; df-&amp;gt;Value;&lt;br /&gt;}&lt;/span&gt;&lt;span style="font-size:small;font-family:Calibri;"&gt; &lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0cm 0cm 6pt;" class="MsoNormal"&gt;&lt;span style="font-size:small;font-family:Calibri;"&gt;Interface.h and Interface.cpp are 2 new files that you have to add to your project. You have to manually configure the cpp file to be compiled with /clr, and to not use precompiled headers.&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0cm 0cm 6pt;" class="MsoNormal"&gt;&lt;span style="font-size:small;font-family:Calibri;"&gt;As you can see, the interface layer provides a clean native interface for the managed stuff that you want your code to perform. Of course, you are not limited to C style interfaces. You can also work with classes and make classes with a native interface and a managed implementation. But there are a couple of issues that you need to be aware of. If you want to go there, then it would be a good idea to read &lt;/span&gt;&lt;a href="http://www.gotw.ca/publications/C++CLIRationale.pdf"&gt;&lt;span style="font-size:small;font-family:Calibri;"&gt;the paper written by Herb Sutter&lt;/span&gt;&lt;/a&gt;&lt;span style="font-size:small;font-family:Calibri;"&gt; which explains the rationale behind C++/CLI, as well as some of the limitations and pitfalls.&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0cm 0cm 6pt;" class="MsoNormal"&gt;&lt;span style="font-size:small;font-family:Calibri;"&gt;Actually, reading that paper is a good idea for anyone working with C++/CLI who also cares about understanding what is actually going on behind the scenes.&lt;/span&gt;&lt;/p&gt;
&lt;h3 style="margin:10pt 0cm 0pt;"&gt;&lt;span style="font-size:small;color:#17365d;font-family:Calibri;"&gt;Using the interface layer&lt;/span&gt;&lt;/h3&gt;
&lt;p style="margin:0cm 0cm 6pt;" class="MsoNormal"&gt;&lt;span style="font-size:small;font-family:Calibri;"&gt;All the hard work is done. Now you can simply include Interface.h in your native code files, and call &amp;lsquo;DoManagedStuff&amp;rsquo; where appropriate.&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0cm 0cm 0pt;mso-layout-grid-align:none;" class="MsoNormal"&gt;&lt;span style="font-size:10pt;color:blue;font-family:&amp;#39;Courier New&amp;#39;;mso-no-proof:yes;"&gt;#include&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;mso-no-proof:yes;"&gt; &lt;span style="color:#a31515;"&gt;&amp;quot;stdafx.h&amp;quot;&lt;/span&gt;&lt;span style="color:blue;"&gt; &lt;br /&gt;#include&lt;/span&gt; &lt;span style="color:#a31515;"&gt;&amp;quot;InterfaceLayer.h&amp;quot;&lt;br /&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;int&lt;/span&gt; &lt;span style="color:blue;"&gt;__stdcall&lt;/span&gt; DoFoo(&lt;span style="color:blue;"&gt;void&lt;/span&gt;)&lt;br /&gt;{&lt;br /&gt;&lt;span style="mso-tab-count:1;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;return&lt;/span&gt; DoManagedStuff();&lt;br /&gt;}&lt;/span&gt;&lt;/p&gt;
&lt;h3 style="margin:10pt 0cm 0pt;"&gt;&lt;span style="font-size:small;color:#17365d;font-family:Calibri;"&gt;Conclusion&lt;/span&gt;&lt;/h3&gt;
&lt;p style="margin:0cm 0cm 6pt;" class="MsoNormal"&gt;&lt;span style="font-size:small;font-family:Calibri;"&gt;As you can see, extending native code with managed code is not so hard. At least, it isn&amp;rsquo;t if you maintain a clean break between managed and native code. If you cannot do this, things might become more difficult. For example, using .NET controls on an MFC dialog, or using .NET remoting in a native COM project are things that can be much more tricky.&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0cm 0cm 6pt;" class="MsoNormal"&gt;&lt;span style="font-size:small;font-family:Calibri;"&gt;Another thing you should be aware of is that not all compiler switches can be used in conjunction with the /clr&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;switch. The compiler will inform you if it detects this. The combinations which are not allowed are documented, and can be found in the documentation of the /clr switch itself.&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0cm 0cm 6pt;" class="MsoNormal"&gt;&lt;span style="font-size:small;font-family:Calibri;"&gt;This post was not meant to be an exhaustive how-to to those complex scenarios, but instead an explanation behind the basic ideas.&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0cm 0cm 6pt;" class="MsoNormal"&gt;&lt;span style="font-size:small;font-family:Calibri;"&gt;The demo project for this article can be downloaded under the MIT license as usual. &lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1646601" width="1" height="1"&gt;</description><enclosure url="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Components.PostAttachments/00.01.64.66.01/DemoDll.zip" length="18800" type="application/x-zip-compressed" /><category domain="http://msmvps.com/blogs/vandooren/archive/tags/Interoperability/default.aspx">Interoperability</category><category domain="http://msmvps.com/blogs/vandooren/archive/tags/C_2B002B00_/default.aspx">C++</category><category domain="http://msmvps.com/blogs/vandooren/archive/tags/.NET/default.aspx">.NET</category><category domain="http://msmvps.com/blogs/vandooren/archive/tags/cplusplus/default.aspx">cplusplus</category></item><item><title>Excel and OleDb stupidity</title><link>http://msmvps.com/blogs/vandooren/archive/2008/02/29/excel-and-oledb-stupidity.aspx</link><pubDate>Fri, 29 Feb 2008 20:47:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1528706</guid><dc:creator>vanDooren</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/vandooren/rsscomments.aspx?PostID=1528706</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/vandooren/commentapi.aspx?PostID=1528706</wfw:comment><comments>http://msmvps.com/blogs/vandooren/archive/2008/02/29/excel-and-oledb-stupidity.aspx#comments</comments><description>&lt;p&gt;This afternoon I was working on a Windows Forms app for the finance guys, to help them allocate costs to systems, proportional to predefined allocation keys.&lt;/p&gt;
&lt;p&gt;The app has to import Excel spreadsheet files and perform all the database actions.&lt;/p&gt;
&lt;p&gt;The key columns to uniquely identify a cost are text values. Unfortunately, some of those key values do not contain letters, but only numeric characters. And this is where it sucks to have to work with Excel.&lt;/p&gt;
&lt;p&gt;This is because Excel knows no datatypes. You can specify formatting for cells, but Excel ignores that when someone asks for cell data. Instead, it scans the first couple of rows to guess the datatype. By default it checks the first 8 rows. If those contains mixed values, it uses a specified default type for those values that are not numeric.&lt;/p&gt;
&lt;p&gt;This means that if you use OleDb to retrieve values, the column type can vary per row.&lt;/p&gt;
&lt;p&gt;What can you do about it? Well nothing really. You can tweak some values, and hope that you will never encounter the corner cases that you cannot do anything about. There is plenty of information to be found. One good explanation was &lt;a class="" href="http://www.brianpeek.com/blog/archive/2006/04/18/415.aspx"&gt;this&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;However, one of the finance guys gave me an incredibly useful tip, which you can use as a workaround. You have to manually make a couple of easy modifications to the excel file, and Excel will always use the text data type.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;div&gt;Assume that the offending data is in column 1, and that the first row is the header row.&amp;nbsp;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;
&lt;div&gt;You insert 2 empty columns to the right of the offending column.&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;
&lt;div&gt;Put an &amp;#39; in the first cell of the first empty column (B2).&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;
&lt;div&gt;Then enter =B2&amp;amp;B1in the cell B3.&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;
&lt;div&gt;Select B2 and B3, and double-click the bottom right corner of the selection box. This will copy the data from there to the last row.&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;
&lt;div&gt;B3 will now hold the data as text, because the &amp;#39; tells Excel that no matter what is in the cell, it is text.&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;
&lt;div&gt;Then you copy column 3, paste it as &amp;#39;values only&amp;#39; over column 1.&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;
&lt;div&gt;Delete columns 2 and 3 again.&lt;/div&gt;&lt;/li&gt;&lt;/ol&gt;
&lt;p&gt;Now you can read the column in OleDb and always get text values for that column.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1528706" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/vandooren/archive/tags/Interoperability/default.aspx">Interoperability</category><category domain="http://msmvps.com/blogs/vandooren/archive/tags/.NET/default.aspx">.NET</category><category domain="http://msmvps.com/blogs/vandooren/archive/tags/Excel/default.aspx">Excel</category></item><item><title>Executing LabVIEW VIs through C style function pointers via .NET</title><link>http://msmvps.com/blogs/vandooren/archive/2006/11/16/executing-labview-vis-through-c-style-function-pointers-via-net.aspx</link><pubDate>Thu, 16 Nov 2006 11:46:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:294594</guid><dc:creator>vanDooren</dc:creator><slash:comments>11</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/vandooren/rsscomments.aspx?PostID=294594</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/vandooren/commentapi.aspx?PostID=294594</wfw:comment><comments>http://msmvps.com/blogs/vandooren/archive/2006/11/16/executing-labview-vis-through-c-style-function-pointers-via-net.aspx#comments</comments><description>&lt;P class=MsoNormal style="MARGIN:0in 0in 6pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;Problems exist to be solved.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 6pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;Some problems are so complex that you cannot solve them when you need to. With other problems it is not a matter of complexity, but a matter of not having all the pieces of the puzzle.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 6pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;Some problems are so interesting that it pays to keep them in the back of your head, just in case you ever find that missing piece that allows you to solve them.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 6pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;One of those problems is that with the current LabVIEW external library interface it is impossible to execute LabVIEW VIs in a DLL through a C style function pointer.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 6pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;This feature does not exist, even though lots of programmers would really benefit from it.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 6pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;2 weeks ago I was active on the Visual C++ newsgroup as usual, when learned –by pure coincidence- about an advanced function in the .NET framework called Marshal.GetFunctionPointerForDelegate.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 6pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;I immediately realized that this was the key to solving the old C style function pointer issue&lt;/FONT&gt;&lt;/P&gt;
&lt;H2 style="MARGIN:12pt 0in 3pt;"&gt;&lt;EM&gt;Problem description&lt;/EM&gt;&lt;/H2&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 6pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;Suppose that we have a DLL that exports a function. This function takes a function pointer as an argument, to be executed sometime later to pass some data to the calling application.&lt;/FONT&gt;&lt;/P&gt;
&lt;H3 style="MARGIN:12pt 0in 3pt;"&gt;The Test DLL code&lt;/H3&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 6pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;The idea is to test the ability to run a LabVIEW VI through a function pointer. To test this we need a DLL which will test this for us.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 6pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;The following very simple test function has been created for this purpose.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 6pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;This is the expected prototype of the callback function&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 6pt;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';"&gt;typedef&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';"&gt; &lt;SPAN style="COLOR:blue;"&gt;void&lt;/SPAN&gt; (&lt;SPAN style="COLOR:blue;"&gt;__stdcall&lt;/SPAN&gt; *fSimpleCallBack)(&lt;SPAN style="COLOR:blue;"&gt;int&lt;/SPAN&gt; i);&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 6pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;And this is the DLL function that will perform our test:&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:green;FONT-FAMILY:'Courier New';"&gt;//Test of the simple callback&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';"&gt;void&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';"&gt; Simplefoo(&lt;SPAN style="COLOR:blue;"&gt;int&lt;/SPAN&gt; i, fSimpleCallBack cb)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';"&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;(cb)(i);&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:green;"&gt;//invoke the callback function.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 6pt;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';"&gt;}&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 6pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;As you can see, the LabVIEW VI will be executed with the supplied parameter through the supplied function pointer.&lt;/FONT&gt;&lt;/P&gt;
&lt;H2 style="MARGIN:12pt 0in 3pt;"&gt;&lt;EM&gt;Principal solution&lt;/EM&gt;&lt;/H2&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 6pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;The very first action has to be creating a .NET delegate of which the signature matches the signature of the CallBack function that is required.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 6pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;Then a proxy class is created with only 2 members: an event that is based on the new delegate function, and a method called ‘GetDelegate’.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 6pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;LabVIEW has the ability to link a LabVIEW VI with a .NET event. The VI prototype is generated automatically, and matches the event delegate signature.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 6pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;After registering a VI for the specified event, LabVIEW uses the GetDelegate method of our proxy class to extract the registered delegate from the event. That delegate is then converted to a function pointer via the ‘GetFunctionPointerForDelegate’ method of the Marshal class.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 6pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;That function pointer can then be supplied to a native function that can execute the LabVIEW VI directly through the function pointer without requiring any modification at all.&lt;/FONT&gt;&lt;/P&gt;
&lt;H3 style="MARGIN:12pt 0in 3pt;"&gt;A note on GetFunctionPointerForDelegate&lt;/H3&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 6pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;The documentation for this method is sparse. It seems that VS2005 and .NET2.0 were rushed out of the door without taking the time to fully document the more advanced functions and providing code samples in the documentation.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 6pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;Because of this, it is easy to miss that GetFunctionPointerForDelegate returns a pointer that uses the __stdcall calling convention by default.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 6pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;It is also easy to overlook the fact that you can change this.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 6pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;If you need a function pointer that uses another calling convention - e.g. __cdecl – then you can achieve this by applying the UnmanagedFunctionPointerAttribute attribute to the delegate definition.&lt;/FONT&gt;&lt;/P&gt;
&lt;H3 style="MARGIN:12pt 0in 3pt;"&gt;The .NET code&lt;/H3&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';"&gt;namespace&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';"&gt; FunctionPointerProxy&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';"&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR:blue;"&gt;class&lt;/SPAN&gt; &lt;SPAN style="COLOR:teal;"&gt;SimpleProxy&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:green;"&gt;//Marshal a simple integer parameter as 32 bit integer.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR:blue;"&gt;delegate&lt;/SPAN&gt; &lt;SPAN style="COLOR:blue;"&gt;void&lt;/SPAN&gt; &lt;SPAN style="COLOR:teal;"&gt;SimpleProxyDelegate&lt;/SPAN&gt;(&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;[&lt;SPAN style="COLOR:teal;"&gt;MarshalAs&lt;/SPAN&gt;(&lt;SPAN style="COLOR:teal;"&gt;UnmanagedType&lt;/SPAN&gt;.I4)] &lt;SPAN style="COLOR:blue;"&gt;int&lt;/SPAN&gt; i);&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';"&gt;&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:green;"&gt;//export an event because that is the only way we are going to get&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:green;"&gt;//LabVIEW to give use a delegate.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR:blue;"&gt;event&lt;/SPAN&gt; &lt;SPAN style="COLOR:teal;"&gt;SimpleProxyDelegate&lt;/SPAN&gt; SimpleEvent;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';"&gt;&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:green;"&gt;//extract the delegate from the event. If there was no event&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:green;"&gt;//registered, this will trigger an exception which is caught by the&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:green;"&gt;//LabVIEW .NET interface node. No need to worry about it here.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR:teal;"&gt;Delegate&lt;/SPAN&gt; GetDelegate()&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;return&lt;/SPAN&gt; SimpleEvent.GetInvocationList()[0];&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 6pt;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';"&gt;}&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 6pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;This is all the additional code you really need to make it work. The delegate function has to mirror the native callback prototype for 100%. To achieve this you have to use the MarshalAs attribute on each delegate parameter to insure correct behavior.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 6pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;The event simply has to exist because LabVIEW has only 1 way to produce a delegate for a VI, and that is by registering a VI to an event.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 6pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;And even then, the delegate is never directly accessible, so we have to create a ‘GetDelegate’ method that extracts the registered delegate, and returns it to LabVIEW.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 6pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;As far as the .NET framework is concerned, we could simply make the event and the GetDelegate method static to remove the need to instantiate an object that we won’t need for anything else. But there are 2 reasons why we don’t do that:&lt;/FONT&gt;&lt;/P&gt;
&lt;UL style="MARGIN-TOP:0in;"&gt;
&lt;LI class=MsoNormal style="MARGIN:0in 0in 6pt;mso-list:l1 level1 lfo3;tab-stops:list .5in;"&gt;&lt;FONT face="Times New Roman" size=3&gt;LabVIEW does not support registering VIs to static events.&lt;/FONT&gt;&lt;/LI&gt;
&lt;LI class=MsoNormal style="MARGIN:0in 0in 6pt;mso-list:l1 level1 lfo3;tab-stops:list .5in;"&gt;&lt;FONT face="Times New Roman" size=3&gt;Our GetDelegate function would need way to know which delegate you want to get, in case there are multiple instances of callback VIs. Since the event is tied to an instance, it is easy enough to keep track of the events in LabVIEW.&lt;/FONT&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;H3 style="MARGIN:12pt 0in 3pt;"&gt;The LabVIEW code&lt;/H3&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 6pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;LabVIEW code is graphical, so I have chosen to mark the different steps in the block diagram below, and then add an explanation of each step in a numbered list.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 6pt;"&gt;&lt;FONT size=3&gt;&lt;FONT face="Times New Roman"&gt;&lt;IMG style="WIDTH:963px;HEIGHT:341px;" height=341 src="http://www.bdvd.be/images/blog_lvcallback1/1_principle.jpg" width=963&gt;&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;OL style="MARGIN-TOP:0in;"&gt;
&lt;LI class=MsoNormal style="MARGIN:0in 0in 6pt;mso-list:l2 level1 lfo5;tab-stops:list .5in;"&gt;&lt;FONT face="Times New Roman" size=3&gt;Instantiate a new SimpleProxy Class. We only need it to access the event. Sadly, LabVIEW does not yet support static events.&lt;/FONT&gt;&lt;/LI&gt;
&lt;LI class=MsoNormal style="MARGIN:0in 0in 6pt;mso-list:l2 level1 lfo5;tab-stops:list .5in;"&gt;&lt;FONT face="Times New Roman" size=3&gt;Register a VI for the Event. The way to do this is to wire the SimpleProxy refnum to the event source and select the appropriate event. Right-click 'VI Ref' and select 'Create Callback VI'. This will automatically generate a VI with the correct input and output parameters for you. This will also automatically wire a static VI reference to the VI Ref input. User parameter can be any LabVIEW type at all that you want to pass to the VI when the .NET event is triggered. We don't need it, but if we did we would have to wire it before we generate the callback VI because it changes the VI prototype.&lt;/FONT&gt;&lt;/LI&gt;
&lt;LI class=MsoNormal style="MARGIN:0in 0in 6pt;mso-list:l2 level1 lfo5;tab-stops:list .5in;"&gt;&lt;FONT face="Times New Roman" size=3&gt;Now that the event is registered, we can simply get the .NET delegate that represents the VI callback out of it.&lt;/FONT&gt;&lt;/LI&gt;
&lt;LI class=MsoNormal style="MARGIN:0in 0in 6pt;mso-list:l2 level1 lfo5;tab-stops:list .5in;"&gt;&lt;FONT face="Times New Roman" size=3&gt;Use a static member of the Marshal class to get a funtion pointer to the delegate. This is where the magic happens. A native stub is generated for the delegate at runtime. The unmanaged parameter list is built according to the Marshalling attributes that were attached to the delegate signature.&lt;/FONT&gt;&lt;/LI&gt;
&lt;LI class=MsoNormal style="MARGIN:0in 0in 6pt;mso-list:l2 level1 lfo5;tab-stops:list .5in;"&gt;&lt;FONT face="Times New Roman" size=3&gt;Cast the Delegate IntPtr to an Int32. Pointers are 32 bit on the x386 platform. We need this 32 bit value to supply it to the DLL function call that expects a 32 bit function pointer. Note that this function pointer uses the standard calling convention by default (see below for more info).&lt;/FONT&gt;&lt;/LI&gt;
&lt;LI class=MsoNormal style="MARGIN:0in 0in 6pt;mso-list:l2 level1 lfo5;tab-stops:list .5in;"&gt;&lt;FONT face="Times New Roman" size=3&gt;We no longer need the FunctionPointer IntPtr. As long as the delegate itself is still in memory, the native stub will be valid.&lt;/FONT&gt;&lt;/LI&gt;
&lt;LI class=MsoNormal style="MARGIN:0in 0in 6pt;mso-list:l2 level1 lfo5;tab-stops:list .5in;"&gt;&lt;FONT face="Times New Roman" size=3&gt;Execute the DLL function. This function will use the supplied callback function pointer to execute the callback VI. It will pass the supplied int parameter to the callback vi at the time of the function call.&lt;/FONT&gt;&lt;/LI&gt;
&lt;LI class=MsoNormal style="MARGIN:0in 0in 6pt;mso-list:l2 level1 lfo5;tab-stops:list .5in;"&gt;&lt;FONT face="Times New Roman" size=3&gt;Unregister the Callback VI from the event, and close the various references that were opened.&lt;/FONT&gt;&lt;/LI&gt;&lt;/OL&gt;
&lt;H3 style="MARGIN:12pt 0in 3pt;"&gt;Running the test&lt;/H3&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 6pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;As is sometimes said: the proof is in the pudding.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 6pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;To verify that everything works as advertised, I have put a simple dialog box in the callback VI that displays the value of the integer parameter.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 6pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;Simply run the example and you will see the following dialog box:&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 6pt;"&gt;&lt;IMG style="WIDTH:214px;HEIGHT:104px;" height=104 src="http://www.bdvd.be/images/blog_lvcallback1/2_result.jpg" width=214&gt;&lt;/P&gt;
&lt;H2 style="MARGIN:12pt 0in 3pt;"&gt;&lt;EM&gt;Advanced implementation&lt;/EM&gt;&lt;/H2&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 6pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;The principal solution works, but is not yet ideal. Most importantly, there is too much clutter on the LabVIEW diagram for this solution to be aesthetically pleasing.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 6pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;There are too many manual actions that have to be repeated each time you implement a callback function. I also wanted to show you an example of a callback function that is a bit more complex.&lt;/FONT&gt;&lt;/P&gt;
&lt;H3 style="MARGIN:12pt 0in 3pt;"&gt;Test DLL&lt;/H3&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 6pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;Consider the following callback prototype that is a bit more complex than the previous one:&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';"&gt;typedef&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';"&gt; &lt;SPAN style="COLOR:blue;"&gt;void&lt;/SPAN&gt; (&lt;SPAN style="COLOR:blue;"&gt;__stdcall&lt;/SPAN&gt; *fAdvancedCallBack)(&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;int&lt;/SPAN&gt; i,&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;char&lt;/SPAN&gt;* aString,&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 6pt;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;wchar_t&lt;/SPAN&gt;* wString);&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 6pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;Here we need to supply an integer, an ASCII string and a UNICODE string. The function exported from the DLL has the following implementation:&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';"&gt;void&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';"&gt; Advancedfoo(&lt;SPAN style="COLOR:blue;"&gt;int&lt;/SPAN&gt; i, &lt;SPAN style="COLOR:blue;"&gt;char&lt;/SPAN&gt;* aString, fAdvancedCallBack cb)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';"&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;BSTR uString;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;int&lt;/SPAN&gt; aLength = lstrlenA(aString);&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;int&lt;/SPAN&gt; uLength = ::MultiByteToWideChar(&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;CP_ACP, 0, aString, aLength, 0, 0);&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;if&lt;/SPAN&gt;(0 &amp;lt; uLength)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;uString = SysAllocStringByteLen(0, uLength);&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;::MultiByteToWideChar(&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;CP_ACP, 0, aString, aLength, uString, uLength);&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;else&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;uString = L&lt;SPAN style="COLOR:maroon;"&gt;""&lt;/SPAN&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';"&gt;&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:green;"&gt;//invoke the callback function through its function pointer.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;(cb)(i, aString, uString);&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 6pt;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';"&gt;}&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 6pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;LabVIEW itself does not support UNICODE strings, so we manually transform the supplied ASCII string to UNICODE. Apart from that the function body only contains a function call via the supplied callback pointer.&lt;/FONT&gt;&lt;/P&gt;
&lt;H3 style="MARGIN:12pt 0in 3pt;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&lt;/SPAN&gt;.NET code&lt;/H3&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;[&lt;SPAN style="COLOR:teal;"&gt;UnmanagedFunctionPointerAttribute&lt;/SPAN&gt;(&lt;SPAN style="COLOR:teal;"&gt;CallingConvention&lt;/SPAN&gt;.Cdecl)]&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR:blue;"&gt;class&lt;/SPAN&gt; &lt;SPAN style="COLOR:teal;"&gt;AdvancedProxy&lt;/SPAN&gt; : &lt;SPAN style="COLOR:teal;"&gt;IProxy&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR:blue;"&gt;delegate&lt;/SPAN&gt; &lt;SPAN style="COLOR:blue;"&gt;int&lt;/SPAN&gt; &lt;SPAN style="COLOR:teal;"&gt;AdvancedProxyDelegate&lt;/SPAN&gt;(&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:green;"&gt;//A simple I4 parameter. Nothing special&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;[&lt;SPAN style="COLOR:teal;"&gt;MarshalAs&lt;/SPAN&gt;(&lt;SPAN style="COLOR:teal;"&gt;UnmanagedType&lt;/SPAN&gt;.I4)] &lt;SPAN style="COLOR:blue;"&gt;int&lt;/SPAN&gt; i,&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:green;"&gt;//An ASCII string. this will be marshalled as UNICODE on the&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:green;"&gt;//.NET side and ASCII on the unmanaged side.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;[&lt;SPAN style="COLOR:teal;"&gt;MarshalAs&lt;/SPAN&gt;(&lt;SPAN style="COLOR:teal;"&gt;UnmanagedType&lt;/SPAN&gt;.LPStr)] &lt;SPAN style="COLOR:blue;"&gt;string&lt;/SPAN&gt; aString,&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:green;"&gt;//A UNICODE string. This will be marshalled as UNICODE on the&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:green;"&gt;//.NET side, and UNICODE on the unmanaged side.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;[&lt;SPAN style="COLOR:teal;"&gt;MarshalAs&lt;/SPAN&gt;(&lt;SPAN style="COLOR:teal;"&gt;UnmanagedType&lt;/SPAN&gt;.LPWStr)] &lt;SPAN style="COLOR:blue;"&gt;string&lt;/SPAN&gt; wString);&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR:blue;"&gt;event&lt;/SPAN&gt; &lt;SPAN style="COLOR:teal;"&gt;AdvancedProxyDelegate&lt;/SPAN&gt; AdvancedEvent;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';"&gt;&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR:teal;"&gt;Delegate&lt;/SPAN&gt; GetDelegate()&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;return&lt;/SPAN&gt; AdvancedEvent.GetInvocationList()[0];&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 6pt;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;}&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 6pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;The meaning of the different parts is the same as with the SimpleProxy example. The only real difference – apart from the delegate signature of course – is that all classes that are used as a proxy between a LabVIEW VI and a function pointer should implement the interface IProxy.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 6pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;This interface has the following definition:&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;public&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';"&gt; &lt;SPAN style="COLOR:blue;"&gt;interface&lt;/SPAN&gt; &lt;SPAN style="COLOR:teal;"&gt;IProxy&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:teal;"&gt;Delegate&lt;/SPAN&gt; GetDelegate();&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 6pt;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;}&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 6pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;This allows us to make the LabVIEW code for getting a function pointer generic, instead of tied to the type of the callback delegate.&lt;/FONT&gt;&lt;/P&gt;
&lt;H3 style="MARGIN:12pt 0in 3pt;"&gt;LabVIEW code&lt;/H3&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 6pt;"&gt;&lt;IMG style="WIDTH:589px;HEIGHT:205px;" height=205 src="http://www.bdvd.be/images/blog_lvcallback1/3_advanced.gif" width=589&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 6pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;As you can see, the LabVIEW code is vastly simplified.&lt;/FONT&gt;&lt;/P&gt;
&lt;OL style="MARGIN-TOP:0in;"&gt;
&lt;LI class=MsoNormal style="MARGIN:0in 0in 6pt;mso-list:l5 level1 lfo6;tab-stops:list .5in;"&gt;&lt;FONT face="Times New Roman" size=3&gt;The only thing that we cannot make generic is the event registration, because the event and as a result the VI reference are strongly typed.&lt;/FONT&gt;&lt;/LI&gt;
&lt;LI class=MsoNormal style="MARGIN:0in 0in 6pt;mso-list:l5 level1 lfo6;tab-stops:list .5in;"&gt;&lt;FONT face="Times New Roman" size=3&gt;The process of retrieving the function pointer is generic because all proxy classes now implement the IProxy class for retrieving the event delegate.&lt;/FONT&gt;&lt;/LI&gt;
&lt;LI class=MsoNormal style="MARGIN:0in 0in 6pt;mso-list:l5 level1 lfo6;tab-stops:list .5in;"&gt;&lt;FONT face="Times New Roman" size=3&gt;The call to the test function in the DLL now also takes a string parameter that gets expanded to UNICODE inside the test function to supply the callback function with the correct parameters.&lt;/FONT&gt;&lt;/LI&gt;
&lt;LI class=MsoNormal style="MARGIN:0in 0in 6pt;mso-list:l5 level1 lfo6;tab-stops:list .5in;"&gt;&lt;FONT face="Times New Roman" size=3&gt;Cleanup of the event and references is also generic.&lt;/FONT&gt;&lt;/LI&gt;&lt;/OL&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 6pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;There are 2 new VIs. These are generic, so you can reuse them without limitation. This also makes it easy to support an asynchronous callback mechanism. You can register the event and supply the function pointer to the DLL.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 6pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;The DLL stores it inside, and uses it any time it needs to. Meanwhile, your LabVIEW program can continue processing. You can keep the references cluster around – for example in a buffer – until such time as you want to disable the callback mechanism again.&lt;/FONT&gt;&lt;/P&gt;
&lt;H2 style="MARGIN:12pt 0in 3pt;"&gt;&lt;EM&gt;Running the demo code&lt;/EM&gt;&lt;/H2&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 6pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;The Visual studio solution is for VS2005, and can be built with all versions of VS2005.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 6pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;The LabVIEW project uses version 8.2. You need at least version 8.0 to have decent .NET support, and I used 8.2 because that is the latest version at this moment.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 6pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;To run the demo, simply extract the sources and open and build the Visual studio solution. Then open the LV project and run the sample of your liking.&lt;/FONT&gt;&lt;/P&gt;
&lt;H2 style="MARGIN:12pt 0in 3pt;"&gt;&lt;EM&gt;Conclusion&lt;/EM&gt;&lt;/H2&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 6pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;This article has outlined a relatively simple way to directly execute a LabVIEW VI through a C style function pointer without having to write C or C++ code. The demo code for this article is available under the MIT license as usual.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 6pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;You still need to provide a .NET class library, but the code involved is so minimal and trivial that it should not stop anyone.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 6pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;This approach also makes it possible to use the wealth of win32 API functions that require a callback function without having to resort to writing C or C++ code.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 6pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;In the time it took me to write this article (which took longer than writing the code, as usual) I found 3 other ways to achieve the same result.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 6pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;One is an ugly kludge that only fakes the callback functionality. The other performs a true callback to a LabVIEW VI, but it is even uglier. The third one is fairly elegant but has some other limiting factors.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 6pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;I will explain those 3 lesser solutions in another article. Despite the fact that only one of them is useful; the principle behind all 3 of them might be of use in another situation.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 6pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;Finally, the whole LabVIEW and function pointer issue has existed for a long time among LabVIEW programmers. I have done a bit of research, and as far as I can tell, I am the first to ever solve this problem without requiring C or C++ code.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 6pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;So here and now I claim to be the first to implement and publicize a working C style function pointer callback mechanism in LabVIEW!&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 6pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;In my next article I will follow up with an example involving structures (Clusters in LabVIEW) and n dimensional arrays.&lt;/FONT&gt;&lt;/P&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=294594" width="1" height="1"&gt;</description><enclosure url="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Components.PostAttachments/00.00.29.45.94/LvFunctionPointerProxy1.zip" length="86568" type="application/x-zip-compressed" /><category domain="http://msmvps.com/blogs/vandooren/archive/tags/Interoperability/default.aspx">Interoperability</category><category domain="http://msmvps.com/blogs/vandooren/archive/tags/C_2B002B00_/default.aspx">C++</category><category domain="http://msmvps.com/blogs/vandooren/archive/tags/LabVIEW/default.aspx">LabVIEW</category><category domain="http://msmvps.com/blogs/vandooren/archive/tags/.NET/default.aspx">.NET</category></item><item><title>Fun with template classes: Manipulating LabVIEW arrays in C++, part 3</title><link>http://msmvps.com/blogs/vandooren/archive/2006/08/10/Fun-with-template-classes_3A00_-Manipulating-LabVIEW-arrays-in-C_2B002B002C00_-part-3.aspx</link><pubDate>Thu, 10 Aug 2006 20:45:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:145299</guid><dc:creator>vanDooren</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/vandooren/rsscomments.aspx?PostID=145299</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/vandooren/commentapi.aspx?PostID=145299</wfw:comment><comments>http://msmvps.com/blogs/vandooren/archive/2006/08/10/Fun-with-template-classes_3A00_-Manipulating-LabVIEW-arrays-in-C_2B002B002C00_-part-3.aspx#comments</comments><description>&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;This article is a follow up of my second article on interoperability for LabVIEW arrays in C++. That article provided a method for allowing programmers to index into multi dimensional arrays like this:&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;But that solution was a bit clunky. It involved 4 classes which had 5 [] operators and 2 implementations of the Resize function. There was also no support for memory access via memcpy or something else.&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;After a bit of redesign, I now have an improved implementation.&lt;/font&gt;&lt;/p&gt;&lt;h1 style="margin:12pt 0cm 3pt;"&gt;&lt;font size="5"&gt;The general idea&lt;/font&gt;&lt;/h1&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;Functionality is now split in 2 classes. There is a CLvArrayHandlePtr class that represents the array itself, and a CLvArrayIndexer class to provide the [] operator.&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;You can no longer index in the array object directly. The CLvArrayHandlePtr class is now meant solely for managing the array itself. This makes the array simpler.&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;The indexing functionality has been put in the CLvArrayIndexer class. Since all that class does is to provide a [] operator and an accessor for the data pointer, it is a very lightweight class that is easy to maintain.&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;This solution also makes it easier to add extra functionality later on as separate lightweight classes that are tailored to a specific purpose, instead of having to perform all modifications in a class that includes everything and the kitchen sink.&lt;/font&gt;&lt;/p&gt;&lt;h1 style="margin:12pt 0cm 3pt;"&gt;&lt;font size="5"&gt;The Revised Array Class&lt;/font&gt;&lt;/h1&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;The CLvArrayHandlePtr class is still a template class with a specialization for 1 dimensional arrays. The general principles behind the array has not been changed, so I am not going to reiterate all explanations over here. Instead, I will only explain the changes.&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;color:blue;font-family:&amp;#39;Courier New&amp;#39;;"&gt;template&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; &amp;lt;&lt;span style="color:blue;"&gt;class&lt;/span&gt; T, &lt;span style="color:blue;"&gt;int&lt;/span&gt; Q=1&amp;gt; &lt;span style="color:blue;"&gt;class&lt;/span&gt; CLvArrayHandlePtr&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;{&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;color:blue;font-family:&amp;#39;Courier New&amp;#39;;"&gt;public&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;:&lt;span style="color:green;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;color:blue;font-family:&amp;#39;Courier New&amp;#39;;"&gt;#pragma&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; &lt;span style="color:blue;"&gt;pack&lt;/span&gt;(&lt;span style="color:blue;"&gt;push&lt;/span&gt;)&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;color:blue;font-family:&amp;#39;Courier New&amp;#39;;"&gt;#pragma&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; &lt;span style="color:blue;"&gt;pack&lt;/span&gt;(1)&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;typedef&lt;/span&gt; &lt;span style="color:blue;"&gt;struct&lt;/span&gt; &lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;{&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;size dimSize[Q];&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;T data[1];&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;} t_LvArray, *p_LvArray, **h_LvArray;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;color:blue;font-family:&amp;#39;Courier New&amp;#39;;"&gt;#pragma&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; &lt;span style="color:blue;"&gt;pack&lt;/span&gt;(&lt;span style="color:blue;"&gt;pop&lt;/span&gt;)&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;color:green;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;h_LvArray* m_HandlePtr;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;int&lt;/span&gt; Resize(size DimSize[ Q]){ &amp;hellip; }&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;size_t GetSize(&lt;span style="color:blue;"&gt;void&lt;/span&gt;){ &amp;hellip; }&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;void&lt;/span&gt; GetDimSizes(size_t DimSizes[ Q]){ &amp;hellip; }&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;T* GetDataPtr(&lt;span style="color:blue;"&gt;void&lt;/span&gt;){ &amp;hellip; }&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;};&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;color:blue;font-family:&amp;#39;Courier New&amp;#39;;"&gt;template&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; &amp;lt;&lt;span style="color:blue;"&gt;class&lt;/span&gt; T&amp;gt; &lt;span style="color:blue;"&gt;class&lt;/span&gt; CLvArrayHandlePtr&amp;lt;T, 1&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;{&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;color:blue;font-family:&amp;#39;Courier New&amp;#39;;"&gt;public&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;:&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;color:blue;font-family:&amp;#39;Courier New&amp;#39;;"&gt;#pragma&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; &lt;span style="color:blue;"&gt;pack&lt;/span&gt;(&lt;span style="color:blue;"&gt;push&lt;/span&gt;)&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;color:blue;font-family:&amp;#39;Courier New&amp;#39;;"&gt;#pragma&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; &lt;span style="color:blue;"&gt;pack&lt;/span&gt;(1)&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;typedef&lt;/span&gt; &lt;span style="color:blue;"&gt;struct&lt;/span&gt; &lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;{&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;size_t dimSize;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;T data[1];&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;} t_LvArray, *p_LvArray, **h_LvArray;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;color:blue;font-family:&amp;#39;Courier New&amp;#39;;"&gt;#pragma&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; &lt;span style="color:blue;"&gt;pack&lt;/span&gt;(&lt;span style="color:blue;"&gt;pop&lt;/span&gt;)&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;h_LvArray* m_HandlePtr;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;color:green;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;int&lt;/span&gt; Resize(size_t DimSize){ &amp;hellip; }&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;size_t GetSize(&lt;span style="color:blue;"&gt;void&lt;/span&gt;){ &amp;hellip; }&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;void&lt;/span&gt; GetDimSizes(size_t &amp;amp;DimSize){ &amp;hellip; }&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;T* GetDataPtr(&lt;span style="color:blue;"&gt;void&lt;/span&gt;){ &amp;hellip; }&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;};&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;These classes have roughly the same methods as their previous versions. The most notable differences are:&lt;/font&gt;&lt;/p&gt;&lt;ul style="margin-top:0cm;"&gt;&lt;li class="MsoNormal" style="margin:0cm 0cm 6pt;tab-stops:list 36.0pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;They now use size_t for dimension sizes.&lt;/font&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="margin:0cm 0cm 6pt;tab-stops:list 36.0pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;There is a function for returning the pointer to the first element in the array.&lt;/font&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="margin:0cm 0cm 6pt;tab-stops:list 36.0pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;There is a function to retrieve the dimension sizes.&lt;/font&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;The last 2 points are necessary in order to cleanly work with the 2 new classes.&lt;/font&gt;&lt;/p&gt;&lt;h1 style="margin:12pt 0cm 3pt;"&gt;&lt;font size="5"&gt;The array indexer class&lt;/font&gt;&lt;/h1&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;The 2 new classes are used solely to allow indexing operations on the LabVIEW array. They have no other added functionality, so they are fairly simple.&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;color:blue;font-family:&amp;#39;Courier New&amp;#39;;"&gt;template&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; &amp;lt;&lt;span style="color:blue;"&gt;class&lt;/span&gt; T, &lt;span style="color:blue;"&gt;int&lt;/span&gt; Q=1&amp;gt; &lt;span style="color:blue;"&gt;class&lt;/span&gt; CLvArrayIndexer&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;{&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;color:blue;font-family:&amp;#39;Courier New&amp;#39;;"&gt;private&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;:&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;size_t m_TotalSize;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;size_t m_DimSizes[ Q];&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;T *m_Data;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;color:blue;font-family:&amp;#39;Courier New&amp;#39;;"&gt;public&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;:&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="color:green;"&gt;//create a new instance, based on an actual array.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;CLvArrayIndexer(CLvArrayHandlePtr&amp;lt;T, Q&amp;gt; LvArray)&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;{&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;m_TotalSize = LvArray.GetSize();&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;LvArray.GetDimSizes(m_DimSizes);&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;m_Data = LvArray.GetDataPtr();&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;}&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="color:green;"&gt;//create a new instance, based on a data pointer and dimension sizes&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;CLvArrayIndexer(size_t DimSizes[ Q], T* DataPtr)&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;{&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;for&lt;/span&gt;(&lt;span style="color:blue;"&gt;int&lt;/span&gt; i=0; i&amp;lt;Q; i++)&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;m_DimSizes[ i] = DimSizes[ i];&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;m_Data = DataPtr;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;}&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="color:green;"&gt;//return a new indexer with 1 dimension less.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;CLvArrayIndexer&amp;lt;T, Q-1&amp;gt; &lt;span style="color:blue;"&gt;operator&lt;/span&gt;[](size_t Index)&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;{&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;size_t subDimSize = 1;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;for&lt;/span&gt;(&lt;span style="color:blue;"&gt;int&lt;/span&gt; i=1; i&amp;lt;Q; i++)&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;subDimSize *= m_DimSizes[ i];&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;return&lt;/span&gt; CLvArrayIndexer&amp;lt;T, Q-1&amp;gt;(&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;m_DimSizes + 1,&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;m_Data + Index * subDimSize);&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;}&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="color:green;"&gt;//Get the size of the data segment that represents this subdimension&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;size_t GetSize(&lt;span style="color:blue;"&gt;void&lt;/span&gt;)&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;{&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;return&lt;/span&gt; m_TotalSize;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;}&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="color:green;"&gt;//Get the pointer to the first element of this subdimension&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;T* GetDataPtr(&lt;span style="color:blue;"&gt;void&lt;/span&gt;)&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;{&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;return&lt;/span&gt; m_Data;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;}&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;};&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;color:blue;font-family:&amp;#39;Courier New&amp;#39;;"&gt;template&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; &amp;lt;&lt;span style="color:blue;"&gt;class&lt;/span&gt; T&amp;gt; &lt;span style="color:blue;"&gt;class&lt;/span&gt; CLvArrayIndexer&amp;lt;T, 1&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;{&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;color:blue;font-family:&amp;#39;Courier New&amp;#39;;"&gt;private&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;:&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;size_t m_TotalSize;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;T *m_Data;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;color:blue;font-family:&amp;#39;Courier New&amp;#39;;"&gt;public&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;:&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="color:green;"&gt;//create a new instance, based on an actual array.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;CLvArrayIndexer(CLvArrayHandlePtr&amp;lt;T, 1&amp;gt; LvArray)&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;{&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;m_TotalSize = LvArray.GetSize();&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;m_Data = LvArray.GetDataPtr();&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;}&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="color:green;"&gt;//create a new instance, based on a data pointer and dimension sizes&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;CLvArrayIndexer(size_t DimSizes[1], T* DataPtr)&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;{&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;m_TotalSize = DimSizes[1];&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;m_Data = DataPtr;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;}&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="color:green;"&gt;//return a reference to the element at the specified index.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;T&amp;amp; &lt;span style="color:blue;"&gt;operator&lt;/span&gt;[](size_t Index)&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;{&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;return&lt;/span&gt; m_Data[Index];&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;}&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="color:green;"&gt;//Get the size of the data segment that represents this subdimension&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;size_t GetSize(&lt;span style="color:blue;"&gt;void&lt;/span&gt;)&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;{&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;return&lt;/span&gt; m_TotalSize;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;}&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="color:green;"&gt;//Get the pointer to the first element of this subdimension&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;T* GetDataPtr(&lt;span style="color:blue;"&gt;void&lt;/span&gt;)&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;{&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;return&lt;/span&gt; m_Data;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;}&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;};&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;As you can see, there are 2 constructors for creating an indexer. The first takes the original array as an argument. It uses the array methods for getting the data size and data pointers.&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;The second constructor takes the size and pointer directly. This is used byt CLvArrayIndexer classes that create another CLvArrayIndexer class with a lower dimension.&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;The [] operator itself is also pretty simple. For multi dimensional indexers, the [] operator returns a new indexer that has 1 less dimension than itself. For 1 dimensional array indexers, it returns a reference to an element inside the original array.&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;The trick here is that each next [] operator points to a more specific location inside the original array until 1 specific element is referenced.&lt;/font&gt;&lt;/p&gt;&lt;h1 style="margin:12pt 0cm 3pt;"&gt;&lt;font size="5"&gt;Using the array and indexer classes&lt;/font&gt;&lt;/h1&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;To use the array and indexer classes in not very different from the previous solution.&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;Given an array with the following declaration:&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;CLvArrayHandlePtr&amp;lt;&lt;span style="color:blue;"&gt;double&lt;/span&gt;, 3&amp;gt; Array;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;Using it is done like this:&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;size_t size[3] = {&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;requestCountPages,&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;requestCountRows,&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;requestCountColumns};&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;Array.Resize(size);&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;CLvArrayIndexer&amp;lt;&lt;span style="color:blue;"&gt;double&lt;/span&gt;, 3&amp;gt; indexer(Array);&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;double&lt;/span&gt; i=0;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;for&lt;/span&gt;(&lt;span style="color:blue;"&gt;int&lt;/span&gt; page=0; page&amp;lt;requestCountPages; page++)&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;for&lt;/span&gt;(&lt;span style="color:blue;"&gt;int&lt;/span&gt; row=0; row&amp;lt;requestCountRows; row++)&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;for&lt;/span&gt;(&lt;span style="color:blue;"&gt;int&lt;/span&gt; column=0; column&amp;lt;requestCountColumns; column++)&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;indexer[page][row][column] = i++;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;"&gt;&lt;span&gt;&lt;font size="3"&gt;&lt;font face="Times New Roman"&gt;Using the data pointer and size of a sub segment are of course as easy as&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;Memcpy(Target, indexer.GetDataPtr(), indexer.GetSize());&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;/span&gt;&lt;/p&gt;&lt;h1 style="margin:12pt 0cm 3pt;"&gt;&lt;span&gt;&lt;font size="5"&gt;Afterthoughts&lt;/font&gt;&lt;/span&gt;&lt;/h1&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;This solution is clean, and easy to use and maintain. I am fairly happy with it.&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;Of course, what I am not yet happy about is the lack of error handling. For example, the indexer class does not yet check if the array is actually allocated or not. If it isn&amp;rsquo;t, then the current solution will dereference a NULL pointer.&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;There is also no size checking to prevent indexers from going out of bounds.&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;But as before, this code is proof of concept code. I am toying with the idea of implementing those error handlers, but I want to do it in a way that allows you to use either C style return value error handling or C++ style exception handling. &lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;One possibility is to use error handling template classes. However, That will have to wait for next time.&lt;/font&gt;&lt;/p&gt;&lt;span style="font-size:12pt;font-family:&amp;#39;Times New Roman&amp;#39;;"&gt;The full code for the classes is available for download, together with the dll code and some LabVIEW vis for testing. Everything is licensed under the MIT license as usual.&lt;/span&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=145299" width="1" height="1"&gt;</description><enclosure url="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Components.PostAttachments/00.00.14.52.99/LvArrayTemplate_5F00_3.zip" length="28576" type="application/x-zip-compressed" /><category domain="http://msmvps.com/blogs/vandooren/archive/tags/Interoperability/default.aspx">Interoperability</category><category domain="http://msmvps.com/blogs/vandooren/archive/tags/C_2B002B00_/default.aspx">C++</category><category domain="http://msmvps.com/blogs/vandooren/archive/tags/LabVIEW/default.aspx">LabVIEW</category><category domain="http://msmvps.com/blogs/vandooren/archive/tags/cplusplus/default.aspx">cplusplus</category></item><item><title>Fun with template classes: Manipulating LabVIEW arrays in C++, part 2</title><link>http://msmvps.com/blogs/vandooren/archive/2006/05/19/Fun-with-C_2B002B00_-templates_3A00_-Manipulating-LabVIEW-arrays-in-C_2B002B002C00_-part-2.aspx</link><pubDate>Fri, 19 May 2006 08:49:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:139614</guid><dc:creator>vanDooren</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/vandooren/rsscomments.aspx?PostID=139614</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/vandooren/commentapi.aspx?PostID=139614</wfw:comment><comments>http://msmvps.com/blogs/vandooren/archive/2006/05/19/Fun-with-C_2B002B00_-templates_3A00_-Manipulating-LabVIEW-arrays-in-C_2B002B002C00_-part-2.aspx#comments</comments><description>&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;This article is a follow-up on a previous article: &lt;/font&gt;&lt;font face="Times New Roman" size="3"&gt;&lt;a href="http://msmvps.com/blogs/vandooren/archive/2006/05/16/Fun-with-templates_3A00_-Manipulating-LabVIEW-arrays-in-C_2B002B002C00_-part-1.aspx" title="&amp;#39;Manipulating LabVIEW arrays in C++&amp;#39;"&gt;&amp;#39;Manipulating LabVIEW arrays in C++&amp;#39;&lt;/a&gt;&lt;/font&gt;&lt;font face="Times New Roman" size="3"&gt; in which I&amp;rsquo;ve explained how you could use C++ template classes to work with LabVIEW arrays. There was one annoying issue left to solve: you couldn&amp;rsquo;t use the standard syntax for indexing in a multidimensional array.&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;I.e. the following code would not work:&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;for&lt;/span&gt;(&lt;span style="color:blue;"&gt;int&lt;/span&gt; row=0; row&amp;lt;requestCountRows; row++)&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;for&lt;/span&gt;(&lt;span style="color:blue;"&gt;int&lt;/span&gt; column=0; column&amp;lt;requestCountColumns; column++)&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Array[row][column] = i++;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;After some thinking I was able to redesign the CArrayHandlePtr class to be able to be used like that.&lt;/font&gt;&lt;/p&gt;&lt;h1 style="margin:12pt 0cm 3pt;"&gt;&lt;font size="5"&gt;The general idea&lt;/font&gt;&lt;/h1&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;The idea behind my solution is to let the [x] operator for an n dimensional array return a new instance of the CArrayHandlePtr class that represents a class with n-1 dimensions of which the first element points to the first element of the subset pointed to by the [x] operator.&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;In that case, the operation Array[row][column] = 5 is equivalent to ((Array[row]) [column] = 5;&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;Array[row] returns a temporary 1D array temp. temp is then indexed like this: temp[column]. Since temp is a 1D array, it returns a reference to a specific element.&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;This approach is scalable to as many dimensions as you want, because a multidimensional index statement is simply broken down into n -1 temporary elements, each of which has a number of dimensional which has 1 dimension les than the previous one.&lt;/font&gt;&lt;/p&gt;&lt;h1 style="margin:12pt 0cm 3pt;"&gt;&lt;font size="5"&gt;The implementation problem&lt;/font&gt;&lt;/h1&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;The problem with this approach is that LabVIEW arrays do no lend themselves directly to it. The data block is supposed to begin directly after the dimension sizes. To return an array class of a lesser number of dimensions would mean that the selected subset would have to be preceded by the dimension sizes. This is clearly not an option.&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;To solve this problem we need array helper classes.&lt;/font&gt;&lt;/p&gt;&lt;h1 style="margin:12pt 0cm 3pt;"&gt;&lt;font size="5"&gt;The helper classes&lt;/font&gt;&lt;/h1&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;The point of a helper class is to be able to target a subset of a multidimensional array. To do this they should have a independent dimension size specifiers and data pointer.&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;Apart from that, the helper class has 1 simple requirement: the [] operator has to return a new helper of 1 dimension less than itself. If its number of dimensions is 1, it has to return a reference to the specified element.&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;The helper classes look like this:&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;color:blue;font-family:&amp;#39;Courier New&amp;#39;;"&gt;template&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; &amp;lt;&lt;span style="color:blue;"&gt;class&lt;/span&gt; T, &lt;span style="color:blue;"&gt;int&lt;/span&gt; Q=1&amp;gt; &lt;span style="color:blue;"&gt;class&lt;/span&gt; CArrayHelper&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;{&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;color:blue;font-family:&amp;#39;Courier New&amp;#39;;"&gt;private&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;:&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;int32* m_Sizes; &lt;span style="color:green;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;T* m_Data;&lt;span style="color:green;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;color:blue;font-family:&amp;#39;Courier New&amp;#39;;"&gt;public&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;:&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;CArrayHelper(T* Data, int32 *Sizes)&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;{&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;m_Data = Data;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;m_Sizes = Sizes;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;}&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;CArrayHelper&amp;lt;T, Q-1&amp;gt; &lt;span style="color:blue;"&gt;operator&lt;/span&gt;[](&lt;span style="color:blue;"&gt;int&lt;/span&gt; Index)&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;{&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;int&lt;/span&gt; subsetSize = 1;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:green;"&gt;/*calculate the size of a complete subset*/&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;for&lt;/span&gt;(&lt;span style="color:blue;"&gt;int&lt;/span&gt; i=1; i&amp;lt;Q; i++)&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;subsetSize *= m_Sizes[ i];&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:green;"&gt;/*return an array helper that represents a subset of the original array*/&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;return&lt;/span&gt; CArrayHelper&amp;lt;T, Q-1&amp;gt;(m_Data + subsetSize * Index, m_Sizes +1);&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;}&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;};&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;color:green;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;color:blue;font-family:&amp;#39;Courier New&amp;#39;;"&gt;template&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; &amp;lt;&lt;span style="color:blue;"&gt;class&lt;/span&gt; T&amp;gt; &lt;span style="color:blue;"&gt;class&lt;/span&gt; CArrayHelper&amp;lt;T, 1&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;{&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;color:blue;font-family:&amp;#39;Courier New&amp;#39;;"&gt;private&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;:&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;int32* m_Sizes;&lt;span style="color:green;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;T* m_Data;&lt;span style="color:green;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;color:blue;font-family:&amp;#39;Courier New&amp;#39;;"&gt;public&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;:&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;CArrayHelper(T* Data, int32 *Sizes)&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;{&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;m_Data = Data;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;m_Sizes = Sizes;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;}&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;T&amp;amp; &lt;span style="color:blue;"&gt;operator&lt;/span&gt;[](&lt;span style="color:blue;"&gt;int&lt;/span&gt; Index)&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;{&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;return&lt;/span&gt; m_Data[Index];&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;}&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;};&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;As you can see, these classes are very simple. Their only purpose is to be able to provide a way to specify a subset of a multidimensional array. That way the [] operators can be concatenated to read 1 specific element.&lt;/font&gt;&lt;/p&gt;&lt;h1 style="margin:12pt 0cm 3pt;"&gt;&lt;font size="5"&gt;The actual array classes&lt;/font&gt;&lt;/h1&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;There are 2 array classes: one general one and one that is specialized for 1 dimensional arrays. The reason that the specialization is needed is that the [] operator for a multidimensional array should return an array helper class of 1 dimension less, while the [] operator for a 1 dimensional array should return a reference to an element in the array.&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;color:blue;font-family:&amp;#39;Courier New&amp;#39;;"&gt;template&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; &amp;lt;&lt;span style="color:blue;"&gt;class&lt;/span&gt; T, &lt;span style="color:blue;"&gt;int&lt;/span&gt; Q=1&amp;gt; &lt;span style="color:blue;"&gt;class&lt;/span&gt; CArrayHandlePtr&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;{&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;color:blue;font-family:&amp;#39;Courier New&amp;#39;;"&gt;public&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;:&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="color:green;"&gt;/*type definition for LabVIEW array handle*/&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;color:blue;font-family:&amp;#39;Courier New&amp;#39;;"&gt;#pragma&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; &lt;span style="color:blue;"&gt;pack&lt;/span&gt;(&lt;span style="color:blue;"&gt;push&lt;/span&gt;)&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;color:blue;font-family:&amp;#39;Courier New&amp;#39;;"&gt;#pragma&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; &lt;span style="color:blue;"&gt;pack&lt;/span&gt;(1)&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;typedef&lt;/span&gt; &lt;span style="color:blue;"&gt;struct&lt;/span&gt; &lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;{&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;int&lt;/span&gt; dimSize[Q];&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;T data[1];&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;} t_LvArray, *p_LvArray, **h_LvArray;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;color:blue;font-family:&amp;#39;Courier New&amp;#39;;"&gt;#pragma&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; &lt;span style="color:blue;"&gt;pack&lt;/span&gt;(&lt;span style="color:blue;"&gt;pop&lt;/span&gt;)&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;h_LvArray* m_HandlePtr;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="color:green;"&gt;/*resize the array*/&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;int&lt;/span&gt; Resize(&lt;span style="color:blue;"&gt;int&lt;/span&gt; DimSize[Q])&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;{&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:green;"&gt;/*implementation omitted*/&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;}&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;T&amp;amp; &lt;span style="color:blue;"&gt;operator&lt;/span&gt;[](&lt;span style="color:blue;"&gt;int&lt;/span&gt; Index[Q])&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;{&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:green;"&gt;/*implementation omitted*/&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;}&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;CArrayHelper&amp;lt;T, Q-1&amp;gt; &lt;span style="color:blue;"&gt;operator&lt;/span&gt;[](&lt;span style="color:blue;"&gt;int&lt;/span&gt; Index)&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;{&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;int&lt;/span&gt; subsetSize = 1;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:green;"&gt;/*calculate the size of a complete subset*/&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;for&lt;/span&gt;(&lt;span style="color:blue;"&gt;int&lt;/span&gt; i=1; i&amp;lt;Q; i++)&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;subsetSize *= (**m_HandlePtr)-&amp;gt;dimSize[ i];&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:green;"&gt;/*return an array helper that represents a subset of the original array*/&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;return&lt;/span&gt; CArrayHelper&amp;lt;T, Q-1&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;((T*)(**m_HandlePtr)-&amp;gt;data + subsetSize * Index,&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(int32*)(**m_HandlePtr)-&amp;gt;dimSize +1); &lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;}&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;};&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;color:blue;font-family:&amp;#39;Courier New&amp;#39;;"&gt;template&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; &amp;lt;&lt;span style="color:blue;"&gt;class&lt;/span&gt; T&amp;gt; &lt;span style="color:blue;"&gt;class&lt;/span&gt; CArrayHandlePtr&amp;lt;T, 1&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;{&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;color:blue;font-family:&amp;#39;Courier New&amp;#39;;"&gt;public&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;:&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="color:green;"&gt;/*type definition for LabVIEW array handle*/&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;typedef&lt;/span&gt; &lt;span style="color:blue;"&gt;struct&lt;/span&gt; &lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;{&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;int&lt;/span&gt; dimSize;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;T data[1];&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;} t_LvArray, *p_LvArray, **h_LvArray;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;h_LvArray* m_HandlePtr;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="color:green;"&gt;/*resize the array*/&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;void&lt;/span&gt; Resize(&lt;span style="color:blue;"&gt;int&lt;/span&gt; DimSize)&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;{&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:green;"&gt;/*implementation omitted*/&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;}&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;T&amp;amp; &lt;span style="color:blue;"&gt;operator&lt;/span&gt;[](&lt;span style="color:blue;"&gt;int&lt;/span&gt; Index)&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;{&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;return&lt;/span&gt; (**m_HandlePtr)-&amp;gt;data[Index];&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;}&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;};&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;As you can see, the generic array class allow you to use either a complete element specification via the [](int[Q]) operator, or a partial specification via the [](int) operator. The partial specification returns an array helper. One way or another, you will reach a single array element.&lt;/font&gt;&lt;/p&gt;&lt;h1 style="margin:12pt 0cm 3pt;"&gt;&lt;font size="5"&gt;Using the arrays&lt;/font&gt;&lt;/h1&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;You now have both syntax options for addressing elements inside the array. You can do it like this:&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;color:blue;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;for&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;(&lt;span style="color:blue;"&gt;int&lt;/span&gt; page=0; page&amp;lt;requestCountPages; page++)&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;for&lt;/span&gt;(&lt;span style="color:blue;"&gt;int&lt;/span&gt; row=0; row&amp;lt;requestCountRows; row++)&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;for&lt;/span&gt;(&lt;span style="color:blue;"&gt;int&lt;/span&gt; column=0; column&amp;lt;requestCountColumns; column++)&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Array[page][row][column] = i++;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;Or like this:&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;color:blue;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;int&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; index[3];&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;for&lt;/span&gt;(&lt;span style="color:blue;"&gt;int&lt;/span&gt; page=0; page&amp;lt;requestCountPages; page++)&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;{&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;index[0] = page;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;for&lt;/span&gt;(&lt;span style="color:blue;"&gt;int&lt;/span&gt; row=0; row&amp;lt;requestCountRows; row++)&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;{&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;index[1] = row;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;for&lt;/span&gt;(&lt;span style="color:blue;"&gt;int&lt;/span&gt; column=0; column&amp;lt;requestCountColumns; column++)&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;{&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;index[2] = column;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Array[index] = i++;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;}&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;}&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;}&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;Both have the same effect.&lt;/font&gt;&lt;/p&gt;&lt;h1 style="margin:12pt 0cm 3pt;"&gt;&lt;font size="5"&gt;Afterthoughts&lt;/font&gt;&lt;/h1&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;This solution is easier to use than my first LabVIEW array implementation, because you now have both syntax options for indexing in the array.&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;On top of that, I now know more about partial template specialization than before. It has been a lot of fun already. For my definition of fun at least.&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;I am still not satisfied with this solution though. We are now using a total of 4 classes, which have between them 5 [] operators and 2 implementations of the Resize function. Any method we want to add to the array class has to be implemented in both the generic and the specific class. There is also no compile time option to enable range checking. Nor has any attention been given to indexing performance optimization.&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;I think I will write another follow-up article to at least solve the multiple implementations problem.&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;As always, the complete dll and LabVIEW code can be downloaded used under the MIT license. Enjoy. [;-)]&lt;/font&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=139614" width="1" height="1"&gt;</description><enclosure url="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Components.PostAttachments/00.00.13.96.14/LvArrayTemplat_5F00_2.zip" length="25872" type="application/x-zip-compressed" /><category domain="http://msmvps.com/blogs/vandooren/archive/tags/Interoperability/default.aspx">Interoperability</category><category domain="http://msmvps.com/blogs/vandooren/archive/tags/C_2B002B00_/default.aspx">C++</category><category domain="http://msmvps.com/blogs/vandooren/archive/tags/LabVIEW/default.aspx">LabVIEW</category><category domain="http://msmvps.com/blogs/vandooren/archive/tags/cplusplus/default.aspx">cplusplus</category></item><item><title>Fun with template classes: Manipulating LabVIEW arrays in C++, part 1</title><link>http://msmvps.com/blogs/vandooren/archive/2006/05/16/Fun-with-templates_3A00_-Manipulating-LabVIEW-arrays-in-C_2B002B002C00_-part-1.aspx</link><pubDate>Tue, 16 May 2006 08:20:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:139591</guid><dc:creator>vanDooren</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/vandooren/rsscomments.aspx?PostID=139591</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/vandooren/commentapi.aspx?PostID=139591</wfw:comment><comments>http://msmvps.com/blogs/vandooren/archive/2006/05/16/Fun-with-templates_3A00_-Manipulating-LabVIEW-arrays-in-C_2B002B002C00_-part-1.aspx#comments</comments><description>&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;One of the best things about LabVIEW is its ability to call external code. This code can be used in the form of a dll, a CIN (custom compiled C code) an ActiveX object or a .NET class.&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;I have often created dlls (on windows) or shared object libraries (linux) to create an interface between LabVIEW and external native code.&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;This blog entry is about working with LabVIEW arrays in external code. This is simple as long as you create an interface that takes a pointer to the array data.&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;For data input this poses no problem. For data output this is also simple as long as you follow the C style: supply a valid data pointer, a buffer size and a pointer to a variable that will receive the number of elements written.&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;Of course, if you don&amp;rsquo;t know the number of elements in advance, your code becomes more complex, and will likely result in more external function calls and over-allocation.&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;To overcome this problem we need to dynamically allocate LabVIEW arrays in our external code that can be passed to LabVIEW. This is much more complex than working with a simple data pointer.&lt;/font&gt;&lt;/p&gt;&lt;h1 style="margin:12pt 0cm 3pt;"&gt;&lt;font size="5"&gt;What are LabVIEW arrays?&lt;/font&gt;&lt;/h1&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;A LabVIEW array is in fact a structure that contains a length specifier and the actual data elements. The C declaration is like this:&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;color:blue;font-family:&amp;#39;Courier New&amp;#39;;"&gt;typedef&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; &lt;span style="color:blue;"&gt;struct&lt;/span&gt; &lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;{&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;int&lt;/span&gt; dimSize;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;int&lt;/span&gt; data[1];&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;} t_LvArray, *p_LvArray, **h_LvArray;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;tab-stops:259.5pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;The array contains a dimension size specifier that indicates the size of the data part, and the data part itself.&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;tab-stops:259.5pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;The data part declaration is specified as an array with size 1. the reason for this is that the size specifier and the data are part of the same block of data, so data cannot be a pointer.&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;tab-stops:259.5pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;In order to be able to dereference data, it is declared as an array. The actual size is not 1, but whatever is mentioned in dimSize. It is only declared as an array of 1 byte because 0 sized arrays cannot exist in the C language.&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;tab-stops:259.5pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;Whenever LabVIEW has to pass a LabVIEW style array to external code, it does this by supplying a relocate able handle.&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;tab-stops:259.5pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;In case of multidimensional arrays the declaration is somewhat different:&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;color:blue;font-family:&amp;#39;Courier New&amp;#39;;"&gt;typedef&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; &lt;span style="color:blue;"&gt;struct&lt;/span&gt; &lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;{&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;int&lt;/span&gt; dimSize[NUM_DIMENSIONS];&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;int&lt;/span&gt; data[1];&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;} t_LvArray, *p_LvArray, **h_LvArray;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;tab-stops:259.5pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;Each dimension has an element in the dimSize array to indicate the size of that dimension. For a 3 dimensional array, this array has 3 elements.&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;tab-stops:259.5pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;The data block is still declared as a 1D array.&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;tab-stops:259.5pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;It is also worth to note that LabVIEW structures and arrays are packed with 1-byte alignment. I.e. there is no padding between structure fields to align variables on address boundaries. This means that declarations should be done like this to insure proper packing:&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;color:blue;font-family:&amp;#39;Courier New&amp;#39;;"&gt;#pragma&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; &lt;span style="color:blue;"&gt;pack&lt;/span&gt;(&lt;span style="color:blue;"&gt;push&lt;/span&gt;)&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;color:blue;font-family:&amp;#39;Courier New&amp;#39;;"&gt;#pragma&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; &lt;span style="color:blue;"&gt;pack&lt;/span&gt;(1)&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;typedef&lt;/span&gt; &lt;span style="color:blue;"&gt;struct&lt;/span&gt; &lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;{&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;int&lt;/span&gt; dimSize[Q];&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;T data[1];&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;} t_LvArray, *p_LvArray, **h_LvArray;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;tab-stops:259.5pt;"&gt;&lt;span style="font-size:10pt;color:blue;font-family:&amp;#39;Courier New&amp;#39;;"&gt;#pragma&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; &lt;span style="color:blue;"&gt;pack&lt;/span&gt;(&lt;span style="color:blue;"&gt;pop&lt;/span&gt;)&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;tab-stops:259.5pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;The syntax will be different for different compilers. This syntax is used with Microsoft Visual C++.&lt;/font&gt;&lt;/p&gt;&lt;h1 style="margin:12pt 0cm 3pt;"&gt;&lt;font size="5"&gt;What is the problem with LabVIEW arrays?&lt;/font&gt;&lt;/h1&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;tab-stops:259.5pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;On first glance the handles seem easy to use, but there are 2 distinct problems when you want to use them.&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;tab-stops:259.5pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;The first is simple you need a unique declaration for each data type and each number of dimensions for which you want to create an array.&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;color:blue;font-family:&amp;#39;Courier New&amp;#39;;"&gt;typedef&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; &lt;span style="color:blue;"&gt;struct&lt;/span&gt; &lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;{&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;int&lt;/span&gt; dimSize&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;int&lt;/span&gt; data[1];&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;} t_LvArrayInt1D, *p_LvArrayInt1D, **h_LvArrayInt1D;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;color:blue;font-family:&amp;#39;Courier New&amp;#39;;"&gt;typedef&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; &lt;span style="color:blue;"&gt;struct&lt;/span&gt; &lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;{&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;int&lt;/span&gt; dimSize;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;double&lt;/span&gt; data[1];&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;} t_LvArrayDbl1D, *p_LvArrayDbl1D, **h_LvArrayDbl1D;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;color:blue;font-family:&amp;#39;Courier New&amp;#39;;"&gt;typedef&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; &lt;span style="color:blue;"&gt;struct&lt;/span&gt; &lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;{&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;int&lt;/span&gt; dimSize[2];&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;double&lt;/span&gt; data[1];&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;} t_LvArrayDbl2D, *p_LvArrayDbl2D, **h_LvArrayDbl2D;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;tab-stops:259.5pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;This becomes tedious after a while, and it is cumbersome to maintain a whole header file of declarations for all possible types.&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;tab-stops:259.5pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;The second problem is that you have to manually do all the arithmetic for calculating the position in the data block. You have to have different calculations for each unique combination of data type and number of dimension size. This is very prone to errors, and even more tedious to maintain than the array declarations themselves. The standard indexing notation for multi dimensional array cannot be used because the array size can change at runtime.&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;tab-stops:259.5pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;The third problem is that it is impossible to represent a zero length array. Zero length C style arrays do not exist. Of course the LabVIEW memory manager programmers could have implemented a hack for this, but they didn&amp;rsquo;t.&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;tab-stops:259.5pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;This means that if you want to resize arrays for output, you need to create an interface that takes a pointer to a handle. This way you can allocate a new array if the handle is NULL, or you can resize it if it isn&amp;rsquo;t. As a result, you are now working with a pointer to a pointer to a pointer to a data block. That is a lot of dereferencing to take care of.&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;tab-stops:259.5pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;The fourth problem is that the code for resizing and allocating, like the code for indexing in the arrays is unique per data type and per dimension size.&lt;/font&gt;&lt;/p&gt;&lt;h1 style="margin:12pt 0cm 3pt;"&gt;&lt;font size="5"&gt;C++ template classes to the rescue&lt;/font&gt;&lt;/h1&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;tab-stops:259.5pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;Luckily for us, there is a way around all these issues: C++ template classes.&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;tab-stops:259.5pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;C++ template classes are the most complex but also most powerful feature of the C++ language. It allows you to define templates for classes and functions that are only specialized for specific types at compile time.&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;tab-stops:259.5pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;LabVIEW arrays of any type and number of dimensions can be implemented using the following class:&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;color:blue;font-family:&amp;#39;Courier New&amp;#39;;"&gt;template&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; &amp;lt;&lt;span style="color:blue;"&gt;class&lt;/span&gt; T, &lt;span style="color:blue;"&gt;int&lt;/span&gt; Q=1&amp;gt; &lt;span style="color:blue;"&gt;class&lt;/span&gt; CArrayHandlePtr&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;{&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;color:blue;font-family:&amp;#39;Courier New&amp;#39;;"&gt;public&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;:&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="color:green;"&gt;/*type definition for LabVIEW array handle*/&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;#pragma&lt;/span&gt; &lt;span style="color:blue;"&gt;pack&lt;/span&gt;(&lt;span style="color:blue;"&gt;push&lt;/span&gt;)&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;color:blue;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;#pragma&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; &lt;span style="color:blue;"&gt;pack&lt;/span&gt;(1)&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;typedef&lt;/span&gt; &lt;span style="color:blue;"&gt;struct&lt;/span&gt; &lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;{&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;int&lt;/span&gt; dimSize[Q];&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;T data[1];&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;} t_LvArray, *p_LvArray, **h_LvArray;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;color:blue;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;#pragma&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; &lt;span style="color:blue;"&gt;pack&lt;/span&gt;(&lt;span style="color:blue;"&gt;pop&lt;/span&gt;)&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;h_LvArray* m_HandlePtr;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="color:green;"&gt;/*resize the array*/&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;void&lt;/span&gt; Resize(&lt;span style="color:blue;"&gt;int&lt;/span&gt; DimSize[Q])&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;{&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:green;"&gt;/*implementation omitted*&lt;/span&gt;&lt;span style="color:blue;"&gt;/&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;}&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;T&amp;amp; &lt;span style="color:blue;"&gt;operator&lt;/span&gt;[](&lt;span style="color:blue;"&gt;int&lt;/span&gt; Index[Q])&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;{ &lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:green;"&gt;/*implementation omitted*&lt;/span&gt;&lt;span style="color:blue;"&gt;/&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;}&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;tab-stops:259.5pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;};&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;tab-stops:259.5pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;T and Q have to be supplied at compile time. T is the data type of the elements in the array, and Q is the number of dimensions. The compiler will create a correct implementation of t_LvArray that represents the LabVIEW style array.&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;tab-stops:259.5pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;The class has 2 other functions: a resize functions that allows you to resize the array (or to allocate it if the array handle was NULL), and a [] operator that returns a reference to the element specified in the Index array.&lt;/font&gt;&lt;/p&gt;&lt;h2 style="margin:12pt 0cm 3pt;"&gt;&lt;em&gt;The constructor trick&lt;/em&gt;&lt;/h2&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;tab-stops:259.5pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;The template class does not have a constructor. The reason for this is that there is no point in using true LabVIEW arrays except as function arguments to external code.&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;tab-stops:259.5pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;This means that the array handle pointer will be initialized by LabVIEW. The class has only 1 member variable: the handle pointer itself. If that is supplied by LabVIEW, we change its meaning from a simple address value to a templacized class instance.&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;tab-stops:259.5pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;This might seem a bit dodgy, but there is no constructor code that needs to be run. If the address member is initialized, the object is considered to be properly constructed. This is entirely legal C++ code.&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;tab-stops:259.5pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;The only downside is that we have to be sure that the definition of the data type in LabVIEW has to match what we think it to be. There is no way for the external code to know if the array is 2D or 3D for example. It is the responsibility of the programmer to insure this.&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;tab-stops:259.5pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;Of course, if you decide you want to use true LabVIEW arrays within your C++ code for internal purposes, you can add a constructor that will allocate memory through the LabVIEW memory manager. Just be sure to dispose of it afterwards, and to provide proper copy constructors to prevent heap errors.&lt;/font&gt;&lt;/p&gt;&lt;h2 style="margin:12pt 0cm 3pt;"&gt;&lt;em&gt;Resizing the array&lt;/em&gt;&lt;/h2&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;tab-stops:259.5pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;The implementation for the resize function is this:&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;int&lt;/span&gt; Resize(&lt;span style="color:blue;"&gt;int&lt;/span&gt; DimSize[Q])&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;{&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;int&lt;/span&gt; totalSize = 1;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;int&lt;/span&gt; errorCode = 0;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:green;"&gt;/*calculate number of elements*/&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;for&lt;/span&gt;(&lt;span style="color:blue;"&gt;int&lt;/span&gt; i=0; i&amp;lt;Q; i++)&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;totalSize *= DimSize[ i];&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:green;"&gt;/*convert to number of bytes*/&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;totalSize *= &lt;span style="color:blue;"&gt;sizeof&lt;/span&gt;(T);&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:green;"&gt;/*add size of the dimension array*/&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;totalSize += Q * &lt;span style="color:blue;"&gt;sizeof&lt;/span&gt;(int32);&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;if&lt;/span&gt;(0 &amp;gt;= totalSize)&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;return&lt;/span&gt; mgArgErr;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;if&lt;/span&gt;(NULL != *m_HandlePtr)&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;{&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;errorCode = DSSetHSzClr(*m_HandlePtr, totalSize);&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;if&lt;/span&gt;(noErr != errorCode)&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;return&lt;/span&gt; errorCode;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;}&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;else&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;{&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;*m_HandlePtr = (h_LvArray)DSNewHClr(totalSize);&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;if&lt;/span&gt;(NULL == *m_HandlePtr)&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;return&lt;/span&gt; mZoneErr;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;}&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;for&lt;/span&gt;(&lt;span style="color:blue;"&gt;int&lt;/span&gt; i=0; i&amp;lt;Q; i++)&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(**m_HandlePtr)-&amp;gt;dimSize[ i] = DimSize[ i];&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;return&lt;/span&gt; noErr;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;tab-stops:259.5pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;}&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;tab-stops:259.5pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;TotalSize is the size in bytes of the complete memory block, including the dimension size specifiers. Some extra checking is done to insure that the total size is a positive number.&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;tab-stops:259.5pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;Then the handle is resized if it was a valid handle, or a new handle is allocated if it was a NULL handle. Finally, the dimension sizes have to be filled in manually because the memory manager does not know this information.&lt;/font&gt;&lt;/p&gt;&lt;h2 style="margin:12pt 0cm 3pt;"&gt;&lt;em&gt;Indexing in the array&lt;/em&gt;&lt;/h2&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;tab-stops:259.5pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;The final functionality that has to be implemented is the [] operator that will allow the programmer to read and write values to and from a position in the array.&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;T&amp;amp; &lt;span style="color:blue;"&gt;operator&lt;/span&gt;[](&lt;span style="color:blue;"&gt;int&lt;/span&gt; Index[Q])&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;{&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;int&lt;/span&gt; index = 0;&lt;span style="color:green;"&gt;//sizeof(t_LvArray);&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;for&lt;/span&gt;(&lt;span style="color:blue;"&gt;int&lt;/span&gt; i=0; i&amp;lt;Q-1; i++)&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;{&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;int&lt;/span&gt; subSize = 1;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;for&lt;/span&gt;(&lt;span style="color:blue;"&gt;int&lt;/span&gt; j=1; j&amp;lt;Q; j++)&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;subSize *= Index[ i] * (**m_HandlePtr)-&amp;gt;dimSize[ j];&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;index += subSize;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;}&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;index += Index[Q-1];&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;return&lt;/span&gt; (**m_HandlePtr)-&amp;gt;data[index];&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;}&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;tab-stops:259.5pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;};&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;tab-stops:259.5pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;Because the real data block is just a flat 1D array, we have to calculate the position in the array that matches with the specified indices. This calculation is not so hard to understand:&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;tab-stops:259.5pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;With each dimension that is accounted for, the index in that dimension is multiplied with the total number of elements in a sub-dimension. This value (the subSize value) is calculated for each dimension except for the last dimension (the least significant dimension). That index is just added to the intermediate total because it has no number of elements per sub dimension.&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;tab-stops:259.5pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;The resulting index is the position in the 1D data block that represents the element at the specified multidimensional indices.&lt;/font&gt;&lt;/p&gt;&lt;h1 style="margin:12pt 0cm 3pt;"&gt;&lt;font size="5"&gt;Using the array&lt;/font&gt;&lt;/h1&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;Using the array is very simple, as can be seen in this example:&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;color:blue;font-family:&amp;#39;Courier New&amp;#39;;"&gt;int&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; fun2Ddouble(&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;int&lt;/span&gt; requestCountRows,&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;int&lt;/span&gt; requestCountColumns,&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;CArrayHandlePtr&amp;lt;&lt;span style="color:blue;"&gt;double&lt;/span&gt;, 2&amp;gt; Array)&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;{&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;int&lt;/span&gt; index[2] = {0,0};&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;int&lt;/span&gt; size[2] = {requestCountRows, requestCountColumns};&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;Array.Resize(size);&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;double&lt;/span&gt; i=0;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;for&lt;/span&gt;(&lt;span style="color:blue;"&gt;int&lt;/span&gt; row=0; row&amp;lt;requestCountRows; row++)&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="color:blue;"&gt;for&lt;/span&gt;(&lt;span style="color:blue;"&gt;int&lt;/span&gt; column=0; column&amp;lt;requestCountColumns; column++)&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;{&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;index[0] = row;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;index[1] = column;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Array[index] = i++;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;}&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;return&lt;/span&gt; 0;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;}&lt;/span&gt;&lt;/p&gt;&lt;h1 style="margin:12pt 0cm 3pt;"&gt;&lt;font size="5"&gt;Limitations of this design&lt;/font&gt;&lt;/h1&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;Using the magic of C++ templates, we are able to implement 1 class that can represent all LabVIEW arrays of any given size or data type.&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;That does not mean that we are totally satisfied however. The follow&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;It is regrettable that we have to use arrays as index to the [] operator. It would be nicer to be able to use true multidimensional array syntax. i.e:&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;for&lt;/span&gt;(&lt;span style="color:blue;"&gt;int&lt;/span&gt; row=0; row&amp;lt;requestCountRows; row++)&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;for&lt;/span&gt;(&lt;span style="color:blue;"&gt;int&lt;/span&gt; column=0; column&amp;lt;requestCountColumns; column++)&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Array[row][column] = i++;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;See the next chapter for some more info on that.&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;Another &amp;lsquo;problem&amp;rsquo; if you wish, is that the [] operator does not protect against buffer overflow. This is trivial to implement, but I have not done so for performance reasons. And after all, true C style arrays do not protect against it either. It would perhaps be a good idea to implement this using conditional compilation, enabling the programmer to turn this feature on or off at compile time. This is just proof of concept code however, so I am not going to do that for now.&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;A performance problem is also that the sub dimension sizes are recalculated for all dimensions, each time the [] operator is invoked. It would make more sense to store these values somewhere, but we cannot do that. The requirement that an instance of the template class is 100 % identical with the LabVIEW definition means that we are not allowed to store additional data in the class body.&lt;/font&gt;&lt;/p&gt;&lt;h1 style="margin:12pt 0cm 3pt;"&gt;&lt;font size="5"&gt;Afterthoughts&lt;/font&gt;&lt;/h1&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;This article explains how you can use C++ template classes to create 1 class that you can use to access LabVIEW arrays of any data type and number of dimension. Bear in mind that the code is just proof of concept code.&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;The example LabVIEW and C++ code is available for download under the MIT license.&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;I have already found a solution of the multidimensional syntax problem. With some additional programming it is possible to use the [row][column] notation for 2D arrays, and [page][row][column] notation for 3D arrays.&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;The solution is not limited by the number of dimensions (you could use 100D arrays for all I care) but it is a bit too complex to include it as part of this article.&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 6pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;I will dedicate my next blog article to the solution for that problem. &lt;/font&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=139591" width="1" height="1"&gt;</description><enclosure url="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Components.PostAttachments/00.00.13.95.91/LvArrayTemplate_5F00_1.zip" length="24049" type="application/x-zip-compressed" /><category domain="http://msmvps.com/blogs/vandooren/archive/tags/Interoperability/default.aspx">Interoperability</category><category domain="http://msmvps.com/blogs/vandooren/archive/tags/C_2B002B00_/default.aspx">C++</category><category domain="http://msmvps.com/blogs/vandooren/archive/tags/LabVIEW/default.aspx">LabVIEW</category><category domain="http://msmvps.com/blogs/vandooren/archive/tags/cplusplus/default.aspx">cplusplus</category></item><item><title>Interop between C++ and C or LabVIEW</title><link>http://msmvps.com/blogs/vandooren/archive/2006/05/11/Interop-between-C_2B002B00_-and-C-or-LabVIEW.aspx</link><pubDate>Thu, 11 May 2006 07:39:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:139582</guid><dc:creator>vanDooren</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/vandooren/rsscomments.aspx?PostID=139582</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/vandooren/commentapi.aspx?PostID=139582</wfw:comment><comments>http://msmvps.com/blogs/vandooren/archive/2006/05/11/Interop-between-C_2B002B00_-and-C-or-LabVIEW.aspx#comments</comments><description>&lt;p class="MsoNormal"&gt;One of the questions that recur from time to time is: &amp;lsquo;How
do I use C++ classes in a language that has only C bindings, like C itself or
LabVIEW?&amp;#39;&lt;/p&gt;


&lt;p class="MsoNormal"&gt;The short answer: you can&amp;rsquo;t.&lt;/p&gt;


&lt;p class="MsoNormal"&gt;The long answer: you can&amp;rsquo;t, but you can wrap the C++ code in
C functions, and export those in a wrapper dll, thus allowing you to manipulate
C++ objects through a C interface. &lt;br /&gt;
&lt;/p&gt;


&lt;h1&gt;The simple solution&lt;/h1&gt;


&lt;p class="MsoNormal"&gt;The general way to do this is to export a function for
creating objects that returns the object pointer to the caller. Another
function will take that pointer to do something with it, and a third function
will take the pointer to delete it.&lt;/p&gt;




&lt;p class="MsoNormal"&gt;You have to cast the pointer to something that can be
recognized by the caller. You cannot export a class pointer, because C or
LabVIEW have no idea what a class is. To be safe, you have to cast it to an
INT_PTR to insure that it is always large enough to hold a pointer.&lt;/p&gt;


&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;


&lt;p class="MsoNormal"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;#define&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; OBJPTR INT_PTR&lt;/span&gt;&lt;/p&gt;




&lt;p class="MsoNormal"&gt;The 3 essential functions look like this:&lt;/p&gt;












&lt;p class="MsoNormal"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;int&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;
simple_CreateObject(OBJPTR *ObjPtr)&lt;br /&gt;
{&lt;br /&gt;
&lt;span&gt;&amp;nbsp; &lt;/span&gt;*ObjPtr = (OBJPTR) &lt;span style="color:blue;"&gt;new&lt;/span&gt;
SomeClass();&lt;br /&gt;
&lt;span&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;if&lt;/span&gt;(NULL ==
*ObjPtr)&lt;br /&gt;
&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;return&lt;/span&gt; 1;&lt;/span&gt;&lt;/p&gt;






&lt;p class="MsoNormal"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;span&gt; &lt;/span&gt;&lt;span style="color:blue;"&gt;return&lt;/span&gt;
NO_ERROR;&lt;br /&gt;
}&lt;/span&gt;&lt;/p&gt;














&lt;p class="MsoNormal"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;int&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;
simple_UseObject(OBJPTR ObjPtr)&lt;br /&gt;
{&lt;br /&gt;
&lt;span&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;return&lt;/span&gt;
((SomeClass*)ObjPtr)-&amp;gt;DoSomething();&lt;br /&gt;
}&lt;/span&gt;&lt;/p&gt;

















&lt;p class="MsoNormal"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;int&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;
simple_DeleteObject(OBJPTR ObjPtr)&lt;br /&gt;
{&lt;br /&gt;
&lt;span&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;delete&lt;/span&gt;
(SomeClass*)ObjPtr;&lt;br /&gt;
&lt;span&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;return&lt;/span&gt;
NO_ERROR;&lt;br /&gt;
}&lt;/span&gt;&lt;/p&gt;





&lt;p class="MsoNormal"&gt;This approach is simple and it works. It has at least one
serious problem though: the application will crash if it accidentally asks the
wrapper to delete the same pointer twice, or to dereference an already deleted
pointer.&lt;/p&gt;





&lt;p class="MsoNormal"&gt;Especially if you develop this wrapper for use by LabVIEW, I
consider it bad taste if you do not shield the LabVIEW program against crashes
caused by trivial mistakes.&lt;/p&gt;&lt;h1&gt;A better solution&lt;/h1&gt;


&lt;p class="MsoNormal"&gt;A better solution is to map all object pointers to a unique
integer value. The calling program will only receive the integer values that it
can supply to other functions to manipulate the C++ object.&lt;/p&gt;





&lt;p class="MsoNormal"&gt;The other wrapper functions have to find the pointer that is
mapped to that integer value. If there is no mapping, it can simply return an
error code instead of crashing the application.&lt;/p&gt;





&lt;p class="MsoNormal"&gt;When the object is deleted it is removed from the map so
that the application cannot use it anymore.&lt;/p&gt;





&lt;p class="MsoNormal"&gt;The integer reference is incremented with each object that
is created so that there will never be a duplicate reference.&lt;/p&gt;





&lt;p class="MsoNormal"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;map&amp;lt;BETTER_OBJ_REF,
SomeClass*&amp;gt; g_PtrMap;&lt;/span&gt;&lt;/p&gt;


&lt;p class="MsoNormal"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;int&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; g_Index = 0;&lt;/span&gt;&lt;/p&gt;











&lt;p class="MsoNormal"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&lt;br /&gt;
int&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;
better_CreateObject(BETTER_OBJ_REF *ObjRef)&lt;br /&gt;
{&lt;br /&gt;
&lt;span&gt;&amp;nbsp; &lt;/span&gt;SomeClass* ptr = NULL;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;ptr = &lt;span style="color:blue;"&gt;new&lt;/span&gt;
SomeClass();&lt;/span&gt;&lt;/p&gt;





&lt;p class="MsoNormal"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;if&lt;/span&gt;(NULL ==
ptr)&lt;br /&gt;
&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;return&lt;/span&gt; 1;&lt;/span&gt;&lt;/p&gt;

















&lt;p class="MsoNormal"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;span&gt; &lt;/span&gt;&lt;span style="color:blue;"&gt;if&lt;/span&gt;(NO_ERROR
== errorCode)&lt;br /&gt;
&lt;span&gt;&amp;nbsp; &lt;/span&gt;{&lt;br /&gt;
&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;g_PtrMap[++g_Index] = ptr;&lt;br /&gt;
&lt;span&gt;&amp;nbsp; &lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;*ObjRef = g_Index;&lt;br /&gt;
&lt;span&gt;&amp;nbsp; &lt;/span&gt;}&lt;/span&gt;&lt;/p&gt;








&lt;p class="MsoNormal"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;span&gt; &lt;/span&gt;&lt;span style="color:blue;"&gt;return&lt;/span&gt;
NO_ERROR;&lt;br /&gt;
}&lt;/span&gt;&lt;/p&gt;











&lt;p class="MsoNormal"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&lt;br /&gt;
int&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;
better_UseObject(BETTER_OBJ_REF ObjRef)&lt;br /&gt;
{&lt;br /&gt;
&lt;span&gt;&amp;nbsp; &lt;/span&gt;map&amp;lt;BETTER_OBJ_REF,
SomeClass*&amp;gt;::iterator iter;&lt;br /&gt;
&lt;span&gt;&amp;nbsp; &lt;/span&gt;iter = g_PtrMap.find(ObjRef);&lt;/span&gt;&lt;/p&gt;






&lt;p class="MsoNormal"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;span&gt; &lt;/span&gt;&lt;span style="color:blue;"&gt;if&lt;/span&gt;(iter !=
g_PtrMap.end())&lt;br /&gt;
&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;return&lt;/span&gt;
(iter-&amp;gt;second)-&amp;gt;DoSomething();&lt;/span&gt;&lt;/p&gt;








&lt;p class="MsoNormal"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;&lt;span&gt;else&lt;br /&gt;
&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return&lt;/span&gt; 1;&lt;br /&gt;
}&lt;/span&gt;&lt;/p&gt;














&lt;p class="MsoNormal"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;int&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;
better_DeleteObject(BETTER_OBJ_REF ObjRef)&lt;br /&gt;
{&lt;br /&gt;
&lt;span&gt;&amp;nbsp; &lt;/span&gt;map&amp;lt;BETTER_OBJ_REF,
SomeClass*&amp;gt;::iterator iter;&lt;br /&gt;
&lt;span&gt;&amp;nbsp; &lt;/span&gt;iter = g_PtrMap.find(ObjRef);&lt;/span&gt;&lt;/p&gt;

















&lt;p class="MsoNormal"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;span&gt; &lt;/span&gt;&lt;span style="color:blue;"&gt;if&lt;/span&gt;(iter !=
g_PtrMap.end())&lt;br /&gt;
&lt;span&gt;&amp;nbsp; &lt;/span&gt;{&lt;br /&gt;
&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;SomeClass* ptr = iter-&amp;gt;second;&lt;br /&gt;
&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;g_PtrMap.erase(iter);&lt;br /&gt;
&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;delete&lt;/span&gt; ptr;&lt;/span&gt;&lt;/p&gt;


&lt;p class="MsoNormal"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;return &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;NO_ERROR;&lt;/span&gt;&lt;/p&gt;


&lt;p class="MsoNormal"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;}&lt;/span&gt;&lt;/p&gt;





&lt;p class="MsoNormal"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;&lt;span&gt;else&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;return&lt;/span&gt; 1;&lt;/span&gt;&lt;/p&gt;


&lt;p class="MsoNormal"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;}&lt;/span&gt;&lt;/p&gt;


&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;


&lt;h1&gt;Afterthoughts&lt;/h1&gt;


&lt;p class="MsoNormal"&gt;These 2 examples are proof of concept examples to
demonstrate how to use C++ objects in any language that has C bindings.&lt;/p&gt;





&lt;p class="MsoNormal"&gt;This is not production quality code though, because of the
following reasons:&lt;/p&gt;





&lt;ul style="margin-top:0cm;"&gt;
&lt;li class="MsoNormal"&gt;It
     does not catch C++ exceptions that could be thrown somewhere in the C++
     code.&lt;/li&gt;&lt;li class="MsoNormal"&gt;It
     does not properly handle the overflow of the g_Index variable after 2^32-1
     object allocations.&lt;/li&gt;&lt;li class="MsoNormal"&gt;There
     is no synchronization of access to the global map. This means the
     better_xxx functions are not safe for multithreaded usage.&lt;/li&gt;&lt;li class="MsoNormal"&gt;There
     is no NULL pointer checking in the simple_xxx functions yet.&lt;/li&gt;
&lt;/ul&gt;





&lt;p class="MsoNormal"&gt;You can download the demo project with C++ and LabVIEW code.
It is licensed under the MIT license so you can use it any way you want.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=139582" width="1" height="1"&gt;</description><enclosure url="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Components.PostAttachments/00.00.13.95.82/Dll.zip" length="77027" type="application/zip" /><category domain="http://msmvps.com/blogs/vandooren/archive/tags/Interoperability/default.aspx">Interoperability</category><category domain="http://msmvps.com/blogs/vandooren/archive/tags/C_2B002B00_/default.aspx">C++</category><category domain="http://msmvps.com/blogs/vandooren/archive/tags/LabVIEW/default.aspx">LabVIEW</category><category domain="http://msmvps.com/blogs/vandooren/archive/tags/cplusplus/default.aspx">cplusplus</category></item></channel></rss>