<?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://dirty-motherfucker.org/blog/category/cplusplus/feed/" rel="self" type="application/rss+xml" />
	<link>http://dirty-motherfucker.org/blog</link>
	<description>All kinds of shit</description>
	<lastBuildDate>Wed, 04 Jan 2012 15:38:39 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4-alpha-19620</generator>
		<item>
		<title>Introducing &#8220;annoyance&#8221; aka &#8220;Stop fucking with my Windows&#8221;</title>
		<link>http://dirty-motherfucker.org/blog/2011/03/26/introducing-annoyance-aka-stop-fucking-with-my-windows/</link>
		<comments>http://dirty-motherfucker.org/blog/2011/03/26/introducing-annoyance-aka-stop-fucking-with-my-windows/#comments</comments>
		<pubDate>Fri, 25 Mar 2011 23:48:32 +0000</pubDate>
		<dc:creator>gencha</dc:creator>
				<category><![CDATA[c++]]></category>
		<category><![CDATA[annoyance]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://www.dirty-motherfucker.org/blog/?p=334</guid>
		<description><![CDATA[I can really do well with Windows in my everyday work. Being a developer, a lot of shit that gets on my nerves is usually solvable. But there are two little gems that always get me going when they happen. First of all, I&#8217;m one of those guys who sets his taskbar to auto-hide. So [...]]]></description>
			<content:encoded><![CDATA[<p>I can really do well with Windows in my everyday work. Being a developer, a lot of shit that gets on my nerves is usually solvable. But there are two little gems that always get me going when they happen.</p>
<p>First of all, I&#8217;m one of those guys who sets his taskbar to auto-hide. So when something causes it to un-hide, it will display over quite the large part of my screen (I also dock it to the left side of the left-most screen). And the only reason (in my opinion) to un-hide the taskbar should be through my direct interaction. But Windows thinks a little different about that. There are certain API functions that will cause the taskbar to un-hide. For example FlashWindowEx. And some developers love to use the shit out of that (Yes! I&#8217;m talking to you, Skype developer!).</p>
<p>Another gem is when applications manage to steal your input focus. You&#8217;re just typing away your super secret password, minding your own business. Then you press enter and it ends up in some stupid IM window cause you were stupid enough not to watch the screen while typing.</p>
<p>So what to do about that?</p>
<p>I attempted to solve these issues on numerous occasions. And to my knowledge, there is no built in way of solving them. Additionally, there is no &#8220;easy&#8221; way of solving them either!</p>
<p>What you <em>can</em> do however, is load your own little DLL into every process and hook those damned API calls and overwrite their behavior. And that&#8217;s where my new project <a href="http://code.google.com/p/annoyance/">annoyance</a> comes into play.</p>
<p>Sadly, right now it requires you to use some highly questionable feature in Windows to load the DLL into new processes. Using that feature opens a door for potential malware (and they sure love to use that feature to fuck with your system).</p>
<p>This was only the first step though. And when I find the time, I will research a better method to load the DLL. But until then, I&#8217;m putting the code out there. Maybe someone else can come up with something.</p>
]]></content:encoded>
			<wfw:commentRss>http://dirty-motherfucker.org/blog/2011/03/26/introducing-annoyance-aka-stop-fucking-with-my-windows/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Build count of VC++ project for version string</title>
		<link>http://dirty-motherfucker.org/blog/2009/04/24/build-count-of-vc-project-for-version-string/</link>
		<comments>http://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; title: ; notranslate">
@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://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://dirty-motherfucker.org/blog/2009/03/10/output-the-parent-console-in-windows-application/</link>
		<comments>http://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; title: ; notranslate">
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://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>

