<?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>Dirty Motherfucking Blog &#187; c++</title>
	<atom:link href="http://www.dirty-motherfucker.org/blog/category/cplusplus/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dirty-motherfucker.org/blog</link>
	<description>All kinds of shit</description>
	<lastBuildDate>Tue, 17 Aug 2010 18:19:53 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1-alpha</generator>
		<item>
		<title>Build count of VC++ project for version string</title>
		<link>http://www.dirty-motherfucker.org/blog/2009/04/24/build-count-of-vc-project-for-version-string/</link>
		<comments>http://www.dirty-motherfucker.org/blog/2009/04/24/build-count-of-vc-project-for-version-string/#comments</comments>
		<pubDate>Fri, 24 Apr 2009 12:18:11 +0000</pubDate>
		<dc:creator>gencha</dc:creator>
				<category><![CDATA[c++]]></category>

		<guid isPermaLink="false">http://www.dirty-motherfucker.org/blog/?p=267</guid>
		<description><![CDATA[For ages now I wanted to write me something nice and neat to get build count (how often the project was built) to append it to my version string. And obviously I wanted it to automatically update. However I never really got around to it or cared that much that I actually wrote it. But [...]]]></description>
			<content:encoded><![CDATA[<p>For ages now I wanted to write me something nice and neat to get build count (how often the project was built) to append it to my version string. And obviously I wanted it to automatically update.<br />
However I never really got around to it or cared that much that I actually wrote it. But today is the day!<br />
And here is how it works:</p>
<pre class="brush: plain;">
@echo off
SETLOCAL
set TARGET_PATH=%~dp0
set FILENAME=&quot;%TARGET_PATH%build.h&quot;
set /p BUILD= &lt; %FILENAME%
set BUILD=%BUILD:~22%
if /I &quot;%BUILD%&quot; == &quot;&quot; set BUILD=0
set /a BUILD=%BUILD%+1
echo #define VERSION_BUILD %BUILD% &gt; %FILENAME%
echo #define VERSION_DATE L&quot;%DATE%&quot; &gt;&gt; %FILENAME%
echo #define VERSION_TIME L&quot;%TIME%&quot; &gt;&gt; %FILENAME%
ENDLOCAL
</pre>
<p>In case it&#8217;s not obvious what this batch file does. First we construct our target filename so that it is still valid even if VS calls the batch from another directory. Then we read in the first line of our build.h (the VERSION_BUILD #define), then we cut off the part before the build number, add 1 and write it back. I also add 2 #defines for date and time, cause, why not? I made date and time already wide strings but left the build count an integer. This makes it slightly easier to parse for the batch file ;)</p>
<p>So just throw the two files in a folder in your project and run the batch once so the build.h is created. Then open up your project properties and add the batch as a new Pre-Build Event. It makes most sense just to do it for Release builds. Now whenever you wanna reference the build count, just #include the build.h. Done.</p>
<p>I guess it would be desirable to solve this whole thing without macros. But at this time I lack the energy to make it more complex. Maybe in a few years&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dirty-motherfucker.org/blog/2009/04/24/build-count-of-vc-project-for-version-string/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Output to the parent console in Windows application</title>
		<link>http://www.dirty-motherfucker.org/blog/2009/03/10/output-the-parent-console-in-windows-application/</link>
		<comments>http://www.dirty-motherfucker.org/blog/2009/03/10/output-the-parent-console-in-windows-application/#comments</comments>
		<pubDate>Tue, 10 Mar 2009 00:27:42 +0000</pubDate>
		<dc:creator>gencha</dc:creator>
				<category><![CDATA[c++]]></category>
		<category><![CDATA[boost]]></category>
		<category><![CDATA[win32]]></category>

		<guid isPermaLink="false">http://www.dirty-motherfucker.org/blog/?p=248</guid>
		<description><![CDATA[So I looked into boost.program_options today to parse command line arguments for my Windows Forms application. Which basically works great. Except for the little part to output the &#8211;help output to the console. Now, obviously when you start your application through Explorer you won&#8217;t have a console. And that is fine. I was only interested [...]]]></description>
			<content:encoded><![CDATA[<p>So I looked into boost.program_options today to parse command line arguments for my Windows Forms application. Which basically works great. Except for the little part to output the &#8211;help output to the console. Now, obviously when you start your application through Explorer you won&#8217;t have a console. And that is fine. I was only interested in the case when you start the application through a console window. Additionally it would also have to work with Unicode of course :P<br />
So after looking around the web for a while I finally managed to put it all together. So here it is:</p>
<pre class="brush: cpp;">
BOOL consoleAttached = AttachConsole( ATTACH_PARENT_PROCESS );

boost::program_options::options_description desc( &quot;Allowed options&quot; );
desc.add_options()
	( &quot;help&quot;, &quot;Show this message&quot; )
	( &quot;width&quot;, &quot;Backbuffer width&quot; )
	( &quot;height&quot;, &quot;Backbuffer height&quot; )
	;

wstring commandLine = GetCommandLine();
int     argc = 0;
LPWSTR* argv = 0;
argv = CommandLineToArgvW( commandLine.c_str(), &amp;argc );

boost::program_options::variables_map vm;
boost::program_options::store( boost::program_options::parse_command_line( argc, argv, desc ), vm );
boost::program_options::notify( vm );

LocalFree( argv );

if( vm.count( &quot;help&quot; ) ) {
	if( consoleAttached ) {
		HANDLE hStdOut = GetStdHandle( STD_OUTPUT_HANDLE );
		if( INVALID_HANDLE_VALUE == hStdOut ) {
			return 1;
		}
		DWORD dwCharsWritten;
		std::stringstream desc_strings;
		desc_strings &lt;&lt; desc;
		std::string desc_string = desc_strings.str();

		WriteConsoleA( hStdOut, desc_string.c_str(), desc_string.length(), &amp;dwCharsWritten, NULL );
		FreeConsole();
	}
	return 1;
}
</pre>
<p>Sadly after the application finishes the prompt doesn&#8217;t instantly return. Maybe I&#8217;ll look into that some day&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dirty-motherfucker.org/blog/2009/03/10/output-the-parent-console-in-windows-application/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
