<?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</title><link>http://msmvps.com/blogs/vandooren/default.aspx</link><description>A weblog dedicated to Visual C++, interoperability and other stuff.</description><dc:language>en</dc:language><generator>CommunityServer 2008 SP1 (Build: 30619.63)</generator><item><title>How not to ask question on a forum</title><link>http://msmvps.com/blogs/vandooren/archive/2008/10/06/how-not-to-ask-question-on-a-forum.aspx</link><pubDate>Mon, 06 Oct 2008 06:29:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1649846</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=1649846</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/vandooren/commentapi.aspx?PostID=1649846</wfw:comment><comments>http://msmvps.com/blogs/vandooren/archive/2008/10/06/how-not-to-ask-question-on-a-forum.aspx#comments</comments><description>&lt;p&gt;&lt;a href="http://social.msdn.microsoft.com/Forums/en-US/vclanguage/thread/2e693be9-a672-4f81-b729-42ad9aefcaa6" title="http://social.msdn.microsoft.com/Forums/en-US/vclanguage/thread/2e693be9-a672-4f81-b729-42ad9aefcaa6"&gt;Here is another person who needs to learn some netiquette&lt;/a&gt; (emphasis mine).&lt;/p&gt;
&lt;p style="PADDING-LEFT:30px;"&gt;Hey,&lt;br /&gt;&lt;strong&gt;well, I will not describe my situation because it is not part of my question and has nothing directly to do with it and would only lead to false assumptions as it already did...&lt;br /&gt;&lt;/strong&gt;My question is ... &amp;lt;snip&amp;gt;&lt;br /&gt;&lt;strong&gt;Not that I am implying anything, but seeing that the discussion may drift to an entirely different topic directly, please do not return the question of why I am wanting to do this. I do know what I am doing and why I would need this&lt;/strong&gt;.&lt;br /&gt;&lt;br /&gt;Any help would be greatly appreciated.&lt;br /&gt;Regards,&lt;br /&gt;pd&lt;/p&gt;
&lt;p&gt;His question would have a much better chance of being answered if he&amp;#39;d recognised that the people answering questions are actual people. We are volunteers, doing this to help and because some questions are actually very interesting. Treating us like helpdesk personnel is not something that we generally appreciate.&lt;/p&gt;
&lt;p&gt;We sometimes spend a lot of effort to answer a complex question if&amp;nbsp;the situation is very interesting. Or perhaps because the issue is something advanced that might be helpful to ourselves one day. Denying us the interesting bits and treating us like&amp;nbsp;a bad&amp;nbsp;manager treats his serfs is more likely to cause the reaction &amp;#39;well, in that case figure it out on your own&amp;#39;.&lt;/p&gt;
&lt;p&gt;And apart from the fact that the motivation to answer has left me already, the thing with complex questions is that the devil is in the details. If you don&amp;#39;t tell us&amp;nbsp;exactly what you are trying to do, and which problem you are trying to solve, then how are we supposed to know a) what causes the problem, and b) how to solve it.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;EDIT: I discovered after some digging that he had asked this question before, and the original&amp;nbsp;thread was closed by a moderator because it could be useful to malware authors. Personally I don&amp;#39;t agree with this decision. But the OP should have mentioned this in his new thread. That way we would have known something more. And it doesn&amp;#39;t change the fact that he should have described his problem more clearly.&lt;/em&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1649846" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/vandooren/archive/tags/General/default.aspx">General</category><category domain="http://msmvps.com/blogs/vandooren/archive/tags/C_2B002B00_/default.aspx">C++</category></item><item><title>The sadness of waste</title><link>http://msmvps.com/blogs/vandooren/archive/2008/10/03/the-sadness-of-waste.aspx</link><pubDate>Fri, 03 Oct 2008 08:59:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1649588</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=1649588</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/vandooren/commentapi.aspx?PostID=1649588</wfw:comment><comments>http://msmvps.com/blogs/vandooren/archive/2008/10/03/the-sadness-of-waste.aspx#comments</comments><description>&lt;p&gt;One of the downsides of working for a big corporation is that there are strict rules for dealing with obsolete equipment.&lt;/p&gt;
&lt;p&gt;We have 3 DELL 2600 servers with Dual CPU Xeon cpu, SCSI raid5, 4GB RAM ready to make their final trip to the dumpster.&lt;br /&gt;We cannot use them anymore for plant systems because they are obsolete and out of support. Also the hdds are ultrawide, ultrafast SCSI (which cost $$$ to replace)&lt;br /&gt;Aside from that, they have the usual old age problem: no DVD (only CD-Rom) no USB2.&lt;br /&gt;And they are too big and noisy to use as test systems (as opposed to the 2U 2650s that we are going to keep just for that).&lt;/p&gt;
&lt;p&gt;I would love to have even one of those machines in my basement as a home server, but it is not going to happen.&lt;br /&gt;Corporate policy forbids employees from taking or even buying obsolete equipment.&lt;br /&gt;In the beginning (long before my time) it was allowed, but at a certain point there were problems, so now there has to be a documented paper trail for the destruction of all things going to the digital eternity, or a documented sign over to a charity or school.&lt;/p&gt;
&lt;p&gt;We are going to try and give them away to a charity or school because it hurts to see those perfectly usable machines (except for the disks, which are shot) destroyed. But if that fails for one reason or other, they will be destroyed. :(&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1649588" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/vandooren/archive/tags/General/default.aspx">General</category></item><item><title>Programmer discovers that floating point numbers have a floating point</title><link>http://msmvps.com/blogs/vandooren/archive/2008/10/02/programmer-discovers-that-floating-point-numbers-have-a-floating-point.aspx</link><pubDate>Thu, 02 Oct 2008 05:05:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1649143</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=1649143</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/vandooren/commentapi.aspx?PostID=1649143</wfw:comment><comments>http://msmvps.com/blogs/vandooren/archive/2008/10/02/programmer-discovers-that-floating-point-numbers-have-a-floating-point.aspx#comments</comments><description>&lt;p class="MsoNormal"&gt;&lt;span style="font-size:small;font-family:Times New Roman;"&gt;I hang out in the MSDN forums on a regular basis, to see if there&amp;rsquo;re any questions that need answering. Usualy this is pretty unexciting, but every now and again, the asker really needs a reality check.&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;a href="http://social.msdn.microsoft.com/Forums/en-US/vclanguage/thread/6b48c8ad-6920-41ba-ba9b-ae2054a35bcf"&gt;&lt;span style="font-size:small;font-family:Times New Roman;"&gt;This thread&lt;/span&gt;&lt;/a&gt;&lt;span style="font-size:small;font-family:Times New Roman;"&gt; came up some time ago, and it refuses to die.&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-size:small;font-family:Times New Roman;"&gt;The first thing that stands out is the title itself : &amp;lsquo;&lt;b style="mso-bidi-font-weight:normal;"&gt;A very serious bug in MS Visual C++&lt;/b&gt;&amp;rsquo;. Sensationalist headlines like this almost always indicate a serious misunderstanding on the part of the author. It also indicates someone who is very, very sure of himself, because it excludes any possibility that he himself might be wrong.&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-size:small;font-family:Times New Roman;"&gt;The initial message itself was the classical example of &amp;lsquo;newbie discovers floating point numbers, it&amp;rsquo;s the end of the world as we know it&amp;rsquo;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-size:small;font-family:Times New Roman;"&gt;If you haven&amp;rsquo;t bothered following the link, this is his gripe:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size:9.5pt;color:#080808;font-family:Verdana;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; double a=111.567,b=111,c;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; c=a-b;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // and you will receive&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //a=111.56699999999999&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //b=111.00000000000000&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //c=0.56699999999999307&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //instead =&amp;gt; a=111.567, b=111, c=0.567;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-size:small;font-family:Times New Roman;"&gt;Yawn&amp;hellip; another programmer who discovers that the floating point format does not guarantee fixed decimal correctness. The results are correct within the required precision of the floating point format, so all is well.&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-size:small;font-family:Times New Roman;"&gt;A is no 111.567 because it is a floating point number, and not a fixed point number. In any case, googling for &amp;lsquo;&lt;i style="mso-bidi-font-style:normal;"&gt;what every computer programmer should know about floating point&lt;/i&gt;&amp;rsquo; will get you a paper that explains this issue in detail.&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-size:small;font-family:Times New Roman;"&gt;The original poster also explains that he has tested with every compiler from VC6 to VC2008, and they are all wrong. That in itself should have been a clue to think twice before using such a preposterous title.&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-size:small;font-family:Times New Roman;"&gt;Various people tried to explain the problem, but to no avail. Here are a handful of quotes from the OP (who is building an ERP system...)&amp;nbsp;in the course of the discussion:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size:10pt;color:#080808;font-family:Symbol;mso-bidi-font-size:9.5pt;mso-fareast-font-family:Symbol;mso-bidi-font-family:Symbol;"&gt;&lt;span style="mso-list:Ignore;"&gt;&amp;middot;&lt;span style="font-family:&amp;#39;Times New Roman&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:9.5pt;color:#080808;font-family:Verdana;"&gt;Industry standard ??? I am not agreeing with you. There are laws of mathematics which must be respected by all. I can not agree that 111,567 is equal to 111.56699999999999 because of simple reason that it is not equal.&lt;/span&gt;&lt;/p&gt;
&lt;ul style="margin-top:0cm;"&gt;
&lt;li style="background:white;margin:6pt 6pt 6pt 0cm;mso-list:l0 level1 lfo1;tab-stops:list 36.0pt;mso-outline-level:2;" class="MsoNormal"&gt;&lt;span style="font-size:9.5pt;color:#080808;font-family:Verdana;"&gt;You cover me with theory. Thank you. But things are much simpler.&lt;/span&gt;&lt;/li&gt;
&lt;li style="background:white;margin:6pt 6pt 6pt 0cm;mso-list:l0 level1 lfo1;tab-stops:list 36.0pt;mso-outline-level:2;" class="MsoNormal"&gt;&lt;span style="font-size:9.5pt;color:#080808;font-family:Verdana;"&gt;I think that something fundamental such as a declaration of fractional numbers and their actions should not be in so surrounded way. I think that the variables with floating point (&amp;#39;double&amp;#39;) are unusable at this time, because they do not always give accurate results. And I would like experts from Microsoft, which deal with these issues, in some way to offer basic solution to this problem.&lt;/span&gt;&lt;/li&gt;
&lt;li style="background:white;margin:6pt 6pt 6pt 0cm;mso-list:l0 level1 lfo1;tab-stops:list 36.0pt;mso-outline-level:2;" class="MsoNormal"&gt;&lt;span style="font-size:9.5pt;color:#080808;font-family:Verdana;"&gt;All indicate the standard IEEE as a dogma. I am not familiar with the IEEE simply because I do not have time. But once the standard makes it impossible to use a certain type of fundamental variables and actions with them, maybe it is better to consider changes in the standard&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p class="MsoNormal"&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-size:9.5pt;color:#080808;font-family:Verdana;"&gt;&lt;/span&gt;&lt;/p&gt;
&lt;span style="font-size:9.5pt;color:#080808;font-family:Verdana;"&gt;But it gets even better! A second poster enters the discussion with the claim&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;i style="mso-bidi-font-style:normal;"&gt;&lt;span style="font-size:9.5pt;color:#080808;font-family:Verdana;"&gt;&amp;lsquo;I am absolutely astounded by two things here:&lt;br /&gt;1. That this math bug is still floating around (I remember when it was a CPU issue)&lt;br /&gt;2. That people here claim that it is not a bug in c++ in VS2003 or later&amp;rsquo;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-size:9.5pt;color:#080808;font-family:Verdana;"&gt;Someone then explains that his SUN stations give the same results, just to indicate that this problem has nothing to do with compiler errors (or CPU dependency) whatsoever.&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-size:9.5pt;color:#080808;font-family:Verdana;"&gt;But it wasn&amp;rsquo;t meant to be. What did the second poster reply?&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;i style="mso-bidi-font-style:normal;"&gt;&lt;span style="font-size:9.5pt;color:#080808;font-family:Verdana;"&gt;&amp;lsquo;Thanks for testing it for me on the SPARC system.&lt;br /&gt;Perhaps it is some bizarre feature of hardware-based floating point present in modern CPUs?&amp;nbsp; This may account for why similar code compiled on older compilers (VS6) (who don&amp;#39;t have modern FCPU knowledge) yields expected results.&lt;/span&gt;&lt;/i&gt;&lt;span style="font-size:9.5pt;color:#080808;font-family:Verdana;"&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-size:9.5pt;color:#080808;font-family:Verdana;"&gt;&amp;hellip;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;i style="mso-bidi-font-style:normal;"&gt;&lt;span style="font-size:9.5pt;color:#080808;font-family:Verdana;"&gt;It&amp;#39;s a&amp;nbsp; bit amusing when the system can&amp;#39;t even handle a result with one decimal place!&amp;rsquo;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-size:small;font-family:Times New Roman;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-size:small;font-family:Times New Roman;"&gt;Ah well.&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-size:small;font-family:Times New Roman;"&gt;If people are misguided, you can do your best to make them see. But if they want nothing to do with &amp;lsquo;reality&amp;rsquo;, then you can&amp;rsquo;t force them to understand.&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-size:small;font-family:Times New Roman;"&gt;After all, the powers of reason are futile in face of the powers of persuasion that allow someone to think every CPU, compiler and engineer / programmer / scientist in existence is wrong.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1649143" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/vandooren/archive/tags/General/default.aspx">General</category><category domain="http://msmvps.com/blogs/vandooren/archive/tags/C_2B002B00_/default.aspx">C++</category></item><item><title>Windows 7 Engineering blog</title><link>http://msmvps.com/blogs/vandooren/archive/2008/10/01/windows-7-engineering-blog.aspx</link><pubDate>Wed, 01 Oct 2008 13:47:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1649380</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=1649380</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/vandooren/commentapi.aspx?PostID=1649380</wfw:comment><comments>http://msmvps.com/blogs/vandooren/archive/2008/10/01/windows-7-engineering-blog.aspx#comments</comments><description>&lt;p&gt;I just stumbled upon the &lt;a href="http://blogs.msdn.com/e7/" title="http://blogs.msdn.com/e7/"&gt;engineering blog for Windows 7&lt;/a&gt;. Seems interesting enough to follow in order to have a better idea about what Windows 7 will be like from a technical point of view.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1649380" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/vandooren/archive/tags/General/default.aspx">General</category><category domain="http://msmvps.com/blogs/vandooren/archive/tags/Windows+Platform/default.aspx">Windows Platform</category></item><item><title>AdSync validated for the plant network</title><link>http://msmvps.com/blogs/vandooren/archive/2008/09/30/adsync-validated-for-the-plant-network.aspx</link><pubDate>Tue, 30 Sep 2008 05:09:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1649052</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=1649052</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/vandooren/commentapi.aspx?PostID=1649052</wfw:comment><comments>http://msmvps.com/blogs/vandooren/archive/2008/09/30/adsync-validated-for-the-plant-network.aspx#comments</comments><description>&lt;p&gt;Last week my AdSync application was validated for running on the plant network. &lt;/p&gt;
&lt;p&gt;The plant network exists for running the DCS application that controls everything and the kitchen sink. The application runs on a different desktop as some sort of kiosk application. This means that the users have no access to the windows desktop. &lt;/p&gt;
&lt;p&gt;The user management of this network is completely implemented within the DCS software. This means that all groups and privileges are application defined. I can create new groups and modify permissions, but all of that stays within the application. Of course the user accounts themselves exist in Active Directory, but everything that is DCS related (groups and permissions) is configured in an application database. &lt;/p&gt;
&lt;p&gt;The main reason that this is done (I think) is that the software can also run in a workgroup environment where no Active Directory exists. Imo they should deprecate this and switch to AD only as soon as possible. It&amp;#39;s not like there&amp;#39;s any reason not to run a domain, given the size of the networks for which this software is intended. &lt;/p&gt;
&lt;p&gt;Anyway, this is a bit of a problem because people get assigned to groups, based on the department they are working for, and the things they need to do. E.g. people are in the QA group, or Automation, or Technology&amp;hellip; &lt;/p&gt;
&lt;p&gt;So far so good, but unfortunately, the department someone is in also has implications for Active Directory. Automation people need to be able to reboot certain servers, including the domain controller. The technology group needs a protected folder on the fileserver for storing the reports they generate for the FDA filing of our product&amp;hellip; &lt;/p&gt;
&lt;p&gt;Before now, there was no way to handle all these things, other than manually creating groups and assigning people to it on an as-needed basis. This is tedious for one thing, but it people change groups, their other permissions would not be changed accordingly. &lt;/p&gt;
&lt;p&gt;To solve this problem is a scalable way, I&amp;#39;ve programmed an application called &amp;#39;AdSync&amp;#39;. &lt;/p&gt;
&lt;p&gt;AdSync will be executed every night after the daily backup scripts have taken an export of the DCS configuration database. Another of my applications will parse this database file and generate an XML file containing just the user account configuration, including users, groups and permissions. &lt;/p&gt;
&lt;p&gt;AdSync will first check the groups that exist in the XML file, and verify if they exist in AD. If they don&amp;#39;t exist, they will be created, but with a &amp;#39;DCS &amp;#39; prefix. This way there is a clear distinction between the existing groups, and those that are managed by my application. &lt;/p&gt;
&lt;p&gt;When that is done, the group membership of the user in the XML file is compared with the Active Directory group membership. If they are different, the necessary changes will be made to the AD group. This way, the AD membership is always a mirror of the DCS group membership. &lt;/p&gt;
&lt;p&gt;The synchronization is done only once per day, because it is based on the nightly backup of the configuration database. Exporting that database takes about an hour, and renders the system unusable for engineering work. This means we can only do it at night. &lt;/p&gt;
&lt;p&gt;Every change that is made by my application, as well as the execution timestamp and any errors that may occur are logged in a custom Windows Event Log for auditing. &lt;/p&gt;
&lt;p&gt;Since this is a production environment of pharmaceutical products, installing this on the system takes a good amount of paperwork. The change has to be approved by QA and other relevant departments; I have to do an impact assessment; I have to write an installation manual; I have to set up a validation protocol, and execute it with a witness from validation to prove that the application works as intended; &amp;hellip; &lt;/p&gt;
&lt;p&gt;So all in all, it takes quite a lot of work, but now everything is ready. Yaay me. &lt;span style="font-family:Wingdings;"&gt;J&lt;/span&gt; &lt;/p&gt;
&lt;p&gt;My application was written with VC# 2008, but built to run on the .NET 2.0 framework, which is qualified by the DCS vendor for use alongside the DCS software. The Active Directory interface was made using the System.DirectoryServices namespace. I used the &lt;a href="http://www.amazon.com/Developers-Directory-Programming-Microsoft-Development/dp/0321350170/ref=pd_bbs_sr_2?ie=UTF8&amp;amp;s=books&amp;amp;qid=1222516599&amp;amp;sr=8-2"&gt;.NET Developer&amp;#39;s Guide to Directory Services&lt;/a&gt; as a reference, because the System.DirectoryServices namespace is horrible underdocumented in MSDN. &lt;/p&gt;
&lt;p&gt;I have to admit it is nice to keep on developing software. Officially I am a system administrator, but my boss agrees with me that making custom tools like these is something of real value to the company, and something that cannot be outsourced without spending a significant amount of money.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1649052" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/vandooren/archive/tags/General/default.aspx">General</category><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/SysAdmin/default.aspx">SysAdmin</category></item><item><title>Planning the plant shutdown, part 2</title><link>http://msmvps.com/blogs/vandooren/archive/2008/09/29/planning-the-plant-shutdown-part-2.aspx</link><pubDate>Mon, 29 Sep 2008 05:25:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1649049</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=1649049</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/vandooren/commentapi.aspx?PostID=1649049</wfw:comment><comments>http://msmvps.com/blogs/vandooren/archive/2008/09/29/planning-the-plant-shutdown-part-2.aspx#comments</comments><description>&lt;p&gt;The preparation of the plant shutdown continues unabated. More and more I can understand why this needs months of intense planning. &lt;/p&gt;
&lt;p&gt;There are lots of dependencies between everything that needs doing. For example: the floors of the cold room need new coating. For this the entire room needs to be brought to near environmental temperature, but this cannot happen too suddenly or the floor will crack. &lt;/p&gt;
&lt;p&gt;Sanding away the old coating can be done while the temperature is still low. And during the first day, another team has access to the ceiling panels, but not during the final sanding or coating stages. Other work needs to wait until the coatings are dry. The other teams can then work in the cold room as the temperature is dropping again. &lt;/p&gt;
&lt;p&gt;But as the temperature is re-established, it is important that the controller loops can run uninterrupted. This means from that time onwards I cannot disrupt the DCS network anymore because that would cause problems for the people who rely for their work on the correct functioning of the DCS network. &lt;/p&gt;
&lt;p&gt;After a lot of discussion back and forth, I&amp;#39;ve gotten 1 weekend (from Friday evening to Sunday evening) where I can do with the system as I please. During the same weekend, the utilities will all be down, as well as mains electrical distribution. &lt;/p&gt;
&lt;p&gt;During the shutdown I need to do quite some things. But as luck has it, we have bought additional server racks and servers. Several servers need replacing anyway, so this is a rough sequence of how we will do things: &lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Create an additional Domain Controller, put it in the new rack, disconnect it from the network, and connect it to a new switch. That switch will be the backbone of a &amp;#39;clone&amp;#39; of the DCS domain. &lt;/li&gt;
&lt;li&gt;Rename it to the same name as the old master server which has to be replaced. &lt;/li&gt;
&lt;li&gt;Issue a development freeze so that we can restore the databases to the new server without risking the loss of work. &lt;/li&gt;
&lt;li&gt;Restore the master databases and perform the software upgrade. &lt;/li&gt;
&lt;li&gt;Add new servers in the rack to replace the other machines that needed replacing. All new servers will be connected to the cloned domain. &lt;/li&gt;
&lt;li&gt;Move the engineering workstation to the cloned domain. &lt;/li&gt;
&lt;li&gt;Wait for official signoff of the DCS network. At this moment we have the major infrastructure running on a cloned domain. &lt;/li&gt;
&lt;li&gt;As soon as we have ownership of the network we shutdown the live domain controller and all other servers that have a replacement servers running in the cloned domain. &lt;/li&gt;
&lt;li&gt;As soon as the domain controllers are down, the backbone switch of the cloned domain is connected to the live network so that the new domain controller can take over. &lt;/li&gt;
&lt;li&gt;The automation engineers can start their work as soon as that happens, because the engineering workstation is already back online. &lt;/li&gt;
&lt;li&gt;While the automation engineers do their thing, we can move the remaining servers into their new slots in the new server racks and reconfigure them. &lt;/li&gt;
&lt;li&gt;The old servers which were replaced can be taken out of the existing racks and put aside for repurposing. &lt;/li&gt;
&lt;li&gt;The additional servers which were bought for new functionality can be moved into the existing racks and configured. &lt;/li&gt;
&lt;li&gt;While all this is going on, the operator terminals can all be reconfigured 1 by 1 after their software upgrade. &lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;This is a rough first draft of how what I will do during shutdown. I&amp;#39;ll need to make a more detailed planning and see what can be done in parallel. The brunt of the work needs to be done beforehand so that the cloned domain can be prepared well before the shutdown. We only have 2 days of shutdown to do what we need, so everything needs to be done as efficiently as possible.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1649049" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/vandooren/archive/tags/General/default.aspx">General</category><category domain="http://msmvps.com/blogs/vandooren/archive/tags/Shutdown/default.aspx">Shutdown</category></item><item><title>My latest article in NTInsider</title><link>http://msmvps.com/blogs/vandooren/archive/2008/09/26/my-latest-article-in-ntinsider.aspx</link><pubDate>Fri, 26 Sep 2008 06:00:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1648864</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=1648864</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/vandooren/commentapi.aspx?PostID=1648864</wfw:comment><comments>http://msmvps.com/blogs/vandooren/archive/2008/09/26/my-latest-article-in-ntinsider.aspx#comments</comments><description>&lt;p&gt;A bit late perhaps, but my latest article on API development got published in the NTInsider (owned by &lt;a href="http://www.osronline.com" title="http://www.osronline.com"&gt;OSR Online&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;The online version can be found &lt;a href="http://www.osronline.com/article.cfm?article=521" title="http://www.osronline.com/article.cfm?article=521"&gt;here&lt;/a&gt;. It requires free registration.&lt;/p&gt;
&lt;p&gt;I know that at least 2 people have read it completely, because that is the number of mails I got to tell me I missed something.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;In the code example at the bottom, I acidentally switched the names of fooA and fooB in the declaration. Doh!&lt;/li&gt;
&lt;li&gt;That same code, compiled for a 64 bit platform, gives a &lt;a href="http://support.microsoft.com/kb/835326" title="http://support.microsoft.com/kb/835326"&gt;linker warning&lt;/a&gt;. I don&amp;#39;t know how I missed that. This code was made using VS2005, so one of two things could have happened: VC2005 didn&amp;#39;t report the warning (unlikely), or I only checked the compilation in detail, and then only checked if the function was exported without checking if there were linker warnings. It&amp;#39;s probably the latter.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;I&amp;#39;ll see if I can get these errata published. But at least now I know that people actually read my articles and use the code. Well, at least one person is using the code :) I&amp;#39;ll have to make an extra effort next time to verify that a) I didn&amp;#39;t make a stupid type, and b) There are no warnings anywhere.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1648864" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/vandooren/archive/tags/General/default.aspx">General</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/Driver+programming/default.aspx">Driver programming</category><category domain="http://msmvps.com/blogs/vandooren/archive/tags/Windows+Platform/default.aspx">Windows Platform</category></item><item><title>Configuring an application through a batch file: what domain am I in?</title><link>http://msmvps.com/blogs/vandooren/archive/2008/09/25/configuring-an-application-through-a-batch-file-what-domain-am-i-in.aspx</link><pubDate>Thu, 25 Sep 2008 06:00:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1648765</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=1648765</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/vandooren/commentapi.aspx?PostID=1648765</wfw:comment><comments>http://msmvps.com/blogs/vandooren/archive/2008/09/25/configuring-an-application-through-a-batch-file-what-domain-am-i-in.aspx#comments</comments><description>&lt;p&gt;I recently had to make an install script for one of my applications which manipulates the Active Directory. The app itself&amp;nbsp;is executed via a scheduled batch file, and it&amp;nbsp;expects the domain name as a command line parameter. I wanted the batch file to figure out on its own what the domain was of the computer on which it is executed. That turned out to be harder than I thought, but in the end I found an elegant, if rather hairy solution.&lt;/p&gt;
&lt;p&gt;FOR /F &amp;quot;tokens=1* delims=REG_SZ&amp;nbsp;&amp;quot; %%A IN (&amp;#39;REG QUERY HKLM\System\CurrentControlSet\Services\Tcpip\Parameters /v Domain&amp;#39;) DO (&lt;br /&gt;SET CURR_DOMAIN=%%B&lt;br /&gt;)&lt;/p&gt;
&lt;p&gt;This code snippet will query the registry to get the Domain the computer belongs to. Of course, the REG QUERY command returns not just the name, but a tab separated table with the key name, the key type and the key value. That table is then munged by the &amp;#39;FOR&amp;#39; loop which uses &amp;#39;REG_SZ &amp;#39; (the whitespace is a tab character) as a delimiter. The actual domain name itself is then stored in the variable &amp;#39;CURR_DOMAIN&amp;#39;&lt;/p&gt;
&lt;p&gt;It&amp;#39;s crude, but it works rather well. This trick saves me the necessity of having someone configure this by hand when the application is installed. Apart from the fact that this is error prone, it would make the installation procedure more verbose.&lt;/p&gt;
&lt;p&gt;I haven&amp;#39;t tried this on computer that is not part of a domain.&amp;nbsp;&amp;nbsp;Luckily, that is not a situation that will ever occurr on the network that I have to maintain.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1648765" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/vandooren/archive/tags/SysAdmin/default.aspx">SysAdmin</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>Smoke and mirrors in the world of finance</title><link>http://msmvps.com/blogs/vandooren/archive/2008/09/18/smoke-and-mirrors-in-the-world-of-finance.aspx</link><pubDate>Thu, 18 Sep 2008 05:20:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1648159</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=1648159</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/vandooren/commentapi.aspx?PostID=1648159</wfw:comment><comments>http://msmvps.com/blogs/vandooren/archive/2008/09/18/smoke-and-mirrors-in-the-world-of-finance.aspx#comments</comments><description>&lt;p&gt;The recent nosedive of Lehman Brothers brought back some memories of a company that I once worked for as a contractor.&lt;/p&gt;
&lt;p&gt;That company was a NASDAQ darling for a long time, but the financial situation was not great when the stock&amp;nbsp;market for high tech stuff collapsed.&amp;nbsp;Our site had to work hard to save enough money to be spared the axe.&amp;nbsp;Unfortunately, in the year leading up to the stock collapse, a lot of equipment had been ordered for the purpose of increasing our ouput with 100%. They had to do this, because a lot of equipment had lead times up to a year.&lt;/p&gt;
&lt;p&gt;Thus it was that while everyone started to wonder about the reality of getting virtually no orders at all, new equipment was pouring in that we already didn&amp;#39;t need anymore. And in the semiconductor high speed optics world, there is no such thing as cheap equipment. The cheapest thing was probably a power meter at 30 KEuro. The most expensive thing was a 500KEuro 10 GGHz bit error rate tester.&lt;/p&gt;
&lt;p&gt;I should note that the CFO of the site was very good at what he did, which allowed the site to exist for as long as it did. In order to make the papers look better, he invoked a special rule over the new equipment: noone could use it.&lt;/p&gt;
&lt;p&gt;Apparently, if you don&amp;#39;t start using equipment, it is not subject to the write off procedures, and it hasn&amp;#39;t actually cost any money in the books. The hardware still represents the original sum of money and as a result, doesn&amp;#39;t show up as a cost. Financially, it was just very bulky money. Note that this is completely legal.&lt;/p&gt;
&lt;p&gt;Unfortunately it is also as realistic as&amp;nbsp;the tooth fairy, because in reality, the money is already gone. So you get situations like I had, where you have a power meter shaped hole in a measurement system and a brand new power meter waiting to be used. I wan&amp;#39;t allowed to put 1 and 1 together because &lt;em&gt;that would cost money&lt;/em&gt;. I argued that the money was already gone, and we might as well do something useful with the equipment. And while the director agree with me, he also said that it didn&amp;#39;t work that way on paper.&lt;/p&gt;
&lt;p&gt;It was then that I realized the&amp;nbsp;world of finances is all smoke and mirrors, and it only works as long as the people believe the dream. As soon as everybody discovers that the gold is just gilt, you get what happened to Lehman Brothers. Financial institutions are like hot air balloons. If the hot air gets out, all that is left is the skin and the dead weight, and it will plummet to its rocky end.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1648159" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/vandooren/archive/tags/General/default.aspx">General</category></item><item><title>References in C++ are not necessarily safe</title><link>http://msmvps.com/blogs/vandooren/archive/2008/09/17/references-in-c-are-not-safe.aspx</link><pubDate>Wed, 17 Sep 2008 12:46:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1647968</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=1647968</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/vandooren/commentapi.aspx?PostID=1647968</wfw:comment><comments>http://msmvps.com/blogs/vandooren/archive/2008/09/17/references-in-c-are-not-safe.aspx#comments</comments><description>&lt;p&gt;People who are new to C++ sometimes have the mistaken idea that using references instead of pointers makes your code safe. People who have been programming a bit longer know this is anything but the case. References are just semantic sugar coated pointers. &lt;/p&gt;
&lt;p&gt;I&amp;#39;ll explain in more detail with a couple of examples. They use this pretty simple class A. &lt;/p&gt;
&lt;p&gt;&lt;span style="font-size:10pt;font-family:Courier New;"&gt;&lt;span style="color:#0000ff;"&gt;struct&lt;/span&gt; A&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:10pt;font-family:Courier New;"&gt;{&lt;br /&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:Courier New;"&gt;&lt;span style="color:#0000ff;"&gt;int&lt;/span&gt; &amp;amp;I;&lt;br /&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:Courier New;"&gt;A(&lt;span style="color:#0000ff;"&gt;int&lt;/span&gt; &amp;amp;i) : I(i)&lt;br /&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:Courier New;"&gt;{&lt;br /&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:Courier New;"&gt;} &lt;br /&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:Courier New;"&gt;&lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; print(&lt;span style="color:#0000ff;"&gt;void&lt;/span&gt;)&lt;br /&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:Courier New;"&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:Courier New;"&gt;cout &amp;lt;&amp;lt; I &amp;lt;&amp;lt; endl;&lt;br /&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:Courier New;"&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:10pt;font-family:Courier New;"&gt;};&lt;/span&gt; &lt;/p&gt;
&lt;p&gt;When A is instantiated, the constructor takes a reference to an integer and uses it to initialize an internal integer reference. The print method simply prints the value of that integer. &lt;/p&gt;
&lt;h2&gt;Case 1 &lt;/h2&gt;
&lt;p&gt;&lt;span style="font-size:10pt;font-family:Courier New;"&gt;&lt;span style="color:#0000ff;"&gt;int&lt;/span&gt; * i= &lt;span style="color:#0000ff;"&gt;new&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;int&lt;/span&gt;(32);&lt;br /&gt;A a(*i);&lt;br /&gt;*i = 43;&lt;br /&gt;a.print();&lt;br /&gt;&lt;span style="color:#0000ff;"&gt;delete&lt;/span&gt; i;&lt;br /&gt;a.print();&lt;/span&gt; &lt;/p&gt;
&lt;p&gt;I create a new integer value on the heap and I initialize a pointer with its address. I then create a new instance of A, and pass the newly created integer by reference. a initializes its own internal reference with the address of that integer. And indeed, if I assign a value to that integer and then print a&amp;#39;s internal reference, the values match. &lt;/p&gt;
&lt;p&gt;But what happens if that integer is deleted from the heap? It depends. The behavior is undefined. The next read from a.I could result in a bad value or an application crash. But in any case, it is not safe. &lt;/p&gt;
&lt;p&gt;You might argue that I am purposely using pointers to cause problems, but in a large application, you won&amp;#39;t know how and where your objects will be created. This could happen. &lt;/p&gt;
&lt;h2&gt;Case 2 &lt;/h2&gt;
&lt;p&gt;A second case is much more innocuous. It uses no visible pointers. &lt;/p&gt;
&lt;p&gt;&lt;span style="font-size:10pt;font-family:Courier New;"&gt;vector&amp;lt;&lt;span style="color:#0000ff;"&gt;int&lt;/span&gt;&amp;gt; v;&lt;br /&gt;v.push_back(42);&lt;br /&gt;A b(v[0]);&lt;br /&gt;v[0] = 43;&lt;br /&gt;b.print();&lt;br /&gt;v.pop_back(); &lt;span style="color:#008000;"&gt;//remove that element from the container&lt;br /&gt;&lt;/span&gt;b.print();&lt;br /&gt;v.push_back(2); &lt;span style="color:#008000;"&gt;//put something else in the same location&lt;br /&gt;&lt;/span&gt;b.print();&lt;/span&gt; &lt;/p&gt;
&lt;p&gt;Instead of dynamically allocation memory myself, I put an integer in a vector and then feed a reference to that element into an instance of A. This new instance (b) is now using the location of an element in a vector as an internal reference. &lt;/p&gt;
&lt;p&gt;The thing with vectors is that they normally have more capacity than elements. This is because you don&amp;#39;t want the vector to allocate more space for every element that gets inserted. Likewise, you are not going to do a deallocation with each element that gets removed. &lt;/p&gt;
&lt;p&gt;Because of this, when that element is removed, the physical space is still there. A read from that location is not immediately going to trigger a crash. Instead, the program will keep on running, but with bad data instead. Or maybe not, if that element was at the threshold of triggering a deallocation. With bugs like this, you never know what will happen. &lt;/p&gt;
&lt;h2&gt;Case 3 &lt;/h2&gt;
&lt;p&gt;There is an even more interesting option. I am not going to write a repro case for it, but consider the following: I create multiple instances of A, giving them each a reference to an integer that is located on the stack, and I pass those instances of A as pointers to newly created threads, to be used there. &lt;/p&gt;
&lt;p&gt;Meanwhile, the stack on which the integers are located is unwound. What happens next? &lt;/p&gt;
&lt;p&gt;Again, it depends. Probably the stack gets stomped. Or perhaps only the data will be corrupted. Again, what happens is unknown. And I don&amp;#39;t say that this design pattern is a good one. It isn&amp;#39;t. But given certain constraints, it might just be an approach for solving a specific problem (though perhaps not the best one). &lt;/p&gt;
&lt;h2&gt;Conclusion &lt;/h2&gt;
&lt;p&gt;By now, anyone should be convinced that using references do not protect your application against design mistakes. &lt;/p&gt;
&lt;p&gt;The only time your references are really safe is if:&lt;br /&gt;a) your application is single threaded, and there is no asynchronous code executed anywhere, and&lt;br /&gt;b) your classes don&amp;#39;t store references anywhere.&lt;/p&gt;
&lt;p&gt;Outside of those constraints, references don&amp;#39;t guarantee anything more than pointers would. The only guarantee you have with references is that at some point in time, there was an object of the correct type at the specified location, and it was not NULL. Probably.&lt;/p&gt;
&lt;p&gt;If someone is actively trying to subvert your code, you can&amp;#39;t even be sure of that. But since there is nothing you can do about that, you might as well use references because they make your life easier, and are better than raw pointers when it comes to preventing honest mistakes.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1647968" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/vandooren/archive/tags/C_2B002B00_/default.aspx">C++</category></item><item><title>Please use a 'real' email address</title><link>http://msmvps.com/blogs/vandooren/archive/2008/09/16/please-use-a-real-email-address.aspx</link><pubDate>Tue, 16 Sep 2008 05:57:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1647876</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=1647876</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/vandooren/commentapi.aspx?PostID=1647876</wfw:comment><comments>http://msmvps.com/blogs/vandooren/archive/2008/09/16/please-use-a-real-email-address.aspx#comments</comments><description>&lt;p&gt;Yesterday I tried to register on the &lt;a href="http://www.opcfoundation.org" title="http://www.opcfoundation.org"&gt;opcfoundation&lt;/a&gt; forum so that I could find out why the opc SDK comes without documentation or code samples.&lt;/p&gt;
&lt;p&gt;I know that corporate members (i.e. the ones who pay $$$$) can download code samples and specifications, but a publicly available SDK is not going to do anyone much good&amp;nbsp;without access to at least the documentation.&lt;/p&gt;
&lt;p&gt;Anyway, the message board required me to specify my email address so I used my gmail address. I also made a mistake while typing in the captcha. After looking again after the first 2 failures, I noticed that it had to be typed in from right to left, but by then my email adress had been banned.&lt;/p&gt;
&lt;p&gt;I sent a mail to the forum admin, asking for the ban to be undone. This is the complete message I got back.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;All gmail accounts are banned.&amp;nbsp; Please use a &amp;quot;real&amp;quot; email address.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Apart from the total lack of style which I would not expect from an admin of a forum for professionals (notice the lack of addressing), it amazes me that people still think that webmail addresses are unclean (notice the sarcasm). Most people I know on most forums (incl the forum for which I am a moderator) use webmail. And this specific forum was very low traffic so it&amp;#39;s not like they are battling spammers by the hundreds.&lt;/p&gt;
&lt;p&gt;My gut tells me that the problem is that webmail addresses are primarily used by non-paying members. Foundations like these are interested in big bucks. If you can&amp;#39;t even drop 1000$ for the membership, then you are obviously to poor to count for anything, and you can subsequently be dismissed without much thought.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1647876" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/vandooren/archive/tags/General/default.aspx">General</category></item><item><title>How DLL exports really work</title><link>http://msmvps.com/blogs/vandooren/archive/2008/09/12/how-dll-exports-really-work.aspx</link><pubDate>Fri, 12 Sep 2008 10:42:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1647589</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=1647589</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/vandooren/commentapi.aspx?PostID=1647589</wfw:comment><comments>http://msmvps.com/blogs/vandooren/archive/2008/09/12/how-dll-exports-really-work.aspx#comments</comments><description>&lt;p&gt;I found this list of article on &lt;a target="_blank" href="http://blogs.msdn.com/oldnewthing" title="http://blogs.msdn.com/oldnewthing"&gt;Raymond&amp;#39;s blog&lt;/a&gt;. Raymond&amp;#39;s blog is one of the more interesting for programmers who use native APIs because he often touchs on things that are not documented, but interesting to know if you care about how things really work under the hood.&lt;/p&gt;
&lt;p&gt;These links all point to information that goes into DLL importing and exporting, and how it is implemented under the hood. Very interesting stuff.&lt;/p&gt;
&lt;li&gt;&lt;a href="http://blogs.msdn.com/oldnewthing/archive/2006/07/14/665669.aspx"&gt;How were DLL functions exported in 16-bit Windows?&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="http://blogs.msdn.com/oldnewthing/archive/2006/07/17/668284.aspx"&gt;How were DLL functions imported in 16-bit Windows?&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="http://blogs.msdn.com/oldnewthing/archive/2006/07/18/669668.aspx"&gt;How are DLL functions exported in 32-bit Windows?&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="http://blogs.msdn.com/oldnewthing/archive/2006/07/19/671238.aspx"&gt;Exported functions that are really forwarders&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="http://blogs.msdn.com/oldnewthing/archive/2006/07/20/672695.aspx"&gt;Rethinking the way DLL exports are resolved for 32-bit Windows&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="http://blogs.msdn.com/oldnewthing/archive/2006/07/21/673830.aspx"&gt;Calling an imported function, the naive way&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="http://blogs.msdn.com/oldnewthing/archive/2006/07/24/676669.aspx"&gt;How a less naive compiler calls an imported function&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="http://blogs.msdn.com/oldnewthing/archive/2006/07/25/677878.aspx"&gt;Issues related to forcing a stub to be created for an imported function&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="http://blogs.msdn.com/oldnewthing/archive/2006/07/26/679044.aspx"&gt;What happens when you get dllimport wrong?&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="http://blogs.msdn.com/oldnewthing/archive/2006/07/27/679634.aspx"&gt;Names in the import library are decorated for a reason&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="http://blogs.msdn.com/oldnewthing/archive/2004/01/12/57833.aspx"&gt;The dangers of dllexport&lt;/a&gt;&lt;/li&gt;
&lt;p&gt;Another thing which may be useful if you haven&amp;#39;t read it yet are Michael Grier&amp;#39;s articles on the NT DLL loader &lt;a href="http://blogs.msdn.com/mgrier/archive/2005/06/28/433707.aspx" title="over here"&gt;&lt;span style="color:#000000;"&gt;over here&lt;/span&gt;&lt;/a&gt;. I&amp;#39;ve &lt;a target="_blank" href="http://msmvps.com/blogs/vandooren/archive/2006/10/08/What-every-programmer-should-know-about-DLL-loading.aspx" title="http://msmvps.com/blogs/vandooren/archive/2006/10/08/What-every-programmer-should-know-about-DLL-loading.aspx"&gt;blogged about&lt;/a&gt; those articles before. Michael is one of the project leaders who maintained the NT DLL loader for some time.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1647589" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/vandooren/archive/tags/C_2B002B00_/default.aspx">C++</category><category domain="http://msmvps.com/blogs/vandooren/archive/tags/Windows+Platform/default.aspx">Windows Platform</category></item><item><title>Stuck on stupid</title><link>http://msmvps.com/blogs/vandooren/archive/2008/09/10/stuck-on-stupid.aspx</link><pubDate>Wed, 10 Sep 2008 20:31:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1647171</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=1647171</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/vandooren/commentapi.aspx?PostID=1647171</wfw:comment><comments>http://msmvps.com/blogs/vandooren/archive/2008/09/10/stuck-on-stupid.aspx#comments</comments><description>&lt;p&gt;It happens to every programmer. It doesn&amp;#39;t happen often, but it does happen to everyone. You are looking at a piece of code or some debugging output, scratching your head and thinking &amp;#39;This is impossible&amp;#39;. It&amp;#39;s probably only 10 or 20 lines of code or text, and you&amp;#39;ve looked carefully at every line at least a dozen times over the last hour. &lt;/p&gt;
&lt;p&gt;Every line makes sense and seems to mean exactly what you think it means, every word is in place, every semicolon is accounted for, and yet the sum of those lines is something completely unlike what you think it should be. &lt;/p&gt;
&lt;p&gt;What makes matters even worse is that you just know that you are missing something obvious; something that anyone else would see after looking at the issue for less than 5 seconds. Maybe someone is even explaining the issue to you and you still don&amp;#39;t get it. &lt;/p&gt;
&lt;p&gt;Well, I had such a moment just this weekend. &lt;/p&gt;
&lt;p&gt;I was working on some C++ code that involved friend functions and streams. I&amp;#39;ve never done much with streams in C++, and never done anything with friends. Basically, friend declarations allow e.g. class A to specify that class B is allowed to access its private variables. Hence the joke: in C++, your friends can see your privates. I&amp;#39;ve never used it in a design, because if other classes need access to private data, the design is probably wrong. &lt;/p&gt;
&lt;p&gt;There are some exceptions, where it can be extremely useful. One of these cases is if you have to create a serialization function that can serialize and deserialize an object. That function would need access to the private data to efficiently reconstruct the object, but you don&amp;#39;t want any other functions or classes to have the same privilege. &lt;/p&gt;
&lt;p&gt;In my case, I had a template class that I wanted to reconstruct from a generic iostream. I implemented a global function that performed the reconstruction, but despite my friend declaration that gave istream access, the compiler didn&amp;#39;t agree. This is what my code boiled down to: &lt;/p&gt;
&lt;p&gt;&lt;span style="font-size:10pt;font-family:Courier New;"&gt;&lt;span style="color:#0000ff;"&gt;class&lt;/span&gt; A&lt;br /&gt;{&lt;br /&gt;&lt;span style="color:#0000ff;"&gt;friend&lt;/span&gt; istream;&lt;br /&gt;&lt;span style="color:#0000ff;"&gt;int&lt;/span&gt; i;&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;istream&amp;amp; &lt;span style="color:#0000ff;"&gt;operator&lt;/span&gt; &amp;gt;&amp;gt;(istream&amp;amp; is, A &amp;amp;a)&lt;br /&gt;{&lt;br /&gt;is &amp;gt;&amp;gt; a.i; &lt;span style="color:#008000;"&gt;//error C2248: &amp;#39;A::i&amp;#39; :&lt;br /&gt;&lt;/span&gt;&lt;span style="color:#008000;"&gt;//cannot access private member declared in class &amp;#39;A&amp;#39;&lt;br /&gt;&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; is;&lt;br /&gt;} &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I looked at it for a long time, read the &amp;#39;friend&amp;#39; documentation in MSDN, consulted my copy of &amp;#39;The C++ programming language, 3ed&amp;#39;, asked a fellow MVP to explain it to me, and I still didn&amp;#39;t get it. I reasoned: &amp;#39;I just gave istream access to A::I, so WTF is the problem&amp;#39;. &lt;/p&gt;
&lt;p&gt;In this case, the solution was really a &amp;#39;duh&amp;#39; moment. Yes, istreams have access to A. But &amp;ndash; and this is the whole issue &amp;ndash; it is not the istream doing the accessing. The istream accesses an integer by reference; an integer that was retrieved by the global operator &amp;gt;&amp;gt; function. My code was functionally equivalent to: &lt;/p&gt;
&lt;p&gt;&lt;span style="font-size:10pt;font-family:Courier New;"&gt;istream&amp;amp; &lt;span style="color:#0000ff;"&gt;operator&lt;/span&gt; &amp;gt;&amp;gt;(istream&amp;amp; is, A &amp;amp;a)&lt;br /&gt;{&lt;br /&gt;&lt;span style="color:#0000ff;"&gt;int&lt;/span&gt; &amp;amp;temp = a.i; &lt;span style="color:#008000;"&gt;//error C2248 &lt;br /&gt;&lt;/span&gt;is &amp;gt;&amp;gt; temp;&lt;br /&gt;&lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; is;&lt;br /&gt;}&lt;/span&gt; &lt;/p&gt;
&lt;p&gt;And that is pretty obviously wrong. By writing is &amp;gt;&amp;gt; a.i, I lulled myself into believing it was &amp;#39;is&amp;#39; who did the access, while in reality it was someone else. &lt;/p&gt;
&lt;p&gt;As I said already: this was one of those &amp;#39;Aaargh&amp;#39; moments where I just seemed to be stuck on &amp;#39;stupid&amp;#39;. Ah well. Live, learn, and have more coffee next time &lt;span style="font-family:Wingdings;"&gt;J&lt;/span&gt; Glad this doesn&amp;#39;t happen every day, week, or month.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1647171" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/vandooren/archive/tags/General/default.aspx">General</category><category domain="http://msmvps.com/blogs/vandooren/archive/tags/C_2B002B00_/default.aspx">C++</category></item><item><title>The power of a workstation and the convenience of a laptop</title><link>http://msmvps.com/blogs/vandooren/archive/2008/09/09/the-power-of-a-workstation-and-the-convenience-of-a-laptop.aspx</link><pubDate>Tue, 09 Sep 2008 10:24:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1647223</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=1647223</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/vandooren/commentapi.aspx?PostID=1647223</wfw:comment><comments>http://msmvps.com/blogs/vandooren/archive/2008/09/09/the-power-of-a-workstation-and-the-convenience-of-a-laptop.aspx#comments</comments><description>&lt;p&gt;over a year ago, I built myself a new workstation, with a Core2Duo, SATAII hard disks in RAID1 configuration, 4GB memory, MSI nv7950 video card, ... The whole machine was everything a machine could want to be at the time.&lt;/p&gt;
&lt;p&gt;Unfortunately, I learned that having a powerful workstation is not all it&amp;#39;s cracked up to be. The big problem is that you have to put it somewhere. It&amp;#39;s big, it needs power, and it needs to be someplace where the kids will not try to feed it sandwiches or cereals&amp;nbsp;through the DVD. On a table in the living room didn&amp;#39;t get approval from She-who-must-be-obeyed, so I was forced to put it in our bedroom.&lt;/p&gt;
&lt;p&gt;Since that was not a good solution either (for practical reasons), I moved it to the basement where it sat unused for some time. But then I pulled a network cable from my wifi router to the basement, and life was good again. I installed that machine with Vista64, installed VMware and Visual Studio, Installed Office and all the other stuff I need, and then I enabled remote access.&lt;/p&gt;
&lt;p&gt;Now I can sit anywahere in the house with a laptop and connect via remote desktop to my workstation. I can do all my nerdy stuff while sitting in the living room with my wife while she is watching something on tv, and if I need to stop I simply shutdown or close the laptop. When I want to continue I simply connect to the remote session and proceed where I had left my work.&lt;/p&gt;
&lt;p&gt;And the good thing is that I can do all that work on a 6 year old laptop which is more than fast enough to run XP and RDP. And if I use my wife&amp;#39;s laptop from work or mine, I can still have all my tools at my finger tips. Gone are the days of having to move stuff around and installing tools on multiple computers. Now I can put all that time into sufficiently geeky programming activities.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1647223" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/vandooren/archive/tags/General/default.aspx">General</category></item><item><title>Planning for the plant shutdown</title><link>http://msmvps.com/blogs/vandooren/archive/2008/09/08/planning-for-the-plant-shutdown.aspx</link><pubDate>Mon, 08 Sep 2008 10:15:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1647121</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=1647121</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/vandooren/commentapi.aspx?PostID=1647121</wfw:comment><comments>http://msmvps.com/blogs/vandooren/archive/2008/09/08/planning-for-the-plant-shutdown.aspx#comments</comments><description>&lt;p&gt;Come November or december, there will be a 3 week shutdown of our plant to perform maintenance and repairs. A lot of systems cannot be shutdown normally, or taken apart. A lot of the medical systems are never opened, or even turned off. This means that there are a lot of things that cannot be done while the plant is operational.&lt;/p&gt;
&lt;p&gt;Since I am the system admin in charge of the production network and servers, I am part of the group that plans this event.&lt;/p&gt;
&lt;p&gt;My part is both easy and hard at the same time. Easy because I only have to replace some servers and do a software upgrade, and I need no&amp;nbsp;other departments&amp;nbsp;for either action. But hard because everyone needs a live system to do &lt;em&gt;their&lt;/em&gt; jobs.&lt;/p&gt;
&lt;p&gt;For example, if the people from maintenance are working on the cooling system, they need the plant software in order to open and close valves. And once the cooling system is up and running, the plant software should be up and running because they need working controllers. And system cleaning has to be done before the system is live again, but the clean steam utilities need working batch execution software...&lt;/p&gt;
&lt;p&gt;But there are much more dependencies, with some of them being difficult to manage. for example, for some of the maintenance, the ceilings in manufacturing have to be opened up. This also destroys the cleanroom aspect of that area, so it needs to be cleaned. Unfortunately, the cleaning cannot begin before the second week of shutdown, but other activities that have to wait for the end of the second week also need ceiling access. But another activity that has to start in second week for another reason needs a clean environment...&lt;/p&gt;
&lt;p&gt;So all in all a shutdown is a very complicated issue.&lt;/p&gt;
&lt;p&gt;For now it looks like I am going to do most of the work in the&amp;nbsp;first weekend during which everything is shut down completely, including the mains power.&amp;nbsp;I can get power to the server room via the emergency generator, and the second I get the go ahead signal on friday evening, I can start my work. 2 full&amp;nbsp;days &lt;em&gt;should&lt;/em&gt; be enough to cover the critical work, though it will be a very busy weekend.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1647121" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/vandooren/archive/tags/General/default.aspx">General</category></item><item><title>Regex bug in VC2008 SP1 TR1 library</title><link>http://msmvps.com/blogs/vandooren/archive/2008/09/04/small-regex-bug-in-vc2008-sp1-tr1-library.aspx</link><pubDate>Thu, 04 Sep 2008 09:46:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1646721</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=1646721</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/vandooren/commentapi.aspx?PostID=1646721</wfw:comment><comments>http://msmvps.com/blogs/vandooren/archive/2008/09/04/small-regex-bug-in-vc2008-sp1-tr1-library.aspx#comments</comments><description>&lt;p&gt;Yesterday I tracked down a bug in the TR1 regex library that is shipped with VS2008 SP1.&lt;/p&gt;
&lt;p&gt;If you use regexes, then the regex a| will cause an exception to be thrown because of supposedly illegal syntax. For example you could use (a|) in a regular expression to indicate that a string contains at a certain point either a or nothing.&lt;/p&gt;
&lt;p&gt;There are better ways to do this of course, and I&amp;#39;ve changed the problematic regex already, but it should have worked.&lt;/p&gt;
&lt;p&gt;I checked the .NET regexes, and they accept this syntax. .NET regex follows the &lt;a href="http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf" title="http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf"&gt;ECMAScript syntax&lt;/a&gt;, which specifies pretty unambiguously in section 15.10.1 (Thanks Igor for helping me identify the correct section) that the alternative operator should accept empty sections.&lt;br /&gt;The &lt;a href="http://www.open-std.org/JTC1/sc22/wg21/docs/papers/2003/n1429.htm#syntax_discussion" title="http://www.open-std.org/JTC1/sc22/wg21/docs/papers/2003/n1429.htm#syntax_discussion"&gt;TR1 proposal&lt;/a&gt; also specifies that ECMAScript is used, so it should accept this syntax.&lt;/p&gt;
&lt;p&gt;If you use TR1 regexes, take a minute of your time to vote for &lt;a href="https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=365994" title="https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=365994"&gt;this bugreport on connect&lt;/a&gt; so that they fix it in the next SP / release.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1646721" width="1" height="1"&gt;</description><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>0</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></item><item><title>Fun with templates: parsing command line arguments</title><link>http://msmvps.com/blogs/vandooren/archive/2008/08/14/fun-with-templates-parsing-command-line-arguments.aspx</link><pubDate>Thu, 14 Aug 2008 10:17:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1644623</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=1644623</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/vandooren/commentapi.aspx?PostID=1644623</wfw:comment><comments>http://msmvps.com/blogs/vandooren/archive/2008/08/14/fun-with-templates-parsing-command-line-arguments.aspx#comments</comments><description>&lt;p style="margin:0cm 0cm 12pt;" class="MsoNormal"&gt;&lt;span style="font-size:small;font-family:Times New Roman;"&gt;One of the things that everyone has to do sooner or later is parsing command line arguments into program variables. Even the most trivial command line application needs some input variables to tell it what to do.&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0cm 0cm 12pt;" class="MsoNormal"&gt;&lt;span style="font-size:small;font-family:Times New Roman;"&gt;One of the things in which C and C++ are lacking is a unified approach to command line arguments. This allows anyone to do what he wants, but unfortunately it also forces everybody to figure it out for himself.&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0cm 0cm 12pt;" class="MsoNormal"&gt;&lt;span style="font-size:small;font-family:Times New Roman;"&gt;I have done this several times, and tried several approaches. My last projects all needed moderately complex command line configurations, so I finally solved this problem in a reusable way. Originally I used the boost template library for this (&lt;/span&gt;&lt;a href="http://www.boost.org/"&gt;&lt;span style="font-size:small;font-family:Times New Roman;"&gt;www.boost.org&lt;/span&gt;&lt;/a&gt;&lt;span style="font-size:small;font-family:Times New Roman;"&gt;). Specifically, I used regular expressions. But now that VS2008 SP1 is out, I can use the TR1 library to do this for me.&lt;/span&gt;&lt;/p&gt;
&lt;h2 style="margin:12pt 0cm 3pt;"&gt;&lt;em&gt;&lt;span style="font-size:large;font-family:Arial;"&gt;What does a command line argument look like&lt;/span&gt;&lt;/em&gt;&lt;/h2&gt;
&lt;p style="margin:0cm 0cm 12pt;" class="MsoNormal"&gt;&lt;span style="font-size:small;font-family:Times New Roman;"&gt;The exact syntax doesn&amp;rsquo;t matter because we are using regular expressions. What is important is that the identifier and the value are recognized by the shell to belong together.&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0cm 0cm 12pt;" class="MsoNormal"&gt;&lt;span style="font-size:small;font-family:Times New Roman;"&gt;The only way to do this is of course to make sure that they are in the same string. For example, such command line arguments can look like this:&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0cm 0cm 12pt;" class="MsoNormal"&gt;&lt;span style="font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span style="font-size:small;"&gt;-val:12.5&lt;br /&gt;/text=blabla&lt;br /&gt;-file=&amp;rdquo;C:\Documents and Settings\me\desktop\article.doc&amp;rdquo;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0cm 0cm 12pt;" class="MsoNormal"&gt;&lt;span style="font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:small;font-family:Times New Roman;"&gt;It really doesn&amp;rsquo;t matter. As long as all the information is recognized as 1 argument, it&amp;rsquo;s fine. If the value contains spaces, you need to use quotes so that the shell will not treat&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0cm 0cm 12pt;" class="MsoNormal"&gt;&lt;span style="font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span style="font-size:small;"&gt;-file=&amp;rdquo;C:\Documents and Settings\me\desktop\article.doc&amp;rdquo;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0cm 0cm 12pt;" class="MsoNormal"&gt;&lt;span style="font-size:small;font-family:Times New Roman;"&gt;as 3 arguments.&lt;/span&gt;&lt;/p&gt;
&lt;h2 style="margin:12pt 0cm 3pt;"&gt;&lt;em&gt;&lt;span style="font-size:large;font-family:Arial;"&gt;Requirements&lt;/span&gt;&lt;/em&gt;&lt;/h2&gt;
&lt;p style="margin:0cm 0cm 12pt;" class="MsoNormal"&gt;&lt;span style="font-size:small;font-family:Times New Roman;"&gt;The requirements for my solution are as follows:&lt;/span&gt;&lt;/p&gt;
&lt;ul style="margin-top:0cm;"&gt;
&lt;li style="margin:0cm 0cm 12pt;mso-list:l0 level1 lfo1;tab-stops:list 36.0pt;" class="MsoNormal"&gt;&lt;span style="font-size:small;font-family:Times New Roman;"&gt;1 function which can take a command parameter and a regular expression, and which can parse any given type (bool, int, string, &amp;hellip;) from the parameter, according to the specified regex.&lt;/span&gt;&lt;/li&gt;
&lt;li style="margin:0cm 0cm 12pt;mso-list:l0 level1 lfo1;tab-stops:list 36.0pt;" class="MsoNormal"&gt;&lt;span style="font-size:small;font-family:Times New Roman;"&gt;The function should be able to handle string and wstring parameters.&lt;/span&gt;&lt;/li&gt;
&lt;li style="margin:0cm 0cm 12pt;mso-list:l0 level1 lfo1;tab-stops:list 36.0pt;" class="MsoNormal"&gt;&lt;span style="font-size:small;font-family:Times New Roman;"&gt;It should be able to put values into regular data types, as well as into TriStateValue template types (see here &lt;/span&gt;&lt;a href="http://msmvps.com/blogs/vandooren/archive/2007/10/11/fun-with-templates-implementing-a-tri-state-value.aspx"&gt;&lt;span style="font-size:small;font-family:Times New Roman;"&gt;http://msmvps.com/blogs/vandooren/archive/2007/10/11/fun-with-templates-implementing-a-tri-state-value.aspx&lt;/span&gt;&lt;/a&gt;&lt;span style="font-size:small;font-family:Times New Roman;"&gt; for more info).&lt;/span&gt;&lt;/li&gt;
&lt;li style="margin:0cm 0cm 12pt;mso-list:l0 level1 lfo1;tab-stops:list 36.0pt;" class="MsoNormal"&gt;&lt;span style="font-size:small;font-family:Times New Roman;"&gt;The function should return a bool to notify the user if the argument was parsed.&lt;/span&gt;&lt;/li&gt;
&lt;li style="margin:0cm 0cm 12pt;mso-list:l0 level1 lfo1;tab-stops:list 36.0pt;" class="MsoNormal"&gt;&lt;span style="font-size:small;font-family:Times New Roman;"&gt;The part of the regex that identifies the actual value has to be captured. I.e. it has to be enclosed between ( ) symbols.&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 style="margin:12pt 0cm 3pt;"&gt;&lt;em&gt;&lt;span style="font-size:large;font-family:Arial;"&gt;First attempt&lt;/span&gt;&lt;/em&gt;&lt;/h2&gt;
&lt;p style="margin:0cm 0cm 12pt;" class="MsoNormal"&gt;&lt;span style="font-size:small;font-family:Times New Roman;"&gt;The first version of such a function was ready pretty rapidly.&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0cm 0cm 12pt;" 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;template&lt;/span&gt; &amp;lt;&lt;span style="color:blue;"&gt;typename&lt;/span&gt; T&amp;gt;&lt;br /&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;bool&lt;/span&gt; ParseArg(&lt;br /&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;std::tr1::regex &lt;span style="color:blue;"&gt;const&lt;/span&gt;&amp;amp; pattern,&lt;br /&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;std::string &lt;span style="color:blue;"&gt;const&lt;/span&gt;&amp;amp; arg,&lt;br /&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;T&amp;amp; value)&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;std::tr1::smatch matches;&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;if&lt;/span&gt;( !std::tr1::regex_search(arg, matches, pattern))&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;return&lt;/span&gt; &lt;span style="color:blue;"&gt;false&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;std::istringstream iss((string) matches[1]);&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;return&lt;/span&gt; ! (iss &amp;gt;&amp;gt; std::dec &amp;gt;&amp;gt; value).fail();&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:0cm 0cm 12pt;" class="MsoNormal"&gt;&lt;span style="font-size:small;font-family:Times New Roman;"&gt;The function takes a regex and an argument. The value type is a template type which allows the user to use it for any type. The type itself can be inferred at compile time. I.e. the user does not have to explicitly specify the template type using brackets.&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0cm 0cm 12pt;" class="MsoNormal"&gt;&lt;span style="font-size:small;font-family:Times New Roman;"&gt;A string stream is used for getting the value out of the stream. This is very handy because this way, the text to value conversion has no dependency on the value type. By using the string stream, the function remains generic.&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0cm 0cm 12pt;" class="MsoNormal"&gt;&lt;span style="font-size:small;font-family:Times New Roman;"&gt;This function has an overload that uses a TriStateVal type for the resulting value.&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0cm 0cm 12pt;" class="MsoNormal"&gt;&lt;span style="font-size:10pt;color:blue;font-family:&amp;#39;Courier New&amp;#39;;mso-no-proof:yes;"&gt;template&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;mso-no-proof:yes;"&gt; &amp;lt;&lt;span style="color:blue;"&gt;typename&lt;/span&gt; T&amp;gt;&lt;br /&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;bool&lt;/span&gt; ParseArg(&lt;br /&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;std::tr1::regex &lt;span style="color:blue;"&gt;const&lt;/span&gt;&amp;amp; pattern,&lt;br /&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;std::string &lt;span style="color:blue;"&gt;const&lt;/span&gt;&amp;amp; arg,&lt;br /&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;TriStateVal&amp;lt;T&amp;gt;&amp;amp; value)&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;std::tr1::smatch matches;&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;if&lt;/span&gt;( !std::tr1::regex_search(arg, matches, pattern))&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;return&lt;/span&gt; &lt;span style="color:blue;"&gt;false&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;std::istringstream iss((string) matches[1]);&lt;br /&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;T val;&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;if&lt;/span&gt;((iss &amp;gt;&amp;gt; std::dec &amp;gt;&amp;gt; val).fail())&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;return&lt;/span&gt; &lt;span style="color:blue;"&gt;false&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;value = val;&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;return&lt;/span&gt; &lt;span style="color:blue;"&gt;true&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:0cm 0cm 12pt;" class="MsoNormal"&gt;&lt;span style="font-size:small;font-family:Times New Roman;"&gt;The TriStateVal type allows the user of that value to know whether it had been assigned or not. Unfortunately, there is no support yet for streaming directly into a TriStateVal type, so I have to use a temporary value first.&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0cm 0cm 12pt;" class="MsoNormal"&gt;&lt;span style="font-size:small;font-family:Times New Roman;"&gt;Of course, these 2 functions work for strings. What about wstring? Well, for wstring we need another 2 overloads.&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0cm 0cm 12pt;" 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;template&lt;/span&gt; &amp;lt;&lt;span style="color:blue;"&gt;typename&lt;/span&gt; T&amp;gt;&lt;br /&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;bool&lt;/span&gt; ParseArg(&lt;br /&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;std::tr1::wregex &lt;span style="color:blue;"&gt;const&lt;/span&gt;&amp;amp; pattern,&lt;br /&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;std::wstring &lt;span style="color:blue;"&gt;const&lt;/span&gt;&amp;amp; arg,&lt;br /&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;T&amp;amp; value)&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;//&lt;br /&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;template&lt;/span&gt; &amp;lt;&lt;span style="color:blue;"&gt;typename&lt;/span&gt; T&amp;gt;&lt;br /&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;bool&lt;/span&gt; ParseArg(&lt;br /&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;std::tr1::wregex &lt;span style="color:blue;"&gt;const&lt;/span&gt;&amp;amp; pattern,&lt;br /&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;std::wstring &lt;span style="color:blue;"&gt;const&lt;/span&gt;&amp;amp; arg,&lt;br /&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;TriStateVal&amp;lt;T&amp;gt;&amp;amp; value)&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;//&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:0cm 0cm 12pt;" class="MsoNormal"&gt;&lt;span style="font-size:small;font-family:Times New Roman;"&gt;These are almost identical, except that they use wregex, wstring and wistringstream instead of regex, string and istringstream.&lt;/span&gt;&lt;/p&gt;
&lt;h2 style="margin:12pt 0cm 3pt;"&gt;&lt;em&gt;&lt;span style="font-size:large;font-family:Arial;"&gt;The overload mechanism&lt;/span&gt;&lt;/em&gt;&lt;/h2&gt;
&lt;p style="margin:0cm 0cm 12pt;" class="MsoNormal"&gt;&lt;span style="font-size:small;font-family:Times New Roman;"&gt;By now you may have wondered about the function overloading, if you are into template laws.&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:small;font-family:Times New Roman;"&gt;There are 4 overloads (removed template specifier &lt;/span&gt;&lt;span style="font-size:10pt;color:blue;font-family:&amp;#39;Courier New&amp;#39;;mso-no-proof:yes;"&gt;template&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;mso-no-proof:yes;"&gt; &amp;lt;&lt;span style="color:blue;"&gt;typename&lt;/span&gt; T&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0cm 0cm 12pt;" class="MsoNormal"&gt;&lt;span style="font-size:small;"&gt;&lt;span style="font-family:Times New Roman;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&lt;/span&gt;for clarity):&lt;/span&gt;&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;bool&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;mso-no-proof:yes;"&gt; ParseArg(regex &lt;span style="color:blue;"&gt;const&lt;/span&gt;&amp;amp;, string &lt;span style="color:blue;"&gt;const&lt;/span&gt;&amp;amp;, T&amp;amp;);&lt;br /&gt;&lt;span style="color:blue;"&gt;bool&lt;/span&gt; ParseArg(regex &lt;span style="color:blue;"&gt;const&lt;/span&gt;&amp;amp;, string &lt;span style="color:blue;"&gt;const&lt;/span&gt;&amp;amp;, TriStateVal&amp;lt;T&amp;gt;&amp;amp;);&lt;br /&gt;&lt;span style="color:blue;"&gt;bool&lt;/span&gt; ParseArg(wregex &lt;span style="color:blue;"&gt;const&lt;/span&gt;&amp;amp;, wstring &lt;span style="color:blue;"&gt;const&lt;/span&gt;&amp;amp;, T&amp;amp;);&lt;br /&gt;&lt;span style="color:blue;"&gt;bool&lt;/span&gt; ParseArg(wregex &lt;span style="color:blue;"&gt;const&lt;/span&gt;&amp;amp;, wstring &lt;span style="color:blue;"&gt;const&lt;/span&gt;&amp;amp;, TriStateVal&amp;lt;T&amp;gt;&amp;amp;);&lt;br style="mso-special-character:line-break;" /&gt;&lt;br style="mso-special-character:line-break;" /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0cm 0cm 12pt;" class="MsoNormal"&gt;&lt;span style="font-size:small;font-family:Times New Roman;"&gt;It is simple enough to see how the compiler chooses based on the types of the pattern and the argument. That is via normal overloading rules.&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0cm 0cm 12pt;" class="MsoNormal"&gt;&lt;span style="font-size:small;font-family:Times New Roman;"&gt;But how does it know when to pick the generic T template function or the more specific TriStateVal&amp;lt;T&amp;gt; template? Both can be valid.&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0cm 0cm 12pt;" class="MsoNormal"&gt;&lt;span style="font-size:small;font-family:Times New Roman;"&gt;As it turns out, the compiler can follow the rules laid out in the C++ ISO standard section 14.5.5.2, which states that if multiple template functions are valid for the supplied template types, the most specific one will be selected.&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0cm 0cm 12pt;" class="MsoNormal"&gt;&lt;span style="font-size:small;font-family:Times New Roman;"&gt;The wording is of course more complex and formal than the previous paragraph, but that is what it boils down to. Section 14.5.5.2.5 contains a number of helpful examples, and one of them is equivalent with the ParseArg function.&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0cm 0cm 12pt;" class="MsoNormal"&gt;&lt;span style="font-size:small;font-family:Times New Roman;"&gt;TriStateVal&amp;lt;T&amp;gt; is more specific than T, so the function with that parameter type will be used whenever possible.&lt;/span&gt;&lt;/p&gt;
&lt;h2 style="margin:12pt 0cm 3pt;"&gt;&lt;em&gt;&lt;span style="font-size:large;font-family:Arial;"&gt;Evaluation of the first attempt&lt;/span&gt;&lt;/em&gt;&lt;/h2&gt;
&lt;p style="margin:0cm 0cm 12pt;" class="MsoNormal"&gt;&lt;span style="font-size:small;font-family:Times New Roman;"&gt;The first implementation works very well. You use the ParseArg function like this:&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0cm 0cm 12pt;" class="MsoNormal"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;mso-no-proof:yes;"&gt;wregex reFile(L&lt;span style="color:#a31515;"&gt;&amp;quot;^[-/]file[:=]\&amp;quot;{0,1}([^\\?\\*/&amp;lt;&amp;gt;\\\&amp;quot;]*)\&amp;quot;{0,1}$&amp;quot;&lt;/span&gt;);&lt;br /&gt;wregex reRows(L&lt;span style="color:#a31515;"&gt;&amp;quot;^[-/]rows[:=]([0-9]*)$&amp;quot;&lt;/span&gt;);&lt;br /&gt;wregex reCols(L&lt;span style="color:#a31515;"&gt;&amp;quot;^[-/]cols[:=]([0-9]*)$&amp;quot;&lt;/span&gt;);&lt;br /&gt;&lt;br /&gt;&lt;span style="color:blue;"&gt;int&lt;/span&gt; _tmain(&lt;span style="color:blue;"&gt;int&lt;/span&gt; argc, _TCHAR* argv[])&lt;br /&gt;{&lt;br /&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;int&lt;/span&gt; numRows = 0;&lt;br /&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;TriStateVal&amp;lt;&lt;span style="color:blue;"&gt;int&lt;/span&gt;&amp;gt; numCols;&lt;br /&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;wstring file;&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; &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; argc; i++)&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;wstring arg(argv);&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;if&lt;/span&gt;(ParseArg(reRows, arg, numRows))&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;continue&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;if&lt;/span&gt;(ParseArg(reCols, arg, numCols))&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;continue&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;if&lt;/span&gt;(ParseArg(reFile, arg, file))&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;continue&lt;/span&gt;;&lt;br /&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;wcout &amp;lt;&amp;lt; &lt;span style="color:#a31515;"&gt;&amp;quot;numRows : &amp;quot;&lt;/span&gt; &amp;lt;&amp;lt; numRows &amp;lt;&amp;lt; endl;;&lt;br /&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;wcout &amp;lt;&amp;lt; &lt;span style="color:#a31515;"&gt;&amp;quot;numCols : &amp;quot;&lt;/span&gt; &amp;lt;&amp;lt; numRows &amp;lt;&amp;lt; endl;;&lt;br /&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;wcout &amp;lt;&amp;lt; &lt;span style="color:#a31515;"&gt;&amp;quot;file : &amp;quot;&lt;/span&gt; &amp;lt;&amp;lt; file &amp;lt;&amp;lt; endl;;&lt;br /&gt;&lt;br /&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;return&lt;/span&gt; 0;&lt;br /&gt;}&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0cm 0cm 12pt;" class="MsoNormal"&gt;&lt;span style="font-size:small;font-family:Times New Roman;"&gt;As you can see, no matter how many command parameters there are and how complex their formatting is, parsing them remains trivial if you can correctly specify the regular expressions.&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0cm 0cm 12pt;" class="MsoNormal"&gt;&lt;span style="font-size:small;font-family:Times New Roman;"&gt;The regular expressions in my example also take care of the fact that users can use either the &amp;ndash; or the / to precede identifiers, and that the value delimiter can be a = or : sign.&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0cm 0cm 12pt;" class="MsoNormal"&gt;&lt;span style="font-size:small;font-family:Times New Roman;"&gt;The great benefit of the TriStateVal is that you don&amp;rsquo;t have to keep track of Boolean variables, indicating the status of a variable. I.e. you don&amp;rsquo;t have to manually keep track of which variables were assigned.&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0cm 0cm 12pt;" class="MsoNormal"&gt;&lt;span style="font-size:small;font-family:Times New Roman;"&gt;If your application can do several things, based on a &amp;lsquo;command&amp;rsquo; parameter for example, then you can check the TriStateVal variables for that command to see if those have been assigned to. If will make your whole program easier to understand.&lt;/span&gt;&lt;/p&gt;
&lt;h2 style="margin:12pt 0cm 3pt;"&gt;&lt;em&gt;&lt;span style="font-size:large;font-family:Arial;"&gt;Problems with the first attempt&lt;/span&gt;&lt;/em&gt;&lt;/h2&gt;
&lt;p style="margin:0cm 0cm 12pt;" class="MsoNormal"&gt;&lt;span style="font-size:small;font-family:Times New Roman;"&gt;One&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;issue is that it sadly doesn&amp;rsquo;t work if T is of type &amp;lsquo;char&amp;rsquo; or &amp;lsquo;wchar_t&amp;rsquo;. The reason is that these types are the character types which make up &amp;lsquo;string&amp;rsquo; and &amp;lsquo;wstring&amp;rsquo;, and streaming from a string stream into a char is not supported.&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0cm 0cm 12pt;" class="MsoNormal"&gt;&lt;span style="font-size:small;font-family:Times New Roman;"&gt;Another possible issue is that in the case that T is of type bool, the text value has to be 1 or 0. Perhaps we would also like to be able to use &amp;lsquo;on&amp;rsquo; and &amp;lsquo;off&amp;rsquo; as valid value texts, or &amp;lsquo;high&amp;rsquo; and &amp;lsquo;low&amp;rsquo;.&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:small;"&gt;&lt;span style="font-family:Times New Roman;"&gt;Both problems can be solved by providing more specific template functions, like (removed template specifier &lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;mso-no-proof:yes;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0cm 0cm 12pt;" class="MsoNormal"&gt;&lt;span style="font-size:small;"&gt;&lt;span style="font-family:Times New Roman;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&lt;/span&gt;for clarity):&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0cm 0cm 12pt;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;template&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;mso-no-proof:yes;"&gt; &amp;lt;&amp;gt; &lt;span style="color:blue;"&gt;bool&lt;/span&gt; ParseArg(regex &lt;span style="color:blue;"&gt;const&lt;/span&gt;&amp;amp;, string &lt;span style="color:blue;"&gt;const&lt;/span&gt;&amp;amp;, &lt;span style="color:blue;"&gt;bool&lt;/span&gt; &amp;amp;);&lt;br /&gt;&lt;span style="color:blue;"&gt;template&lt;/span&gt; &amp;lt;&amp;gt; &lt;span style="color:blue;"&gt;bool&lt;/span&gt; ParseArg(regex &lt;span style="color:blue;"&gt;const&lt;/span&gt;&amp;amp;, string &lt;span style="color:blue;"&gt;const&lt;/span&gt;&amp;amp;, &lt;span style="color:blue;"&gt;char&lt;/span&gt; &amp;amp;);&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0cm 0cm 12pt;" class="MsoNormal"&gt;&lt;span style="font-size:small;font-family:Times New Roman;"&gt;But if we want to implement those functions, we not only have to implement the string-regex function, but also the wstring-wregex function, and the functions that use TriStateVal parameters.&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0cm 0cm 12pt;" class="MsoNormal"&gt;&lt;span style="font-size:small;font-family:Times New Roman;"&gt;So instead of having to write 2 additional functions, we would have to implement 8 functions.&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0cm 0cm 12pt;" class="MsoNormal"&gt;&lt;span style="font-size:small;font-family:Times New Roman;"&gt;We could partially fix that by making the regex and string parameters templates instead of qualified types, but that does not fix the problem of the types that are used internally (smatch and istringstream).&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0cm 0cm 12pt;" class="MsoNormal"&gt;&lt;span style="font-size:small;font-family:Times New Roman;"&gt;Of course, we could make those template arguments as well, but that would break automatic type inference, and force the programmer to specialize the template function explicitly, which would be ugly and confusing.&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0cm 0cm 12pt;" class="MsoNormal"&gt;&lt;span style="font-size:small;font-family:Times New Roman;"&gt;So instead we use a trick that is also used in the STL itself: we use a helper class that deduces those internal types for us.&lt;/span&gt;&lt;/p&gt;
&lt;h2 style="margin:12pt 0cm 3pt;"&gt;&lt;em&gt;&lt;span style="font-size:large;font-family:Arial;"&gt;Second attempt&lt;/span&gt;&lt;/em&gt;&lt;/h2&gt;
&lt;p style="margin:0cm 0cm 12pt;" class="MsoNormal"&gt;&lt;span style="font-size:small;font-family:Times New Roman;"&gt;The key to the second attempt is to use a helper class that &amp;ndash;through specialization- will specify the dependent types.&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0cm 0cm 12pt;" class="MsoNormal"&gt;&lt;span style="font-size:small;font-family:Times New Roman;"&gt;The coat hanger for this mechanism is the empty class&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0cm 0cm 12pt;" 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;template&lt;/span&gt; &amp;lt;&lt;span style="color:blue;"&gt;typename&lt;/span&gt; strType&amp;gt;&lt;br /&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;struct&lt;/span&gt; __pca_typehelper{};&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0cm 0cm 12pt;" class="MsoNormal"&gt;&lt;span style="font-size:small;font-family:Times New Roman;"&gt;which has 2 specializations:&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0cm 0cm 12pt;" 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;template&lt;/span&gt; &amp;lt;&amp;gt;&lt;br /&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;struct&lt;/span&gt; __pca_typehelper&amp;lt;std::string&amp;gt;&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;&lt;span style="color:blue;"&gt;typedef&lt;/span&gt; std::tr1::smatch MatchType;&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;typedef&lt;/span&gt; std::istringstream SStreamType;&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;typedef&lt;/span&gt; std::tr1::regex RegexType;&lt;br /&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;};&lt;br /&gt;&lt;br /&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;template&lt;/span&gt; &amp;lt;&amp;gt;&lt;br /&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;struct&lt;/span&gt; __pca_typehelper&amp;lt;std::wstring&amp;gt;&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;&lt;span style="color:blue;"&gt;typedef&lt;/span&gt; std::tr1::wsmatch MatchType;&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;typedef&lt;/span&gt; std::wistringstream SStreamType;&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;typedef&lt;/span&gt; std::tr1::wregex RegexType;&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:0cm 0cm 12pt;" class="MsoNormal"&gt;&lt;span style="font-size:small;font-family:Times New Roman;"&gt;Depending on which specialization is picked, MatchType, SStreamType and RegexType are typedef&amp;rsquo;ed to the correct STL and TR1 types.&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0cm 0cm 12pt;" class="MsoNormal"&gt;&lt;span style="font-size:small;font-family:Times New Roman;"&gt;And the nice thing is that is the user supplies something other than string or wstring, compilation will fail at this stage already, because those typedefs don&amp;rsquo;t exist.&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0cm 0cm 12pt;" class="MsoNormal"&gt;&lt;span style="font-size:small;font-family:Times New Roman;"&gt;Using that helper class, the ParseArg function can be written like this:&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0cm 0cm 12pt;" 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;template&lt;/span&gt; &amp;lt;&lt;span style="color:blue;"&gt;typename&lt;/span&gt; Targ, &lt;span style="color:blue;"&gt;typename&lt;/span&gt; Tresult&amp;gt;&lt;br /&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;bool&lt;/span&gt; ParseArg(&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;typename&lt;/span&gt; __pca_typehelper&amp;lt;Targ&amp;gt;::RegexType &lt;span style="color:blue;"&gt;const&lt;/span&gt;&amp;amp; pattern,&lt;br /&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Targ &lt;span style="color:blue;"&gt;const&lt;/span&gt;&amp;amp; arg,&lt;br /&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Tresult&amp;amp; value)&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;n