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

<channel>
	<title>&#62;devblog_ &#187; C++</title>
	<atom:link href="http://devblog.itsth.com/category/c/feed/" rel="self" type="application/rss+xml" />
	<link>http://devblog.itsth.com</link>
	<description>Thoughts on developing shareware</description>
	<lastBuildDate>Wed, 14 Dec 2011 16:29:59 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Useful function: EnableWindowsDependingOn</title>
		<link>http://devblog.itsth.com/2011/03/21/useful-function-enablewindowsdependingon/</link>
		<comments>http://devblog.itsth.com/2011/03/21/useful-function-enablewindowsdependingon/#comments</comments>
		<pubDate>Mon, 21 Mar 2011 14:48:11 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://devblog.itsth.com/?p=161</guid>
		<description><![CDATA[One of my favorite internal functions. It helps my manage my app&#8217;s GUI. Checkboxes that cause their sub-elements to be greyed out when not checked can be easily handled by this: bool EnableWindowsDependingOn (CWnd *pParent, DWORD DependingOnThisCheckbox, DWORD Value1, ...) { va_list marker; bool bState = (((CButton*)pParent-&#62;GetDlgItem(DependingOnThisCheckbox))-&#62;GetCheck()!=0); DWORD i=Value1; va_start (marker, Value1); while (i != [...]]]></description>
			<content:encoded><![CDATA[<p>One of my favorite internal functions. It helps my manage my app&#8217;s GUI. Checkboxes that cause their sub-elements to be greyed out when not checked can be easily handled by this:</p>
<pre>bool EnableWindowsDependingOn (CWnd *pParent, DWORD DependingOnThisCheckbox, DWORD Value1, ...)
{
 va_list marker;

 bool bState = (((CButton*)pParent-&gt;GetDlgItem(DependingOnThisCheckbox))-&gt;GetCheck()!=0);

 DWORD i=Value1;
 va_start (marker, Value1);
 while (i != 0)
 {
 if (i&lt;=0xffff)
 {
 if (pParent-&gt;GetDlgItem(i))
 pParent-&gt;GetDlgItem(i)-&gt;EnableWindow (bState);
 }
 else
 ((CWnd*)i)-&gt;EnableWindow (bState);

 i = va_arg (marker, long);
 }
 va_end (marker);

 return (bState);
}
</pre>
<p>It excepts the this pointer of your CDialog and the id of the master checkbox. Then you can append any number of sub-element ids or pointers. And finally a NULL. Example:<br />
EnableWindowsDependingOn (this, IDC_CHECK1, IDC_EDIT1, IDC_EDIT2, NULL);</p>
<p>This would enable the two edit boxes if the checkbox is enabled.</p>
]]></content:encoded>
			<wfw:commentRss>http://devblog.itsth.com/2011/03/21/useful-function-enablewindowsdependingon/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Visual Studio 2005: Speeding up compiles</title>
		<link>http://devblog.itsth.com/2010/10/19/visual-studio-2005-speeding-up-compiles/</link>
		<comments>http://devblog.itsth.com/2010/10/19/visual-studio-2005-speeding-up-compiles/#comments</comments>
		<pubDate>Tue, 19 Oct 2010 21:49:05 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[microsoft]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://devblog.itsth.com/?p=139</guid>
		<description><![CDATA[There&#8217;s a hidden switch in Visual Studio 2005 while doubles compile speed. I know, it sounds ridiculous.  But I&#8217;ve tested it. It&#8217;s MUCH faster now. The switch works by enabling multi-core processing. I have no idea why Microsoft has hidden this, instead of making it a big, obvious feature. Anyways. You can enable it by [...]]]></description>
			<content:encoded><![CDATA[<p>There&#8217;s a hidden switch in Visual Studio 2005 while doubles compile speed.</p>
<p>I know, it sounds ridiculous.  But I&#8217;ve tested it. It&#8217;s MUCH faster now. The switch works by enabling multi-core processing. I have no idea why Microsoft has hidden this, instead of making it a big, obvious feature.</p>
<p>Anyways. You can enable it by adding /MP to the &#8220;Additional options&#8221; in &#8220;Configuration properties &gt; C/C++ &gt; Commandline&#8221;.</p>
<p>(Found it at <a href="http://lahsiv.net/blog/?p=40">1</a> and <a href="http://blog.280z28.org/archives/2007/10/17/">2</a>)</p>
]]></content:encoded>
			<wfw:commentRss>http://devblog.itsth.com/2010/10/19/visual-studio-2005-speeding-up-compiles/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dangerous CFile::GetStatus</title>
		<link>http://devblog.itsth.com/2010/10/01/dangerous-cfilegetstatus/</link>
		<comments>http://devblog.itsth.com/2010/10/01/dangerous-cfilegetstatus/#comments</comments>
		<pubDate>Fri, 01 Oct 2010 11:57:09 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[Dangerous]]></category>
		<category><![CDATA[GetStatus]]></category>

		<guid isPermaLink="false">http://devblog.itsth.com/?p=133</guid>
		<description><![CDATA[The third (and I hope final) dangerous posting. This code looks harmless enough: CFileStatus rStatus; CFile::GetStatus (MyFilename, rStatus); And it will work most of the time. But CFileStatus uses CTime, which is limited to dates after 1.1.1970. If you apply this code to a file with a file-modification date of e.g. 1.1.1960, GetStatus will raise [...]]]></description>
			<content:encoded><![CDATA[<p>The third (and I hope final) <a href="http://devblog.itsth.com/tag/dangerous/">dangerous</a> posting.</p>
<p>This code looks harmless enough:</p>
<pre>CFileStatus rStatus;
CFile::GetStatus (MyFilename, rStatus);</pre>
<p>And it will work most of the time. But CFileStatus uses CTime, which is limited to dates after 1.1.1970. If you apply this code to a file with a file-modification date of e.g. 1.1.1960, GetStatus will raise an exception. (Which it isn&#8217;t documented to to.) And if you don&#8217;t catch that, it will terminate your program.</p>
]]></content:encoded>
			<wfw:commentRss>http://devblog.itsth.com/2010/10/01/dangerous-cfilegetstatus/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dangerous printf</title>
		<link>http://devblog.itsth.com/2010/09/17/dangerous-printf/</link>
		<comments>http://devblog.itsth.com/2010/09/17/dangerous-printf/#comments</comments>
		<pubDate>Fri, 17 Sep 2010 16:53:03 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[Dangerous]]></category>
		<category><![CDATA[printf]]></category>

		<guid isPermaLink="false">http://devblog.itsth.com/?p=127</guid>
		<description><![CDATA[It took quite some time until I found this bug. Here&#8217;s a simplified version of what caused it: char dir[2048]; GetCurrentDirectory(2048, dir); printf(CString("Current dir is:")+dir)); That&#8217;s doesn&#8217;t look bad, does it? And (like in the great programmer quotes), it works on my computer. But it doesn&#8217;t work if the customer&#8217;s current folder is something like [...]]]></description>
			<content:encoded><![CDATA[<p>It took quite some time until I found this bug. Here&#8217;s a simplified version of what caused it:</p>
<pre>char dir[2048];
GetCurrentDirectory(2048, dir);
printf(CString("Current dir is:")+dir));</pre>
<p>That&#8217;s doesn&#8217;t look bad, does it? And (like in the great <a href="http://archive.kaskus.us/thread/1187451/">programmer quotes</a>), it works on my computer. But it doesn&#8217;t work if the customer&#8217;s current folder is something like &#8220;%&amp;§something&#8221;, because it contains %s.</p>
<p>So don&#8217;t throw any external data at the first parameter of printf, sprintf, etc; instead put it into the following parameters.</p>
<p>printf(&#8220;Current dir is: %s&#8221;, dir);</p>
]]></content:encoded>
			<wfw:commentRss>http://devblog.itsth.com/2010/09/17/dangerous-printf/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dangerous COleDateTime::ParseDateTime</title>
		<link>http://devblog.itsth.com/2010/08/20/dangerous-coledatetimeparsedatetime/</link>
		<comments>http://devblog.itsth.com/2010/08/20/dangerous-coledatetimeparsedatetime/#comments</comments>
		<pubDate>Fri, 20 Aug 2010 11:59:40 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[COleDateTime]]></category>
		<category><![CDATA[Dangerous]]></category>
		<category><![CDATA[ParseDateTime]]></category>

		<guid isPermaLink="false">http://devblog.itsth.com/?p=116</guid>
		<description><![CDATA[COleDateTime::ParseDateTime is a handy function to parse a date string into a COleDateTime (and then SYSTEMTIME and then CTime). The problem is that the expected date format depends on the user&#8217;s system settings. If you&#8217;re parsing a string that is always in the same format (from a file or from the internet), then parsing might [...]]]></description>
			<content:encoded><![CDATA[<p>COleDateTime::ParseDateTime is a handy function to parse a date string into a COleDateTime (and then SYSTEMTIME and then CTime).</p>
<p>The problem is that the expected date format depends on the user&#8217;s system settings. If you&#8217;re parsing a string that is always in the same format (from a file or from the internet), then parsing might work on your computer, but fail on the customer&#8217;s computer (in another country).</p>
<p>Solution: Use the locale ID parameter to force the parsing language.</p>
]]></content:encoded>
			<wfw:commentRss>http://devblog.itsth.com/2010/08/20/dangerous-coledatetimeparsedatetime/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CMap: Mapping CString to CStringArray</title>
		<link>http://devblog.itsth.com/2010/08/09/cmap-mapping-cstring-to-cstringarray/</link>
		<comments>http://devblog.itsth.com/2010/08/09/cmap-mapping-cstring-to-cstringarray/#comments</comments>
		<pubDate>Mon, 09 Aug 2010 10:10:29 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[MFC]]></category>

		<guid isPermaLink="false">http://devblog.itsth.com/?p=109</guid>
		<description><![CDATA[Just a simple MFC trick. To map from CString to CStringArray use: CMap&#60;CString, LPCTSTR, CStringArrayX, CStringArrayX&#38;&#62; where CStringArrayX is defined as: class CStringArrayX : public CStringArray { public: CStringArrayX() {} CStringArrayX(const CStringArrayX &#38;qSource); CStringArrayX &#38;operator = (const CStringArrayX &#38;qSource); }; CStringArrayX::CStringArrayX (const CStringArrayX &#38;qSource) { SetSize (qSource.GetSize()); for (long c=qSource.GetSize()-1; c&#62;=0; c--) (*this)[c]=qSource[c]; } CStringArrayX [...]]]></description>
			<content:encoded><![CDATA[<p>Just a simple MFC trick. To map from CString to CStringArray use:</p>
<p>CMap&lt;CString, LPCTSTR, CStringArrayX, CStringArrayX&amp;&gt;</p>
<p>where CStringArrayX is defined as:</p>
<pre>class CStringArrayX : public CStringArray
{
 public:
 CStringArrayX() {}
 CStringArrayX(const CStringArrayX &amp;qSource);
 CStringArrayX &amp;operator = (const CStringArrayX &amp;qSource);
};
</pre>
<pre>CStringArrayX::CStringArrayX (const CStringArrayX &amp;qSource)
{
 SetSize (qSource.GetSize());

 for (long c=qSource.GetSize()-1; c&gt;=0; c--)
   (*this)[c]=qSource[c];
}
</pre>
<pre>CStringArrayX &amp;CStringArrayX::operator = (const CStringArrayX &amp;qSource)
{
 SetSize (qSource.GetSize());
</pre>
<pre> for (long c=qSource.GetSize()-1; c&gt;=0; c--)
   (*this)[c]=qSource[c];
</pre>
<pre> return (*this);
}
</pre>
<p>Hopefully this post keeps some people from searching as long as I did&#8230; <img src='http://devblog.itsth.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://devblog.itsth.com/2010/08/09/cmap-mapping-cstring-to-cstringarray/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Silencing command line builds</title>
		<link>http://devblog.itsth.com/2010/08/02/silencing-command-line-builds/</link>
		<comments>http://devblog.itsth.com/2010/08/02/silencing-command-line-builds/#comments</comments>
		<pubDate>Mon, 02 Aug 2010 11:13:32 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[freeware]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[build]]></category>
		<category><![CDATA[silent]]></category>
		<category><![CDATA[verbose]]></category>

		<guid isPermaLink="false">http://devblog.itsth.com/?p=104</guid>
		<description><![CDATA[My builds have become more and more complex. Especially when releasing a new version it wasn&#8217;t always easy to tell at first glance whether all build steps succeeded. Some tools (I&#8217;m not telling names, here) are quite verbose and &#8220;pollute&#8221; the build log with things that I don&#8217;t really care about. Here&#8217;s a simple freeware [...]]]></description>
			<content:encoded><![CDATA[<p>My builds have become more and more complex. Especially when releasing a new version it wasn&#8217;t always easy to tell at first glance whether all build steps succeeded. Some tools (I&#8217;m not telling names, here) are quite verbose and &#8220;pollute&#8221; the build log with things that I don&#8217;t really care about.</p>
<p>Here&#8217;s a simple freeware tool that I wrote to fix this: SilentCommandline.exe. It works as a DOS pipe with filter functions that can be configured in two external text files.</p>
<h3>Using SilentCommandline:</h3>
<p>Simply append it to your build batch files:</p>
<pre>yourbuildcommand.exe |SilentCommandline.exe</pre>
<p>It will take all output of  yourbuildcommand.exe, check if you want to see it and print it to stdout. To configure what you want to see, create 2 text files in the same folder where you keep SilentComandline.exe and name them silentlines.txt and silentlinesre.txt.</p>
<h3>Config files:</h3>
<p>The first one is simple. On string per line. If one of the strings equals a line from your build output, then this line will not be printed. You can use that for static texts that are always the same. Example:</p>
<pre>Succeeded</pre>
<p>The second file works basically the same, but allows you to use regular expressions in each line. Use it to handle build outputs that might change. Example:</p>
<pre>Protected[0-9]* blocks of [0-9]* blocks total.</pre>
<h3>Download:</h3>
<p>Here&#8217;s the download link to <a href="http://www.itsth.com/download/SilentCommandline.exe">SilentCommandLine.exe</a></p>
<p>System requirements: Windows</p>
]]></content:encoded>
			<wfw:commentRss>http://devblog.itsth.com/2010/08/02/silencing-command-line-builds/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Linking .lib files in C++</title>
		<link>http://devblog.itsth.com/2010/07/22/linking-lib-files-in-c/</link>
		<comments>http://devblog.itsth.com/2010/07/22/linking-lib-files-in-c/#comments</comments>
		<pubDate>Thu, 22 Jul 2010 10:20:07 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://devblog.itsth.com/?p=102</guid>
		<description><![CDATA[Sooner or later you will need to link static external library files (.lib files), when developing a larger project. Microsoft C++ can do this in several ways: Link settings in the project properties Adding the file to the source file tree Using a #pragma So far I&#8217;ve mostly used 1 &#38; 2, because they&#8217;re the [...]]]></description>
			<content:encoded><![CDATA[<p>Sooner or later you will need to link static external library files (.lib files), when developing a larger project. Microsoft C++ can do this in several ways:</p>
<ol>
<li>Link settings in the project properties</li>
<li>Adding the file to the source file tree</li>
<li>Using a #pragma</li>
</ol>
<p>So far I&#8217;ve mostly used 1 &amp; 2, because they&#8217;re the easiest and most obvious ways. Solution 2 can even be used conditionally for certain build types (by using the &#8220;exclude for this build&#8221; option).</p>
<p>But with the projects getting more complex, I found that solution 3 is the best and switched projects to that. The reason is that different combinations of project types (debug/release 32/64 Bit) are otherwise quite difficult  to handle.</p>
<p>With #pragma&#8217;s is does take some space in one your .cpp-files, but at least the different conditions are easy to understand and verify:</p>
<pre>#ifdef _WIN64
  #ifdef _DEBUG
    #pragma comment(lib, "C:\MyPath\\MyDebug64.lib")
  #else
    #pragma comment(lib, "C:\MyPath\\MyRelease64.lib")
  #endif
#else
  #ifdef _DEBUG
    #pragma comment(lib, "C:\MyPath\\MyDebug32.lib")
  #else
    #pragma comment(lib, "C:\MyPath\\MyRelease32.lib")
  #endif
#endif
</pre>
]]></content:encoded>
			<wfw:commentRss>http://devblog.itsth.com/2010/07/22/linking-lib-files-in-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The C++ riddle</title>
		<link>http://devblog.itsth.com/2010/06/24/the-c-riddle/</link>
		<comments>http://devblog.itsth.com/2010/06/24/the-c-riddle/#comments</comments>
		<pubDate>Thu, 24 Jun 2010 08:49:22 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://devblog.itsth.com/?p=100</guid>
		<description><![CDATA[C++ is sometimes even more cryptic than regular expressions. Can you figure out what this one means? %016I64lx]]></description>
			<content:encoded><![CDATA[<p>C++ is sometimes even more cryptic than regular expressions. Can you figure out what this one means?</p>
<p>%016I64lx</p>
]]></content:encoded>
			<wfw:commentRss>http://devblog.itsth.com/2010/06/24/the-c-riddle/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using usertype.dat as spell checker</title>
		<link>http://devblog.itsth.com/2009/11/15/using-usertype-dat-as-spell-checker/</link>
		<comments>http://devblog.itsth.com/2009/11/15/using-usertype-dat-as-spell-checker/#comments</comments>
		<pubDate>Sun, 15 Nov 2009 11:36:01 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[IDE]]></category>
		<category><![CDATA[keywords]]></category>
		<category><![CDATA[usertype.dat]]></category>

		<guid isPermaLink="false">http://devblog.itsth.com/?p=58</guid>
		<description><![CDATA[There are thousands of classes, structure, functions and constants in the Windows library and it&#8217;s often hard to remember the right spelling. Here&#8217;s a simple trick to use the usertype.dat as a very simple spell checker. Usertype.dat? First, usertype.dat is a file which can be configured in the MS IDE (see help file, because it [...]]]></description>
			<content:encoded><![CDATA[<p>There are thousands of classes, structure, functions and constants in the Windows library and it&#8217;s often hard to remember the right spelling. Here&#8217;s a simple trick to use the usertype.dat as a very simple spell checker.</p>
<p><strong>Usertype.dat?</strong><br />
First, usertype.dat is a file which can be configured in the MS IDE (see help file, because it differs with the versions). Simply activate it and use my <a href="http://www.easy2sync.com/img/blog/USERTYPE:DAT">usertype.dat</a> as a start. It contains almost 4000 key words from the libraries.</p>
<p>When you now type one of these key words right, it will be displayed in a different color (I prefer gray &#8211; to emphasize that I don&#8217;t have to pay attention here). Here&#8217;s how it can look like.</p>
<p><strong>Example:</strong></p>
<p><img class="alignnone" title="Usertype sample" src="http://www.easy2sync.com/img/blog/Usertype.gif" alt="" width="435" height="77" /></p>
<p>Note that all the common things like HICON, LoadImage or LR_DEFAULTCOLOR are written in gray because they&#8217;re spelled correct. And other words (variables in this case) like hIcon and IconId1 a printed in white because they&#8217;re not predefined. If I had written Load_Image (instead of LoadImage), it would have been printed in white, too, and I know that it might be incorrect.</p>
]]></content:encoded>
			<wfw:commentRss>http://devblog.itsth.com/2009/11/15/using-usertype-dat-as-spell-checker/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

