<?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>Fooling Around</title>
	<atom:link href="http://alax.info/blog/feed" rel="self" type="application/rss+xml" />
	<link>http://alax.info/blog</link>
	<description>// Software Production Line</description>
	<lastBuildDate>Fri, 03 Feb 2012 22:49:15 +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>Utility Clearance: Simple SMTP Email Sender</title>
		<link>http://alax.info/blog/1331</link>
		<comments>http://alax.info/blog/1331#comments</comments>
		<pubDate>Sun, 29 Jan 2012 19:52:09 +0000</pubDate>
		<dc:creator>Roman</dc:creator>
				<category><![CDATA[Utilities]]></category>
		<category><![CDATA[COM]]></category>
		<category><![CDATA[email]]></category>
		<category><![CDATA[message]]></category>
		<category><![CDATA[schannel]]></category>
		<category><![CDATA[SMTP]]></category>
		<category><![CDATA[ssl]]></category>
		<category><![CDATA[tls]]></category>
		<category><![CDATA[utilitiy]]></category>

		<guid isPermaLink="false">http://alax.info/blog/?p=1331</guid>
		<description><![CDATA[The library implements SMTP client and exposes a simple COM interface to send emails. The interface is simple and straightforward, and the emails can be send from various environments, including such as JavaScript code. The class supports SSL/TLS security and &#8230;<p class="read-more"><a href="http://alax.info/blog/1331">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<p>The library implements SMTP client and exposes a simple COM interface to send emails. The interface is simple and straightforward, and the emails can be send from various environments, including such as JavaScript code. The class supports SSL/TLS security and is GMail compliant.</p>
<p><img class="alignnone size-full wp-image-1332" title="Alax.Info Email Tools 1.0 Type Library" src="http://alax.info/blog/wp-content/uploads/2012/01/Image001.png" alt="" width="523" height="479" /></p>
<p>A JScript code snippet below provides a sample use case:</p>
<pre style="color: #000000; background: #ffffff;">message <span style="color: #808030;">=</span> <span style="color: #800000; font-weight: bold;">new</span> <span style="color: #797997;">ActiveXObject</span><span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0000e6;">AlaxInfo.EmailTools.Message</span><span style="color: #800000;">"</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span>
message<span style="color: #808030;">.</span>ServerHost <span style="color: #808030;">=</span> <span style="color: #800000;">"</span><span style="color: #0000e6;">mail.alax.info</span><span style="color: #800000;">"</span><span style="color: #800080;">;</span>
<span style="color: #696969;">//message.ServerPort = 25;</span>
message<span style="color: #808030;">.</span>Sender <span style="color: #808030;">=</span> <span style="color: #800000;">"</span><span style="color: #0000e6;">Sender &lt;test@alax.info&gt;</span><span style="color: #800000;">"</span><span style="color: #800080;">;</span>
message<span style="color: #808030;">.</span>ToRecipients <span style="color: #808030;">=</span> <span style="color: #800000;">"</span><span style="color: #0000e6;">Recipient &lt;address@gmail.com&gt;</span><span style="color: #800000;">"</span><span style="color: #800080;">;</span>
<span style="color: #696969;">//message.CcRecipients = "";</span>
<span style="color: #696969;">//message.BccRecipients = "";</span>
message<span style="color: #808030;">.</span>Subject <span style="color: #808030;">=</span> <span style="color: #800000;">"</span><span style="color: #0000e6;">Message Test (Plain)</span><span style="color: #800000;">"</span><span style="color: #800080;">;</span>
message<span style="color: #808030;">.</span>Body <span style="color: #808030;">=</span> <span style="color: #800000;">"</span><span style="color: #0000e6;">This is an e-mail message test:</span><span style="color: #800000;">"</span> <span style="color: #808030;">+</span> <span style="color: #800000;">"</span><span style="color: #0f69ff;">\r</span><span style="color: #0f69ff;">\n</span><span style="color: #800000;">"</span> <span style="color: #808030;">+</span>
  <span style="color: #800000;">"</span><span style="color: #800000;">"</span> <span style="color: #808030;">+</span> <span style="color: #800000;">"</span><span style="color: #0f69ff;">\r</span><span style="color: #0f69ff;">\n</span><span style="color: #800000;">"</span> <span style="color: #808030;">+</span>
  <span style="color: #800000;">"</span><span style="color: #0000e6;">- Security: None</span><span style="color: #800000;">"</span> <span style="color: #808030;">+</span> <span style="color: #800000;">"</span><span style="color: #0f69ff;">\r</span><span style="color: #0f69ff;">\n</span><span style="color: #800000;">"</span> <span style="color: #808030;">+</span>
  <span style="color: #800000;">"</span><span style="color: #0000e6;">- Authentication: Plain Text (PLAIN)</span><span style="color: #800000;">"</span> <span style="color: #808030;">+</span> <span style="color: #800000;">"</span><span style="color: #0f69ff;">\r</span><span style="color: #0f69ff;">\n</span><span style="color: #800000;">"</span> <span style="color: #808030;">+</span>
  <span style="color: #800000;">"</span><span style="color: #800000;">"</span><span style="color: #800080;">;</span>
message<span style="color: #808030;">.</span>AuthMethods <span style="color: #808030;">=</span> <span style="color: #800000;">"</span><span style="color: #0000e6;">plain</span><span style="color: #800000;">"</span><span style="color: #800080;">;</span>
message<span style="color: #808030;">.</span>AuthName <span style="color: #808030;">=</span> <span style="color: #800000;">"</span><span style="color: #0000e6;">test@alax.info</span><span style="color: #800000;">"</span><span style="color: #800080;">;</span>
message<span style="color: #808030;">.</span>AuthPassword <span style="color: #808030;">=</span> <span style="color: #800000;">"</span><span style="color: #0000e6;">12345678</span><span style="color: #800000;">"</span><span style="color: #800080;">;</span>
message<span style="color: #808030;">.</span>Send<span style="color: #808030;">(</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span></pre>
<p>The capabilities include:</p>
<ul>
<li>No additional dependencies &#8211; regsvr32 the DLL and it&#8217;s ready to use; SSL/TLS implementation through <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa374782%28v=vs.85%29.aspx">SChannel API</a></li>
<li>UTF-8 encoding and support for Unicode and international characters</li>
<li>Secure SSL connections (<strong>SecureSocketsLayer</strong> property)</li>
<li>Secure Transport Layer Security (TLS) connections with <strong>STARTTLS</strong> command (<strong>TransportLayerSecurity</strong> property)</li>
<li>Authentication options: plain text (LOGIN, PLAIN), digest (CRAM-MD5)</li>
<li>Protocol References:</li>
<ul>
<li><a href="http://tools.ietf.org/html/rfc5321">RFC 5321 &#8211; Simple Mail Transfer Protocol</a></li>
<li><a href="http://tools.ietf.org/html/rfc2045">RFC 2045 &#8211; Multipurpose Internet Mail Extensions (MIME) Part One: Format of Internet Message Bodies</a></li>
<li><a href="http://tools.ietf.org/html/rfc3207">RFC 3207 &#8211; SMTP Service Extension for Secure SMTP over Transport Layer Security</a></li>
<li><a href="http://tools.ietf.org/html/rfc2195">RFC 2195 &#8211; IMAP/POP AUTHorize Extension for Simple Challenge/Response</a></li>
<li><a href="http://tools.ietf.org/html/rfc4616">RFC 4616 &#8211; The PLAIN Simple Authentication and Security Layer (SASL) Mechanism</a></li>
</ul>
</ul>
<p><span id="more-1331"></span></p>
<p>Relaying through Google Mail needs secure connection (SSL or TLS) plus plain text authentication of sender:</p>
<pre style="color: #000000; background: #ffffff;">message <span style="color: #808030;">=</span> <span style="color: #800000; font-weight: bold;">new</span> <span style="color: #797997;">ActiveXObject</span><span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0000e6;">AlaxInfo.EmailTools.Message</span><span style="color: #800000;">"</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span>
message<span style="color: #808030;">.</span>ServerHost <span style="color: #808030;">=</span> <span style="color: #800000;">"</span><span style="color: #0000e6;">smtp.gmail.com</span><span style="color: #800000;">"</span><span style="color: #800080;">;</span>
<span style="color: #696969;">//message.ServerPort = 587;</span>
message<span style="color: #808030;">.</span>Sender <span style="color: #808030;">=</span> <span style="color: #800000;">"</span><span style="color: #0000e6;">Sender &lt;foo+sender@gmail.com&gt;</span><span style="color: #800000;">"</span><span style="color: #800080;">;</span>
message<span style="color: #808030;">.</span>ToRecipients <span style="color: #808030;">=</span> <span style="color: #800000;">"</span><span style="color: #0000e6;">Recipient &lt;bar+receiver@gmail.com&gt;</span><span style="color: #800000;">"</span><span style="color: #800080;">;</span>
<span style="color: #696969;">//message.CcRecipients = "";</span>
<span style="color: #696969;">//message.BccRecipients = "";</span>
message<span style="color: #808030;">.</span>Subject <span style="color: #808030;">=</span> <span style="color: #800000;">"</span><span style="color: #0000e6;">Message Test (TLS, Plain)</span><span style="color: #800000;">"</span><span style="color: #800080;">;</span>
message<span style="color: #808030;">.</span>Body <span style="color: #808030;">=</span> <span style="color: #800000;">"</span><span style="color: #0000e6;">This is an e-mail message test:</span><span style="color: #800000;">"</span> <span style="color: #808030;">+</span> <span style="color: #800000;">"</span><span style="color: #0f69ff;">\r</span><span style="color: #0f69ff;">\n</span><span style="color: #800000;">"</span> <span style="color: #808030;">+</span>
  <span style="color: #800000;">"</span><span style="color: #800000;">"</span> <span style="color: #808030;">+</span> <span style="color: #800000;">"</span><span style="color: #0f69ff;">\r</span><span style="color: #0f69ff;">\n</span><span style="color: #800000;">"</span> <span style="color: #808030;">+</span>
  <span style="color: #800000;">"</span><span style="color: #0000e6;">- Security: TLS</span><span style="color: #800000;">"</span> <span style="color: #808030;">+</span> <span style="color: #800000;">"</span><span style="color: #0f69ff;">\r</span><span style="color: #0f69ff;">\n</span><span style="color: #800000;">"</span> <span style="color: #808030;">+</span>
  <span style="color: #800000;">"</span><span style="color: #0000e6;">- Authentication: Plain Text (PLAIN)</span><span style="color: #800000;">"</span> <span style="color: #808030;">+</span> <span style="color: #800000;">"</span><span style="color: #0f69ff;">\r</span><span style="color: #0f69ff;">\n</span><span style="color: #800000;">"</span> <span style="color: #808030;">+</span>
  <span style="color: #800000;">"</span><span style="color: #800000;">"</span><span style="color: #800080;">;</span>
message<span style="color: #808030;">.</span>TransportLayerSecurity <span style="color: #808030;">=</span> <span style="color: #0f4d75;">true</span><span style="color: #800080;">;</span>
message<span style="color: #808030;">.</span>AuthMethods <span style="color: #808030;">=</span> <span style="color: #800000;">"</span><span style="color: #0000e6;">plain</span><span style="color: #800000;">"</span><span style="color: #800080;">;</span>
message<span style="color: #808030;">.</span>AuthName <span style="color: #808030;">=</span> <span style="color: #800000;">"</span><span style="color: #0000e6;">foo@gmail.com</span><span style="color: #800000;">"</span><span style="color: #800080;">;</span>
message<span style="color: #808030;">.</span>AuthPassword <span style="color: #808030;">=</span> <span style="color: #800000;">"</span><span style="color: #0000e6;">password</span><span style="color: #800000;">"</span><span style="color: #800080;">;</span>
message<span style="color: #808030;">.</span>Send<span style="color: #808030;">(</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span></pre>
<h4>Download Information</h4>
<ul>
<li>Download (32-bit): <a href="http://www.alax.info/svn/public/trunk/Utilities/EmailTools/Win32/">EmailTools.dll</a></li>
<li>Download (64-bit): <a href="http://www.alax.info/svn/public/trunk/Utilities/EmailTools/x64/">EmailTools.dll</a></li>
<li>License: This software is free to use</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://alax.info/blog/1331/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>File Mappings: Virtual Memory and Virtual Address Space</title>
		<link>http://alax.info/blog/1325</link>
		<comments>http://alax.info/blog/1325#comments</comments>
		<pubDate>Thu, 15 Dec 2011 23:36:34 +0000</pubDate>
		<dc:creator>Roman</dc:creator>
				<category><![CDATA[ATL]]></category>
		<category><![CDATA[Source]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[WTL]]></category>
		<category><![CDATA[32-bit]]></category>
		<category><![CDATA[CreateFileMapping]]></category>
		<category><![CDATA[file mapping]]></category>
		<category><![CDATA[MapViewOfFile]]></category>
		<category><![CDATA[RAM]]></category>
		<category><![CDATA[virtual memory]]></category>

		<guid isPermaLink="false">http://alax.info/blog/?p=1325</guid>
		<description><![CDATA[More and more applications hit the Windows limit of available address space for 32-bit applications, and the whole concept becomes more important for understanding due to necessity to work things around. A thing, which is more or less easy to &#8230;<p class="read-more"><a href="http://alax.info/blog/1325">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<p>More and more applications hit the Windows limit of available <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa366912%28v=VS.85%29.aspx">address space</a> for 32-bit applications, and the whole concept becomes more important for understanding due to necessity to work things around.</p>
<p>A thing, which is more or less easy to understand, is that a user mode 32-bit application can address 2^32 addresses. The addresses are not directly physical RAM and the operating system is responsible for management of the mapping addresses into RAM as a part of virtual memory manager operation. Paged memory organization is <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa366914%28v=VS.85%29.aspx">well documented on MSDN</a>, and the questions has been raised numerous times. An interesting question is whether a 32-bit application can effectively manage memory amounts exceeding address space limits.</p>
<p>Back in 80386 times, the systems could address megabytes of RAM in 16-bit code through <a href="http://en.wikipedia.org/wiki/EXtended_Memory_Specification#eXtended_Memory_Specification_.28XMS.29">XMS</a> and <a href="http://en.wikipedia.org/wiki/Expanded_memory">EMS</a> services. The application could access &#8220;high&#8221; memory addresses by requesting mapping portions of RAM into lower megabyte address space. In some way similar technique is also here for 32-bit applications in Windows through use of <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa366556%28v=vs.85%29.aspx">file mappings</a>.</p>
<p>A regular memory backed file mapping requests Windows to reserve a memory block which becomes available for mapping into address space of one or more processes. Creating file mapping itself does not imply mapping and this leaves a great option for the owner to allocate more data than it can actually map into address space: if 32-bit process virtual address space is fundamentally constrained, the file mapping allocation space is more loosely limited by amount of physical memory and paging file. The application can allocate 2, 3, 4 and more gigabytes of memory &#8211; it just cannot still map it all together into address space and make it available simultaneously.</p>
<p>The FileMappingVirtualAddress utility does a simple thing:</p>
<ul>
<li>on startup it allocates (<a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa366537%28v=VS.85%29.aspx">CreateFileMapping</a>) as many 256 MB file mappings as operating system would allow, and shows it in a list</li>
<li>each time a user checks a box, the application maps (<a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa366761%28v=vs.85%29.aspx">MapViewOfFile</a>) corresponding file mapping into address space; unchecking a box unmaps the view</li>
<li>the caption shows currently used and maximal available virtual address space</li>
</ul>
<p><img class="alignnone size-full wp-image-1326" title="Allocated and Mapped 256 MB File Mappings" src="http://alax.info/blog/wp-content/uploads/2011/12/Image001.png" alt="" width="462" height="426" /></p>
<p>A plain 32-bit version of the application allocated 51 blocks for me (which totals in 13 GB of memory, with 8 GB physical RAM installed in the system). The allocation takes place immediately because the operating system does not actually make all this memory prepared for use &#8211; the actual pages would be allocated and ready to use on demand when the application requires them.</p>
<p><strong>The most important part made so obvious is that the 32-bit application succeeds in allocating well over 4 GB, which is maximal virtual address space it can ever get.</strong></p>
<p>The virtual address space in use is only 1641 MB and another request to map an additional section with <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa366761%28v=vs.85%29.aspx">MapViewOfFile</a> would fail (the default address space limit is 2 GB) &#8211; space fragmentation make mapping unavailable earlier than we actually use the whole space, since the API would need to allocate contiguous range of addresses to satisfy the request.</p>
<p><img class="alignnone size-full wp-image-1327" title="Error Hitting Virtual Address Space Limit" src="http://alax.info/blog/wp-content/uploads/2011/12/Image002.png" alt="" width="426" height="171" /></p>
<p>32-bit application built with <a href="http://msdn.microsoft.com/en-us/library/wz223b1z%28v=VS.100%29.aspx">/LARGEADDRESSAWARE</a> parameter might manage to do more allocations: 64-bit versions of Windows provide 4 GB of addresses to 32-bit processes. 32-bit operating systems might also be extending the limit in case of <a href="http://support.microsoft.com/kb/291988">4GB RAM Tuning</a> (which would typically be 3 GB of space for a process).</p>
<p><img class="alignnone size-full wp-image-1328" title="File Mappings with /LARGEADDRESSAWARE" src="http://alax.info/blog/wp-content/uploads/2011/12/Image003.png" alt="" width="462" height="426" /></p>
<p>Finally, 64-bit build of the application is free from virtual address space limit as the limit is <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa384271%28v=VS.85%29.aspx">8 terabytes</a>. The mapping is again instantaneous because actual RAM will be supplied on first request to mapped pages only.</p>
<p><img class="alignnone size-full wp-image-1329" title="File Mappings in 64-bit Code" src="http://alax.info/blog/wp-content/uploads/2011/12/Image004.png" alt="" width="462" height="426" /></p>
<p>A binary [<a href="http://www.alax.info/svn/public/trunk/Utilities/FileMappingVirtualAddress/Win32/Release/FileMappingVirtualAddress.exe">Win32</a>, <a href="http://www.alax.info/svn/public/trunk/Utilities/FileMappingVirtualAddress/Win32/Release%20with%20Large%20Address%20Aware/FileMappingVirtualAddress.exe">Win32 with /LARGEADDRESSAWARE</a>, <a href="http://www.alax.info/svn/public/trunk/Utilities/FileMappingVirtualAddress/x64/Release/FileMappingVirtualAddress.exe">x64</a>] and partial Visual C++ .NET 2010 <a href="http://www.alax.info/trac/public/browser/trunk/Utilities/FileMappingVirtualAddress">partial source code</a> are available from SVN.</p>
]]></content:encoded>
			<wfw:commentRss>http://alax.info/blog/1325/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>DirectShow SDK at Crime Scene Investigation Service</title>
		<link>http://alax.info/blog/1322</link>
		<comments>http://alax.info/blog/1322#comments</comments>
		<pubDate>Sun, 27 Nov 2011 11:03:46 +0000</pubDate>
		<dc:creator>Roman</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[Video]]></category>
		<category><![CDATA[amusing]]></category>
		<category><![CDATA[DirectShow]]></category>

		<guid isPermaLink="false">http://alax.info/blog/?p=1322</guid>
		<description><![CDATA[According to CSI: Crime Scene Investigation, Season 06 Episode 13 (17:04), investigators are using snake scope camera with DirectShow AMCAP tool to present the captured image:]]></description>
			<content:encoded><![CDATA[<p>According to <em>CSI: Crime Scene Investigation</em>, Season 06 Episode 13 (17:04), investigators are using snake scope camera with <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/dd373424%28v=vs.85%29.aspx">DirectShow AMCAP</a> tool to present the captured image:</p>
<p><img class="alignnone size-full wp-image-1323" title="AmCap and CSI" src="http://alax.info/blog/wp-content/uploads/2011/11/csi.s06e13.rus_.eng_.dvdrip.novafilm.tv_.avi_snapshot_17.04_2011.11.27_12.57.05-2.jpg" alt="" width="624" height="352" /></p>
]]></content:encoded>
			<wfw:commentRss>http://alax.info/blog/1322/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hardware assisted memory corruption detection</title>
		<link>http://alax.info/blog/1319</link>
		<comments>http://alax.info/blog/1319#comments</comments>
		<pubDate>Sat, 19 Nov 2011 17:26:25 +0000</pubDate>
		<dc:creator>Roman</dc:creator>
				<category><![CDATA[ATL]]></category>
		<category><![CDATA[Seriously]]></category>
		<category><![CDATA[Source]]></category>
		<category><![CDATA[corruption]]></category>
		<category><![CDATA[debug]]></category>
		<category><![CDATA[detection]]></category>
		<category><![CDATA[exception]]></category>
		<category><![CDATA[hardware]]></category>
		<category><![CDATA[memory]]></category>
		<category><![CDATA[protection]]></category>

		<guid isPermaLink="false">http://alax.info/blog/?p=1319</guid>
		<description><![CDATA[So you got a memory corruption issue with a piece of software. It comes in a unique scenario along the line of having a huge pile of weird code running well most of the time and then, right out of &#8230;<p class="read-more"><a href="http://alax.info/blog/1319">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<p>So you got a memory corruption issue with a piece of software. It comes in a unique scenario along the line of having a huge pile of weird code running well most of the time and then, right out of the blue, a corruption takes place followed by unexpected code execution and unstable software state in general.</p>
<p>The biggest problem with memory corruption is that a fragment of code is modifying a memory block which it does not own, and it has no idea who actually is the owner of the block, while the real owner has no timely way to detect the modification. You only face the consequences being unable to capture the modification moment in first place.</p>
<p>To get back to the original cause, an engineer has to drop into a time machine, turn back time and step back to where the trouble took originally place. As developers are not actually given state-of-the-art time machines, the time turning step is speculative.</p>
<h4>CVirtualHeapPtr Class: Memory with Exception-on-Write access mode</h4>
<p>At the same time a Windows platform developer is or might be aware of <a href="http://msdn.microsoft.com/en-us/library/ms810627.aspx">virtual memory API</a> which among other things provides user mode application with capabilities to define memory protection modes. Having this on hands opens unique opportunity to apply read-only protection (PAGE_READONLY) onto a memory block and have exception raised at the very moment of unexpected memory modification, having call stack showing up a source of the problem. I refer to this mode of operation as &#8220;hardware assisted&#8221; because the access violation exception/condition would be generated purely in hardware without any need to additionally do any address comparison in code.</p>
<p>Needless to say that this way is completely convenient for the developer as he does not need to patch the monstrous application all around in order to compare access addresses against read-only fragment. Instead, a block defined as read-only will be immediately available as such for the whole process almost without any performance overhead.</p>
<p>As ATL provides a set of memory allocator templates (<a href="http://msdn.microsoft.com/en-us/library/3by29yh0%28v=vs.80%29.aspx">CHeapPtr</a> for heap backed memory blocks, allocated with <em>CCRTAllocator</em>, alternate options include <a href="http://msdn.microsoft.com/en-us/library/80zw33a6%28v=vs.80%29.aspx">CComHeapPtr</a> with <em>CComAllocator</em> wrapping <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms692727%28v=vs.85%29.aspx">CoTaskMemAlloc</a>/<em>CoTaskMemFree</em> API), let us make an alternate allocator option that mimic well-known class interface and would facilitate corruption detection.</p>
<p>Because virtual memory allocation unit is a page, and protection mode is defined for the whole page, this would be the allocation granularity. For a single allocated byte we would need to request <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms724958%28v=vs.85%29.aspx">SYSTEM_INFO::dwPageSize</a> bytes of virtual memory. Unlike normal memory heap manager, we have no way to share pages between allocations as we would be unable to effectively apply protection modes. This would definitely increase application pressure onto virtual memory, but is still acceptable for the sacred task of troubleshooting.</p>
<p>We define a <em>CVirtualAllocator</em> class to be compatible with ATL&#8217;s <em>CCRTAllocator</em>, however based on <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa366887%28v=vs.85%29.aspx">VirtualAlloc</a>/<em>VirtualFree</em> API. The smart pointer class over memory pointer would be defined as follows:</p>
<pre style="color: #000000; background: #ffffff;"><span style="color: #800000; font-weight: bold;">template</span> <span style="color: #800080;">&lt;</span><span style="color: #800000; font-weight: bold;">typename</span> T<span style="color: #800080;">&gt;</span>
<span style="color: #800000; font-weight: bold;">class</span> CVirtualHeapPtr <span style="color: #800080;">:</span>
    <span style="color: #800000; font-weight: bold;">public</span> CHeapPtr<span style="color: #800080;">&lt;</span>T<span style="color: #808030;">,</span> CVirtualAllocator<span style="color: #800080;">&gt;</span>
<span style="color: #800080;">{</span>
<span style="color: #800000; font-weight: bold;">public</span><span style="color: #e34adc;">:</span>
<span style="color: #696969;">// CVirtualHeapPtr</span>
    CVirtualHeapPtr<span style="color: #808030;">(</span><span style="color: #808030;">)</span> <span style="color: #800000; font-weight: bold;">throw</span><span style="color: #808030;">(</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span>
    <span style="color: #800000; font-weight: bold;">explicit</span> CVirtualHeapPtr<span style="color: #808030;">(</span>_In_ T<span style="color: #808030;">*</span> pData<span style="color: #808030;">)</span> <span style="color: #800000; font-weight: bold;">throw</span><span style="color: #808030;">(</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span>
    <span style="color: #603000;">VOID</span> SetProtection<span style="color: #808030;">(</span><span style="color: #603000;">DWORD</span> nProtection<span style="color: #808030;">)</span>
    <span style="color: #800080;">{</span>
        <span style="color: #696969;">// </span><span style="color: #ffffff; background: #808000;">TODO: ...</span>
    <span style="color: #800080;">}</span>
<span style="color: #800080;">}</span><span style="color: #800080;">;</span></pre>
<p>The <em>SetProtection</em> method is to define memory protection for the memory block. Full code for the classes <a href="http://www.alax.info/trac/public/browser/trunk/Utilities/VirtualHeapPtr/VirtualHeapPtr.h#L9">is available on Trac here</a> (lines 9-132):</p>
<ul>
<li><em>CGlobalVirtualAllocator</em> class is a singleton querying operating system for virtual memory page size, and provides alignment method</li>
<li><em>CVirtualAllocator</em> class is a <em>CCRTAllocator</em>-compatible allocator class</li>
<li><em>CVirtualHeapPtr</em> class is smart template class wrapping a pointer to allocated memory</li>
</ul>
<p>Use case code will be as follows. &#8220;SetProtection(PAGE_READONLY)&#8221; enables protection on memory block and turns on exception generation at the moment memory block modification attempt. &#8220;SetProtection(PAGE_READWRITE)&#8221; would restore normal mode of memory operation.</p>
<pre style="color: #000000; background: #ffffff;">CVirtualHeapPtr<span style="color: #800080;">&lt;</span><span style="color: #603000;">BYTE</span><span style="color: #800080;">&gt;</span> p<span style="color: #800080;">;</span>
p<span style="color: #808030;">.</span>Allocate<span style="color: #808030;">(</span><span style="color: #008c00;">2</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span>
p<span style="color: #808030;">[</span><span style="color: #008c00;">1</span><span style="color: #808030;">]</span> <span style="color: #808030;">=</span> <span style="color: #008000;">0x01</span><span style="color: #800080;">;</span>
p<span style="color: #808030;">.</span>SetProtection<span style="color: #808030;">(</span>PAGE_READONLY<span style="color: #808030;">)</span><span style="color: #800080;">;</span>
<span style="color: #696969;">// NOTE: Compile with /EHa on order to catch the exception</span>
_ATLTRY
<span style="color: #800080;">{</span>
    p<span style="color: #808030;">[</span><span style="color: #008c00;">1</span><span style="color: #808030;">]</span> <span style="color: #808030;">=</span> <span style="color: #008000;">0x02</span><span style="color: #800080;">;</span>
    <span style="color: #696969;">// NOTE: We never reach here due to exception</span>
<span style="color: #800080;">}</span>
_ATLCATCHALL<span style="color: #808030;">(</span><span style="color: #808030;">)</span>
<span style="color: #800080;">{</span>
    <span style="color: #696969;">// NOTE: Catching the access violation for now to be able to continue execution</span>
<span style="color: #800080;">}</span>
p<span style="color: #808030;">.</span>SetProtection<span style="color: #808030;">(</span>PAGE_READWRITE<span style="color: #808030;">)</span><span style="color: #800080;">;</span>
p<span style="color: #808030;">[</span><span style="color: #008c00;">1</span><span style="color: #808030;">]</span> <span style="color: #808030;">=</span> <span style="color: #008000;">0x03</span><span style="color: #800080;">;</span></pre>
<p>Given the information what data gets corrupt, the pointer allocator provides an efficient opportunity to detect the violation attempt. The only thing remained is to keep memory read-only, and temporarily revert to write access when the &#8220;legal&#8221; memory modification code is about to be executed.</p>
<p><span id="more-1319"></span></p>
<h5>One-shot Read/Write Protection with Guard Pages</h5>
<p>Another option granted by memory protection modes is brought by PAGE_GUARD flag. MSDN says:</p>
<blockquote><p>A guard page provides a one-shot alarm for memory page access. This can be useful for an application that needs to monitor the growth of large dynamic data structures. For example, there are operating systems that use guard pages to implement automatic stack checking.</p></blockquote>
<p>Setting a guard page mode provides an additional option to trigger an exception with even read access to a protected memory block.</p>
<pre style="color: #000000; background: #ffffff;">p<span style="color: #808030;">.</span>SetProtection<span style="color: #808030;">(</span>PAGE_READWRITE <span style="color: #808030;">|</span> PAGE_GUARD<span style="color: #808030;">)</span><span style="color: #800080;">;</span>
<span style="color: #603000;">BYTE</span> n <span style="color: #808030;">=</span> p<span style="color: #808030;">[</span><span style="color: #008c00;">0</span><span style="color: #808030;">]</span><span style="color: #800080;">;</span></pre>
<h4>CDebugHeapPtr Class: More Options to Catch Memory Corruption Conditions</h4>
<p>While setting memory protection attributes on a memory block of interest provides unique troubleshooting opportunities, it still does not cover important typical problems with memory misuse scenarios. Those are writing immediately before the allocated block, and writing immediately after. Having array of N items, this would be writing to indices -1 and N respectively.</p>
<p>To address this scenarios of misuse we can extend CVirtualHeapPtr class so that it could additionally provide &#8220;sanity pages&#8221; with PAGE_NOACCESS protection at the boundary of allocation. Because virtual memory allocation is granular, we will have to have padding bytes that extend our block to the page boundary, however we have an option to put the padding bytes before or after the payload data block in order to capture after or before memory block writes respectively.</p>
<p>The figure below shows memory layout for the data:</p>
<p><img class="alignnone size-full wp-image-1320" title="CDebugHeapPtr Memory Layout" src="http://alax.info/blog/wp-content/uploads/2011/11/image.png" alt="" width="509" height="541" /></p>
<p>Source code for the <em>CDebugHeapPtr</em> class <a href="http://www.alax.info/trac/public/browser/trunk/Utilities/VirtualHeapPtr/VirtualHeapPtr.h#L155">is available on Trac</a> (lines 155-). The sanity pages create a block of inaccessible addresses which immediately cause access violation exception on either read of write access attempt. Under debugger, those are shows with question marks:</p>
<p><img class="alignnone size-full wp-image-1321" title="PAGE_NOACCESS Data" src="http://alax.info/blog/wp-content/uploads/2011/11/Image0011.png" alt="" width="673" height="288" /></p>
<p>The padding space is pre-initialized with hardcoded value 0&#215;77, and the space is checked for integrity at release of memory block call.</p>
<h4>Catching the Exceptions</h4>
<p>Having the exceptions generated on run-time, they immediately alter application execution code path and are easy to track and catch. There is no need to bring the feature rich debugger, such as Visual Studio to the production site in order to catch the exception and environment, instead a way simpler tool such as <a href="http://alax.info/blog/1248">LogProcessExceptions</a> would be able to create a minidump file and write the state of the application. The minidump can be transferred into debugger-enabled environment for detailed check.</p>
<p>Visual C++ .NET 2010 <a href="http://www.alax.info/trac/public/browser/trunk/Utilities/VirtualHeapPtr">source code</a> is available from SVN.</p>
]]></content:encoded>
			<wfw:commentRss>http://alax.info/blog/1319/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>GPS Location/Coordinate Converter: Multiple Locations at Once</title>
		<link>http://alax.info/blog/1313</link>
		<comments>http://alax.info/blog/1313#comments</comments>
		<pubDate>Mon, 14 Nov 2011 18:06:26 +0000</pubDate>
		<dc:creator>Roman</dc:creator>
				<category><![CDATA[ATL]]></category>
		<category><![CDATA[Source]]></category>
		<category><![CDATA[Utilities]]></category>
		<category><![CDATA[WTL]]></category>
		<category><![CDATA[gps]]></category>
		<category><![CDATA[rally]]></category>
		<category><![CDATA[utility]]></category>

		<guid isPermaLink="false">http://alax.info/blog/?p=1313</guid>
		<description><![CDATA[Today&#8217;s update lets you convert multiple locations at once with a single click. Here is the story behind the update and use case scenario. In rally raid sport events (so called baja), a team gets a road book for the &#8230;<p class="read-more"><a href="http://alax.info/blog/1313">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<p>Today&#8217;s update lets you convert multiple locations at once with a single click. Here is the story behind the update and use case scenario.</p>
<p>In <a href="http://en.wikipedia.org/wiki/Rally_raid">rally raid</a> sport events (so called <em>baja</em>), a team gets a road book for the next competition day in a few hours before actual start. The GPS coordinates are printed on one of the pages of the roadbook and are not available in any electronic format.</p>
<p>There were just a few times when the organizer also uploaded a copy of a file with the coordinates and shared a link to download from, but this was rather an exception. Another alternate option was a dedicated person to upload the coordinates (they were earlier full tracks, but at some point tracks were no longer available at all) to pilots&#8217; hardware, but in a state of pre-start рфыеу and variety of GPS hardware, formats, cable etc. this created lines of people. The most one can rely on is a sheet of paper with GPS coordinates. The mistery does not end even here as you don&#8217;t know whether you are to get Degrees only, or Degrees and Minutes, or Degrees, Minutes and Seconds. Everything depends on software the organizer uses.</p>
<p><img class="alignnone size-full wp-image-1314" title="A Page with GPS Locations in Road Book " src="http://alax.info/blog/wp-content/uploads/2011/11/Scan1.jpg" alt="" width="480" height="307" /></p>
<p>As soon as you get a hard copy of this, the idea is to upload it into device as quickly as possible because there are other things to do and the time is normally 11 PM when the race is to start 7 AM next day tens of miles away from you. The time interval will be shared by uploading data, sleeping and transfer to start location.</p>
<p>The utility is here to grant extra sleep time. Since it is capable to accept various separators on the input, a convenient way is to quickly type in the text in Microsoft Excel, check the data against the hardcopy, and copy into clipboard to transfer to the utility.</p>
<p><img class="alignnone size-full wp-image-1315" title="GPS Coordinates in Microsoft Excel" src="http://alax.info/blog/wp-content/uploads/2011/11/Image001.png" alt="" width="558" height="472" /></p>
<p>A hotkey with conversion transfers data into format of interest, and single &#8220;Find and Replace&#8221; operation creates a good OziExplorer waypoint file which is good for upload onto portable navigation device.<img class="alignnone size-large wp-image-1316" title="Visual Studio with OziExplorer Waypoint Data" src="http://alax.info/blog/wp-content/uploads/2011/11/Image002-687x600.png" alt="" width="620" height="541" /></p>
<p>The whole thing take a few minutes to do with minimal routine typing in.</p>
<p>A binary [<a href="http://www.alax.info/svn/public/trunk/Utilities/GpsLocationConverter/_Bin/Release/GpsLocationConverter.exe">Win32</a>] and partial Visual C++ .NET 2010 <a href="http://www.alax.info/trac/public/browser/trunk/Utilities/GpsLocationConverter">partial source code</a> are available from SVN.</p>
<p>Bonus picture, rally raid Suzuki is on the way to score the victory and the rally promotional teaser:</p>
<p><a href="https://picasaweb.google.com/105209331201471192155/BajaPolygon4thRoundOfUkrainianCup2011InRallyRaidsNearNovomoskovskUkraine"><img class="alignnone" src="https://lh6.googleusercontent.com/--53JPr3B2Hw/TsD_WnIrE9I/AAAAAAAAFXo/PjmYMfS_WJI/s640/DSC04127a.jpg" alt="Rally Raid Suzuki Samurai on the Way" width="640" height="426" /></a></p>
<p><object width="640" height="360"><param name="movie" value="http://www.youtube.com/v/k-_-Re2PhQ8&#038;rel=0&#038;hl=en_US&#038;feature=player_embedded&#038;version=3"></param><param name="allowFullScreen" value="true"></param><param name="allowScriptAccess" value="always"></param><embed src="http://www.youtube.com/v/k-_-Re2PhQ8&#038;rel=0&#038;hl=en_US&#038;feature=player_embedded&#038;version=3" type="application/x-shockwave-flash" allowfullscreen="true" allowScriptAccess="always" width="640" height="360"></embed></object></p>
]]></content:encoded>
			<wfw:commentRss>http://alax.info/blog/1313/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Common Controls: Versions, Compatibility, WTL</title>
		<link>http://alax.info/blog/1306</link>
		<comments>http://alax.info/blog/1306#comments</comments>
		<pubDate>Sun, 30 Oct 2011 19:55:52 +0000</pubDate>
		<dc:creator>Roman</dc:creator>
				<category><![CDATA[WTL]]></category>
		<category><![CDATA[bug]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[compatibility]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://alax.info/blog/?p=1306</guid>
		<description><![CDATA[An application appears to be not working in Windows XP in a weird way: rebar control appeared to fail showing up. Where the application is expected to look much nicer with rebar control as a container for menu (implemented as &#8230;<p class="read-more"><a href="http://alax.info/blog/1306">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<p>An application appears to be not working in Windows XP in a weird way: <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/bb774373%28v=vs.85%29.aspx">rebar control</a> appeared to fail showing up.</p>
<p><img class="alignnone size-full wp-image-1310" title="Rebar Failed" src="http://alax.info/blog/wp-content/uploads/2011/10/Image003.png" alt="" width="640" height="238" /></p>
<p>Where the application is expected to look much nicer with rebar control as a container for menu (implemented as command bar WTL control) and toolbar with buttons:</p>
<p><img class="alignnone size-full wp-image-1309" title="Rebar Succeeded" src="http://alax.info/blog/wp-content/uploads/2011/10/Image0022.png" alt="" width="640" height="238" /></p>
<p>A WTL sample project generated by a Visual Studio wizard would never give such effect, and the bug was a combination of factors:</p>
<ol>
<li>An application built with a newer version of Windows SDK, which includes support for features (Windows Vista+ Common Controls) that are more recent than production environment (Windows XP); the application targets to Windows Vista+ environment too (<em>_WIN32_WINNT</em> &gt;= <em>0&#215;0600</em>)</li>
<li>Compatibility issues of Common Controls library</li>
<li>WTL version (7.5), which did not yet include a workaround for the problem</li>
</ol>
<p>The problem, which caused the bug directly was the <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/bb774393%28v=vs.85%29.aspx">REBARBANDINFO structure</a> and its use as an argument with Common Controls API. As MSDN shows, the structure was amended twice with additional fields.</p>
<p>One of the way to support multiple versions of the structure definition, and to resolve compatibility issues, is to embed structure size into structure payload. In fact, <em>REBARBANDINFO::cbSize</em> member is there exactly for this reason.</p>
<p>The application is normally filling <em>cbSize</em> with the maximal known structure size and fills the rest of the fields respectively. The API is expected to be checking <em>cbSize</em> member and be detecting API version compatibility scenarios:</p>
<ol>
<li><em>cbSize</em> holds exactly the value the API expects (that is, the maximal value known/defined to the API) &#8211; the simplest scenario where the API and the application are on the same page, both are using the same versions of the &#8220;protocol&#8221;/interface.</li>
<li><em>cbSize</em> is smaller than API can support &#8211; the API sees that it is dealing with a sort of legacy application which cannot utilize all available features, and the API acts respectively supporting the older part of the protocol, and keeping defaults or &#8220;old look&#8221; for the rest of implementation. This addresses backward compatibility: the newer API works with apps designed for older version of the API</li>
<li><em>cbSize</em> is greater then API can support &#8211; the API sees that the application is already aware of newer version API and is possibly requesting some of the missing features. The API might be ignoring the unsupported part in assumption that API evolution tool place keeping some compatibility in mind, and still do the best it can with the existing implementation. Or, the API might just fail to work.</li>
</ol>
<p>The latter item #3 is the scenario here with rebar control. The application is using Windows Vista version of <em>REBARBANDINFO</em> structure and Windows XP implementation choses to completely fail.</p>
<p>While it does not seem to be directly a bug, this attitude is definitely not developer friendly: there is no reason for the control to not work in its best and default way. Having API acting this way, each developer using the API needs to take care of the situation explicitly: whenever Windows Vista enabled application needs to be able to run in Windows XP system, the code around <em>REBARBANDINFO</em> would look like this:</p>
<pre style="color: #000000; background: #ffffff;">REBARBANDINFO BandInformation <span style="color: #808030;">=</span> <span style="color: #800080;">{</span> <span style="color: #800000; font-weight: bold;">sizeof</span> BandInformation<span style="color: #808030;">,</span> RBBIM_LPARAM <span style="color: #800080;">}</span><span style="color: #800080;">;</span>
<span style="color: #004a43;">#</span><span style="color: #004a43;">if</span><span style="color: #004a43;"> _WIN32_WINNT </span><span style="color: #808030;">&gt;</span><span style="color: #808030;">=</span><span style="color: #004a43;"> 0x0600</span>
<span style="color: #800000; font-weight: bold;">if</span><span style="color: #808030;">(</span>GetOsVersion<span style="color: #808030;">(</span><span style="color: #808030;">)</span> <span style="color: #808030;">&lt;</span> <span style="color: #008000;">0x00060000</span> <span style="color: #808030;">|</span><span style="color: #808030;">|</span> GetCommCtrlVersion<span style="color: #808030;">(</span><span style="color: #808030;">)</span> <span style="color: #808030;">&lt;</span> <span style="color: #008000;">0x00060000</span><span style="color: #808030;">)</span> <span style="color: #696969;">// pre-Vista, Common Controls pre-6.0</span>
    BandInformation<span style="color: #808030;">.</span>cbSize <span style="color: #808030;">=</span> REBARBANDINFO_V6_SIZE<span style="color: #800080;">;</span>
<span style="color: #004a43;">#</span><span style="color: #004a43;">endif</span><span style="color: #696969;">// _WIN32_WINNT &gt;= 0x0600</span>
<span style="color: #800000; font-weight: bold;">const</span> <span style="color: #603000;">BOOL</span> bGetBandInfoResult <span style="color: #808030;">=</span> Rebar<span style="color: #808030;">.</span>GetBandInfo<span style="color: #808030;">(</span><span style="color: #008c00;">0</span><span style="color: #808030;">,</span> <span style="color: #808030;">&amp;</span>BandInformation<span style="color: #808030;">)</span><span style="color: #800080;">;</span></pre>
<p>If the API was nicer to developers, the code would be plain and simple:</p>
<pre style="color: #000000; background: #ffffff;">REBARBANDINFO BandInformation <span style="color: #808030;">=</span> <span style="color: #800080;">{</span> <span style="color: #800000; font-weight: bold;">sizeof</span> BandInformation<span style="color: #808030;">,</span> RBBIM_LPARAM <span style="color: #800080;">}</span><span style="color: #800080;">;</span>
<span style="color: #800000; font-weight: bold;">const</span> <span style="color: #603000;">BOOL</span> bGetBandInfoResult <span style="color: #808030;">=</span> Rebar<span style="color: #808030;">.</span>GetBandInfo<span style="color: #808030;">(</span><span style="color: #008c00;">0</span><span style="color: #808030;">,</span> <span style="color: #808030;">&amp;</span>BandInformation<span style="color: #808030;">)</span><span style="color: #800080;">;</span></pre>
<p>To address this problem, <a href="http://wtl.sourceforge.net/">WTL</a> 8.0 comes up with <em>RunTimeHelper</em> namespace and its <em>SizeOf_REBARBANDINFO</em> function. It takes care of details for the developer choosing the proper size of the structure on runtime. The code is being taken back to a simpler shape:</p>
<pre style="color: #000000; background: #ffffff;">REBARBANDINFO BandInformation <span style="color: #808030;">=</span> <span style="color: #800080;">{</span> RunTimeHelper<span style="color: #800080;">::</span>SizeOf_REBARBANDINFO<span style="color: #808030;">(</span><span style="color: #808030;">)</span><span style="color: #808030;">,</span> RBBIM_LPARAM <span style="color: #800080;">}</span><span style="color: #800080;">;</span>
<span style="color: #800000; font-weight: bold;">const</span> <span style="color: #603000;">BOOL</span> bGetBandInfoResult <span style="color: #808030;">=</span> Rebar<span style="color: #808030;">.</span>GetBandInfo<span style="color: #808030;">(</span><span style="color: #008c00;">0</span><span style="color: #808030;">,</span> <span style="color: #808030;">&amp;</span>BandInformation<span style="color: #808030;">)</span><span style="color: #800080;">;</span></pre>
<p>All in all:</p>
<ul>
<li>be aware of compatibility issues (same scenario exists with other SDK structures: <em>LVGROUP</em>, <em>LVTILEINFO</em>, <em>MCHITTESTINFO</em>, <em>NONCLIENTMETRICS</em> and other).</li>
<li>use latest version of WTL to have things worked around for you where Microsoft developers were not kid enough to provide perfect API</li>
<li>be aware and take advantage of WTL&#8217;s <em>RunTimeHelper</em> class</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://alax.info/blog/1306/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>GPS Location/Coordinate Converter: Fractional Seconds, More Shortcuts</title>
		<link>http://alax.info/blog/1302</link>
		<comments>http://alax.info/blog/1302#comments</comments>
		<pubDate>Thu, 20 Oct 2011 17:48:42 +0000</pubDate>
		<dc:creator>Roman</dc:creator>
				<category><![CDATA[ATL]]></category>
		<category><![CDATA[Source]]></category>
		<category><![CDATA[Utilities]]></category>
		<category><![CDATA[WTL]]></category>
		<category><![CDATA[coordinate]]></category>
		<category><![CDATA[geolocation]]></category>
		<category><![CDATA[gps]]></category>
		<category><![CDATA[map]]></category>
		<category><![CDATA[tool]]></category>
		<category><![CDATA[utility]]></category>

		<guid isPermaLink="false">http://alax.info/blog/?p=1302</guid>
		<description><![CDATA[This adds a small update to the recently published GPS Location/Coordinate Converter utility: Seconds in Degrees, Minutes &#38; Seconds notation are shown and are accepted as floating point numbers More shortcuts to popular online map services (note that only Google &#8230;<p class="read-more"><a href="http://alax.info/blog/1302">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<p>This adds a small update to the recently published <a title="Permalink to Utility Clearance: GPS Location/Coordinate Converter" href="../1297">GPS Location/Coordinate Converter</a> utility:</p>
<ul>
<li>Seconds in <em>Degrees, Minutes &amp; Seconds</em> notation are shown and are accepted as floating point numbers</li>
<li>More shortcuts to popular online map services (note that only Google Maps and Yandex Maps are still accepted as input via clipboard):</li>
<ul>
<li style="text-align: left;">Bing Maps</li>
<li style="text-align: left;">Yahoo Maps</li>
<li style="text-align: left;">Open Street Map</li>
<li style="text-align: left;">WikiMapia</li>
</ul>
</ul>
<p>The latter makes the tool an easy to use converted between the services for a GPS POI.</p>
<p><a href="http://alax.info/blog/wp-content/uploads/2011/10/Image0011.png"><img class="alignnone size-large wp-image-1303" title="GPS Location Converter" src="http://alax.info/blog/wp-content/uploads/2011/10/Image0011-800x316.png" alt="" width="620" height="244" /></a></p>
<p>A binary [<a href="http://www.alax.info/svn/public/trunk/Utilities/GpsLocationConverter/_Bin/Release/GpsLocationConverter.exe">Win32</a>] and partial Visual C++ .NET 2010 <a href="http://www.alax.info/trac/public/browser/trunk/Utilities/GpsLocationConverter">partial source code</a> are available from SVN.</p>
]]></content:encoded>
			<wfw:commentRss>http://alax.info/blog/1302/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Utility Clearance: GPS Location/Coordinate Converter</title>
		<link>http://alax.info/blog/1297</link>
		<comments>http://alax.info/blog/1297#comments</comments>
		<pubDate>Wed, 12 Oct 2011 21:20:40 +0000</pubDate>
		<dc:creator>Roman</dc:creator>
				<category><![CDATA[ATL]]></category>
		<category><![CDATA[Source]]></category>
		<category><![CDATA[Utilities]]></category>
		<category><![CDATA[WTL]]></category>
		<category><![CDATA[coordinate]]></category>
		<category><![CDATA[geolocation]]></category>
		<category><![CDATA[gps]]></category>
		<category><![CDATA[map]]></category>
		<category><![CDATA[tool]]></category>
		<category><![CDATA[utility]]></category>

		<guid isPermaLink="false">http://alax.info/blog/?p=1297</guid>
		<description><![CDATA[This tool came up as a result of mess around GPS coordinate formatting and variety of popular formats and notations. Some use latitude and longitude degrees, some prefer degrees and minutes with fractional part. this does not take into account &#8230;<p class="read-more"><a href="http://alax.info/blog/1297">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<p>This tool came up as a result of mess around GPS coordinate formatting and variety of popular formats and notations. Some use latitude and longitude degrees, some prefer degrees and minutes with fractional part. this does not take into account choices for datum and file formats.</p>
<p>For instance, both <a href="http://maps.google.com">Google Maps</a> and <a href="http://maps.yandex.ru">Yandex Maps</a> accept latitude and longitude as <strong>ll=</strong> URL parameter with the value of latitude and longitude in degrees, however Google uses latitude coming first, while Yandex prefers the opposite.</p>
<p>Recently, a rally road book contained the following formatting of track points:</p>
<p><a href="http://alax.info/blog/wp-content/uploads/2011/10/Image001.png"><img class="alignnone size-large wp-image-1298" title="Rally Raid Service Book" src="http://alax.info/blog/wp-content/uploads/2011/10/Image001-800x418.png" alt="" width="620" height="323" /></a></p>
<p>Having to put a stop to the madness, this utility comes up as a handy assistant to convert and format GPS coordinates into reasonable presentation and separators.</p>
<p>The utility runs on background and monitors clipboard, and once it recognizes one of the following:</p>
<ul>
<li>GPS Point in Degrees</li>
<li>GPS Point in Degrees and Minutes</li>
<li>GPS Point in Degrees, Minutes and Seconds</li>
<li>Google Maps URL</li>
<li>Yandex Maps URL</li>
</ul>
<p>it flashes and updates its UI providing the choices of track point formatting:</p>
<p><a href="http://alax.info/blog/wp-content/uploads/2011/10/Image0021.png"><img class="alignnone size-full wp-image-1299" title="GPS Point Formatting and Options" src="http://alax.info/blog/wp-content/uploads/2011/10/Image0021.png" alt="" width="778" height="248" /></a></p>
<p>The utility is trying hard to accept various separators and formats, just one thing is important to keep in mind: if you are using minutes without seconds, the fractional part of minutes should be separated by decimal point (.).</p>
<p>The utility also responds to hotkeys <em>Ctrl+Shift+F1</em>, <em>Ctrl+Shift+F2</em> etc. and copies the formatted point location back into clipboard so that one could quickly re-format editable text in another application through clipboard updates. Alternatively, it is possible to click the formatted value and place it into clipboard.</p>
<p>The utility also provides clickable hyperlinks to open Google Maps and Yandex Maps into the point of interest.</p>
<p>A binary [<a href="http://www.alax.info/svn/public/trunk/Utilities/GpsLocationConverter/_Bin/Release/GpsLocationConverter.exe">Win32</a>] and partial Visual C++ .NET 2010 <a href="http://www.alax.info/trac/public/browser/trunk/Utilities/GpsLocationConverter">partial source code</a> are available from SVN.</p>
<p>Note: you might need to run the tool &#8220;As Administrator&#8221; elevating UAC privileges in Vista/7 operating systems.</p>
<p>Bonus links on the topic:</p>
<ul>
<li><a href="http://boulter.com/gps/">GPS Coordinate Converter, Maps and Info</a></li>
<li><a href="http://www.benichou-software.com/index.php?option=com_content&amp;view=article&amp;id=4&amp;Itemid=2&amp;lang=en">ITN Converter</a> &#8211; converts for route file formats</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://alax.info/blog/1297/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>NTFS Links: x64 build</title>
		<link>http://alax.info/blog/1294</link>
		<comments>http://alax.info/blog/1294#comments</comments>
		<pubDate>Wed, 12 Oct 2011 19:37:43 +0000</pubDate>
		<dc:creator>Roman</dc:creator>
				<category><![CDATA[NTFS Links]]></category>
		<category><![CDATA[junction]]></category>
		<category><![CDATA[link]]></category>
		<category><![CDATA[ntfs]]></category>
		<category><![CDATA[tool]]></category>
		<category><![CDATA[utility]]></category>
		<category><![CDATA[x64]]></category>

		<guid isPermaLink="false">http://alax.info/blog/?p=1294</guid>
		<description><![CDATA[Per user request, here goes 64-bit version of NTFS Links utility, which provides shell UI for NTFS Junction Points. As 64-bit version of Windows operating systems provide two versions of shell explorer, and support both Win32 and x64 platform applications, &#8230;<p class="read-more"><a href="http://alax.info/blog/1294">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<p>Per user request, here goes 64-bit version of <a href="http://alax.info/blog/ntfslinks">NTFS Links</a> utility, which provides shell UI for <a href="http://en.wikipedia.org/wiki/NTFS_junction_point">NTFS Junction Points</a>.</p>
<p>As 64-bit version of Windows operating systems provide two versions of shell explorer, and support both <em>Win32</em> and <em>x64</em> platform applications, it is typical to install both 32-bit and 64-bit versions of the utility to cover/extend applications of both platforms. Note that 32-bit (Win32) applications can only load and directly interact with 32-bit builds of libraries (DLLs), so 64-bit (x64) applications need a corresponding matching version of the shell extension available.</p>
<p>As the utility provides a shell extension for directory property pages, here comes a curiosity exercise: how Windows 7 uses junction points to cross-map directories under user profile directory, e.g. <strong>C:\Users\&lt;username&gt;\Local Settings</strong> directory is actually a shortcut to <strong>C:\Users\&lt;username&gt;\AppData\Local</strong>.</p>
<p><img class="alignnone size-full wp-image-1296" title="User Profile Junction Points" src="http://alax.info/blog/wp-content/uploads/2011/10/Image002.png" alt="" width="377" height="505" /></p>
<p>Current version of Alax.Info NTFS Links can be downloaded from:</p>
<ul>
<li><a title="Download from http://alax.info/" href="http://www.alax.info/svn/public/trunk/NtfsLinks/AlaxInfoNtfsLinksSetup.msi" target="_blank">AlaxInfoNtfsLinksSetup.msi</a> – Version 1.1.5, 32-bit</li>
<li><a title="Download from http://alax.info/" href="http://www.alax.info/svn/public/trunk/NtfsLinks/AlaxInfoNtfsLinksSetup-x64.msi" target="_blank">AlaxInfoNtfsLinksSetup-x64.msi</a> – Version 1.1.5, 64-bit (x64)</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://alax.info/blog/1294/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sample: Simultaneous Audio Playback via Waveform Audio (waveOut) API</title>
		<link>http://alax.info/blog/1291</link>
		<comments>http://alax.info/blog/1291#comments</comments>
		<pubDate>Wed, 12 Oct 2011 17:15:50 +0000</pubDate>
		<dc:creator>Roman</dc:creator>
				<category><![CDATA[Audio]]></category>
		<category><![CDATA[Source]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[playback]]></category>
		<category><![CDATA[waveOut]]></category>

		<guid isPermaLink="false">http://alax.info/blog/?p=1291</guid>
		<description><![CDATA[The minimalistic sample demonstrates support of [deprecated] Waveform Audio API for multiple playback streams. Depending on command line parameters, the application starts threads to open audio hardware using separate waveOutOpen call and stream one or more generated sine waves: 1,000 &#8230;<p class="read-more"><a href="http://alax.info/blog/1291">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<p>The minimalistic sample demonstrates support of [deprecated] <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/dd757715%28v=VS.85%29.aspx">Waveform Audio API</a> for multiple playback streams.</p>
<p>Depending on command line parameters, the application starts threads to open audio hardware using separate <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/dd743866%28v=VS.85%29.aspx">waveOutOpen</a> call and stream one or more generated sine waves:</p>
<ul>
<li>1,000 Hz sine wave as 22,050 Hz, Mono, 16-bit PCM (command line parameter &#8220;a&#8221;)</li>
<li>5,000 Hz sine wave as 32,000 Hz, Mono, 16-bit PCM (command line parameter &#8220;b&#8221;)</li>
<li>15,000 Hz sine wave as 44,100 Hz, Mono, 16-bit PCM (command line parameter &#8220;c&#8221;)</li>
</ul>
<pre style="color: #000000; background: #ffffff;">Check<span style="color: #808030;">(</span><span style="color: #400000;">waveOutOpen</span><span style="color: #808030;">(</span><span style="color: #808030;">&amp;</span>hWaveOut<span style="color: #808030;">,</span> WAVE_MAPPER<span style="color: #808030;">,</span> <span style="color: #808030;">&amp;</span>WaveFormatEx<span style="color: #808030;">,</span> <span style="color: #7d0045;">NULL</span><span style="color: #808030;">,</span> <span style="color: #7d0045;">NULL</span><span style="color: #808030;">,</span> CALLBACK_NULL<span style="color: #808030;">)</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span>
ATLASSERT<span style="color: #808030;">(</span>hWaveOut<span style="color: #808030;">)</span><span style="color: #800080;">;</span>
WAVEHDR<span style="color: #808030;">*</span> pWaveHeader<span style="color: #800080;">;</span>
<span style="color: #603000;">HGLOBAL</span> hWaveHeader <span style="color: #808030;">=</span> <span style="color: #808030;">(</span>WAVEHDR<span style="color: #808030;">*</span><span style="color: #808030;">)</span> <span style="color: #400000;">GlobalAlloc</span><span style="color: #808030;">(</span>GMEM_MOVEABLE <span style="color: #808030;">|</span> GMEM_SHARE<span style="color: #808030;">,</span> <span style="color: #800000; font-weight: bold;">sizeof</span> <span style="color: #808030;">*</span>pWaveHeader <span style="color: #808030;">+</span> WaveFormatEx<span style="color: #808030;">.</span>nAvgBytesPerSec <span style="color: #808030;">*</span> <span style="color: #008c00;">10</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span>
pWaveHeader <span style="color: #808030;">=</span> <span style="color: #808030;">(</span>WAVEHDR<span style="color: #808030;">*</span><span style="color: #808030;">)</span> <span style="color: #400000;">GlobalLock</span><span style="color: #808030;">(</span>hWaveHeader<span style="color: #808030;">)</span><span style="color: #800080;">;</span>
ATLENSURE_THROW<span style="color: #808030;">(</span>pWaveHeader<span style="color: #808030;">,</span> E_OUTOFMEMORY<span style="color: #808030;">)</span><span style="color: #800080;">;</span>
pWaveHeader<span style="color: #808030;">-</span><span style="color: #808030;">&gt;</span>lpData <span style="color: #808030;">=</span> <span style="color: #808030;">(</span><span style="color: #603000;">LPSTR</span><span style="color: #808030;">)</span> <span style="color: #808030;">(</span><span style="color: #603000;">BYTE</span><span style="color: #808030;">*</span><span style="color: #808030;">)</span> <span style="color: #808030;">(</span>pWaveHeader <span style="color: #808030;">+</span> <span style="color: #008c00;">1</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span>
pWaveHeader<span style="color: #808030;">-</span><span style="color: #808030;">&gt;</span>dwBufferLength <span style="color: #808030;">=</span> WaveFormatEx<span style="color: #808030;">.</span>nAvgBytesPerSec <span style="color: #808030;">*</span> <span style="color: #008c00;">10</span><span style="color: #800080;">;</span>
<span style="color: #696969;">//pWaveHeader-&gt;dwUser = </span>
pWaveHeader<span style="color: #808030;">-</span><span style="color: #808030;">&gt;</span>dwFlags <span style="color: #808030;">=</span> <span style="color: #008c00;">0</span><span style="color: #800080;">;</span>
pWaveHeader<span style="color: #808030;">-</span><span style="color: #808030;">&gt;</span>dwLoops <span style="color: #808030;">=</span> <span style="color: #008c00;">0</span><span style="color: #800080;">;</span>
<span style="color: #004a43;">#</span><span style="color: #004a43; font-weight: bold;">pragma </span><span style="color: #bb7977; font-weight: bold;">region Generate Actual Data</span>
<span style="color: #800080;">{</span>
    <span style="color: #603000;">SHORT</span><span style="color: #808030;">*</span> pnData <span style="color: #808030;">=</span> <span style="color: #808030;">(</span><span style="color: #603000;">SHORT</span><span style="color: #808030;">*</span><span style="color: #808030;">)</span> pWaveHeader<span style="color: #808030;">-</span><span style="color: #808030;">&gt;</span>lpData<span style="color: #800080;">;</span>
    SIZE_T nDataCount <span style="color: #808030;">=</span> pWaveHeader<span style="color: #808030;">-</span><span style="color: #808030;">&gt;</span>dwBufferLength <span style="color: #808030;">/</span> <span style="color: #800000; font-weight: bold;">sizeof</span> <span style="color: #808030;">*</span>pnData<span style="color: #800080;">;</span>
    <span style="color: #800000; font-weight: bold;">for</span><span style="color: #808030;">(</span>SIZE_T nIndex <span style="color: #808030;">=</span> <span style="color: #008c00;">0</span><span style="color: #800080;">;</span> nIndex <span style="color: #808030;">&lt;</span> nDataCount<span style="color: #800080;">;</span> nIndex<span style="color: #808030;">+</span><span style="color: #808030;">+</span><span style="color: #808030;">)</span>
    pnData<span style="color: #808030;">[</span>nIndex<span style="color: #808030;">]</span> <span style="color: #808030;">=</span> <span style="color: #808030;">(</span><span style="color: #603000;">SHORT</span><span style="color: #808030;">)</span> <span style="color: #808030;">(</span><span style="color: #008c00;">32000</span> <span style="color: #808030;">*</span> <span style="color: #603000;">sin</span><span style="color: #808030;">(</span><span style="color: #008000;">1.0</span> <span style="color: #808030;">*</span> nIndex <span style="color: #808030;">/</span> WaveFormatEx<span style="color: #808030;">.</span>nSamplesPerSec <span style="color: #808030;">*</span> nFrequency <span style="color: #808030;">*</span> <span style="color: #008c00;">2</span> <span style="color: #808030;">*</span> M_PI<span style="color: #808030;">)</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span>
<span style="color: #800080;">}</span>
<span style="color: #004a43;">#</span><span style="color: #004a43; font-weight: bold;">pragma </span><span style="color: #bb7977; font-weight: bold;">endregion </span>
Check<span style="color: #808030;">(</span>waveOutPrepareHeader<span style="color: #808030;">(</span>hWaveOut<span style="color: #808030;">,</span> pWaveHeader<span style="color: #808030;">,</span> <span style="color: #800000; font-weight: bold;">sizeof</span> <span style="color: #808030;">*</span>pWaveHeader<span style="color: #808030;">)</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span>
Check<span style="color: #808030;">(</span>waveOutWrite<span style="color: #808030;">(</span>hWaveOut<span style="color: #808030;">,</span> pWaveHeader<span style="color: #808030;">,</span> <span style="color: #800000; font-weight: bold;">sizeof</span> <span style="color: #808030;">*</span>pWaveHeader<span style="color: #808030;">)</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span>
<span style="color: #400000;">GlobalUnlock</span><span style="color: #808030;">(</span>hWaveHeader<span style="color: #808030;">)</span><span style="color: #800080;">;</span></pre>
<p>The operating system is supposed to mix the waves, which can be easily perceived taking place. It is possible to run the application with multiple waveforms within a process, e.g. &#8220;abc&#8221; command line parameter, and/or start multiple instances of the application.</p>
<p>A binary [<a href="http://www.alax.info/svn/public/trunk/Utilities/WaveOutMultiPlay/Release/WaveOutMultiPlay.exe">Win32</a>] and partial Visual C++ .NET 2010 <a href="http://www.alax.info/trac/public/browser/trunk/Utilities/WaveOutMultiPlay">source code</a> are available from SVN.</p>
]]></content:encoded>
			<wfw:commentRss>http://alax.info/blog/1291/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

