<?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>JEDI Windows API &#187; Common</title>
	<atom:link href="http://blog.delphi-jedi.net/category/common/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.delphi-jedi.net</link>
	<description>Joint Endeavor of Delphi Innovators of Windows Programming</description>
	<lastBuildDate>Sat, 21 Aug 2010 05:44:40 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=abc</generator>
		<item>
		<title>TRegistry.DeleteKey and 64bit</title>
		<link>http://blog.delphi-jedi.net/2010/08/17/tregistry-deletekey-and-64bit/</link>
		<comments>http://blog.delphi-jedi.net/2010/08/17/tregistry-deletekey-and-64bit/#comments</comments>
		<pubDate>Tue, 17 Aug 2010 12:51:19 +0000</pubDate>
		<dc:creator>Christian Wimmer</dc:creator>
				<category><![CDATA[Common]]></category>
		<category><![CDATA[64bit]]></category>
		<category><![CDATA[Registry]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://blog.delphi-jedi.net/?p=784</guid>
		<description><![CDATA[I got a bug from someone who told me that he had problems with the TRegistry method DeleteKey on his 64bit Windows. It just didn&#8217;t delete a 64bit key* from the registry although he used the KEY_WOW64_64KEY flag in desired access parameter of  TRegistry.Create. At first I thought that it was a problem with the [...]]]></description>
			<content:encoded><![CDATA[<p>I got a bug from someone who told me that he had problems with the TRegistry method <a href="http://docwiki.embarcadero.com/VCL/en/Registry.TRegistry.DeleteKey" target="_blank"><em>DeleteKey</em></a> on his 64bit Windows. It just didn&#8217;t delete a 64bit key* from the registry although he used the KEY_WOW64_64KEY flag in desired access parameter of  TRegistry.Create.</p>
<p><span id="more-784"></span></p>
<p>At first I thought that it was a problem with the OpenKey function of TRegistry. However, this was already confirmed and fixed as a bug in <a href="http://qc.embarcadero.com/wc/qcmain.aspx?d=23429" target="_blank">QC# 23429</a>.</p>
<p>Then I wanted to check the real error value of DeleteKey. Of course, it just returns true or false, so I added a call to GetLastError. And it returned 87 (Invalid Parameter). It must be said that using GetLastError in a framework like VCL is always a problem because you don&#8217;t really know how many winapi functions are called subsequent to the actual winapi function. So you may get an error value from another random function. This is one reason I&#8217;m using exceptions in JWSCL, btw.<br />
 A quick step through debugging session (you have to enable debug dcu in project options and rebuild the project) confirmed that the invalid parameter error (87) came from RegDeleteKey. But why 87? The next step was obvious because I had a windows function and thus I would have to read its <a href="http://msdn.microsoft.com/en-us/library/ms724845%28VS.85%29.aspx" target="_blank">MSDN documentation</a>.</p>
<p>It reads:</p>
<div>
<blockquote><p><cite><strong>RegDeleteKey </strong>Function<br />
 Deletes a subkey and its values. Note that key names are not case sensitive. <strong> </strong></cite></p>
<p><strong>64-bit Windows: </strong>On WOW64, 32-bit  applications view a registry tree that is separate from the registry  tree that 64-bit applications view. To enable an application to delete  an entry in the alternate registry view, use the <a id="ctl00_MTCS_main_ctl01" onclick="javascript:Track('ctl00_MTCS_main_ctl00|ctl00_MTCS_main_ctl01',this);" href="http://msdn.microsoft.com/en-us/library/ms724847%28VS.85%29.aspx"><strong>RegDeleteKeyEx</strong></a> function.</p>
</blockquote>
<p><br class="spacer_" /></p>
<p>So the RegDeleteKey<strong>Ex</strong> function must be used. But don&#8217;t stop reading here and implement it. We can&#8217;t just use this function because MSDN states that this function is only available in XP 64bit or Vista (32 and 64bit). So this gets more complicated and I suggest this way :</p>
<table border="1">
<tbody>
<tr>
<td></td>
<td>XP 32bit</td>
<td>XP 64bit</td>
<td>Vista and newer (32+64)</td>
</tr>
<tr style="text-align: center;">
<td style="text-align: left;">RegDeleteKey</td>
<td>√</td>
<td>only 32bit keys</td>
<td>only 32bit keys</td>
</tr>
<tr>
<td>RegDeleteKeyEx</td>
<td>unsupported</td>
<td style="text-align: center;">√</td>
<td style="text-align: center;">√</td>
</tr>
</tbody>
</table>
<p>√ &#8211; will run fine as it is intended.</p>
<ul>
<li>On a 64bit Windows, always call RegDeleteKeyEx. It supports both 32bit and 64bit registry keys.</li>
<li>Otherwise, if you don&#8217;t want to delete 64bit keys:
<ul>
<li>Call RegDeleteKeyEx on Vista or newer, though.</li>
<li>Call RegDeleteKey on XP 32bit. </li>
</ul>
</li>
</ul>
<p>As a conclusion, you cannot use the TRegistry method DeleteKey with 64bit registry keys. Either you have to use your own RegDeleteKeyEx call or just use a derived class of TRegistry. Of course this is only necessary it you want to access 64bit keys&#8230;this article is FYI.</p>
<p>In the end, the question arises to me why RegDeleteKey does not support 64bit registry keys. I couldn&#8217;t find any evidences, so I can only use my brain to think of one:<br />
 Well, the RegDeleteKey function can be really dangerous if a 32bit application, that is not aware of 64bit, erases 64bit keys. This is especially true for &#8220;HKEY_LOCAL_MACHINE\SOFTWARE&#8221; because you may have installed two versions of an application with same name. First you installed a 32bit only application (name it X) you bought several years ago for your 32bit Windows. One day the vendor sends you a 64bit only update that you install (*so happy*). You decide to abandon the 32bit version and call its custom made uninstaller which deletes all of its known keys. Of course, it will also delete the 64bit version. This may be fictional but possible without the breakup of 32bit and 64bit keys in heavily used parts of the registry. So RegDeleteKey will not delete the 64bit keys because that would break 64bit applications. It seems to me that Microsoft experienced it already, before they decided to add 32-64bit registry separation.  Maybe Raymond Chen would say something like this: <em>Believe us, we tried the other way around:  it&#8217;s worse</em>.</p>
<p><br class="spacer_" /></p>
<p>If you are interested in more information, I suggest you to read <a href="http://msdn.microsoft.com/en-us/library/aa384129%28VS.85%29.aspx" target="_blank">Accessing an Alternate Registry View</a>.</p>
<p>* The key was a subkey from &#8220;HKEY_LOCAL_MACHINE\SOFTWARE&#8221;. In 64bit Windows, a 32bit application (not aware of 64bit) will only see the contents of &#8220;HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node&#8221;.</p>
<h3>Update</h3>
<p>I submitted a bug report to QC: <a href="http://qc.embarcadero.com/wc/qcmain.aspx?d=87323" target="_blank">#87323</a></p>
<h3>Links</h3>
<ul>
<li><a href="http://www.delphipraxis.net/127364-registry-deletekey-problem-unter-xp64.html" target="_blank">DelphiPraxis</a></li>
</ul>
</div>
<!-- PHP 5.x -->]]></content:encoded>
			<wfw:commentRss>http://blog.delphi-jedi.net/2010/08/17/tregistry-deletekey-and-64bit/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Windows LNK Exploit</title>
		<link>http://blog.delphi-jedi.net/2010/07/19/windows-lnk-exploit/</link>
		<comments>http://blog.delphi-jedi.net/2010/07/19/windows-lnk-exploit/#comments</comments>
		<pubDate>Mon, 19 Jul 2010 10:37:18 +0000</pubDate>
		<dc:creator>Christian Wimmer</dc:creator>
				<category><![CDATA[Common]]></category>

		<guid isPermaLink="false">http://blog.delphi-jedi.net/?p=751</guid>
		<description><![CDATA[As you maybe have heard already. There is a shell exploit that is executed when Windows shows just the icon from a link file. MS works on it but currently you can only remove the icon handler key from the registry to be &#8220;safe&#8221;. See this link. It also tells us the impact of the [...]]]></description>
			<content:encoded><![CDATA[<p>As you maybe have heard already. There is a shell exploit that is executed when Windows shows just the icon from a link file. MS works on it but currently you can only remove the icon handler key from the registry to be &#8220;safe&#8221;. See this <a href="http://www.microsoft.com/technet/security/advisory/2286198.mspx" target="_blank">link</a>. It also tells us the impact of the action. However, on Windows 7, I think this prevents me from working efficiently with the Windows Explorer.<span id="more-751"></span><a href="http://www.microsoft.com/technet/security/advisory/2286198.mspx" target="_blank"> Technet reads:</a></p>
<p><cite><strong>Impact of workaround.</strong>Disabling icons from being displayed for  shortcuts prevents the issue from being exploited on affected systems.  When this workaround is implemented, shortcut files and Internet  Explorer shortcuts will no longer have an icon displayed.</cite></p>
<p>Let me show you, why I can&#8217;t work anymore efficiently.</p>
<div id="attachment_752" class="wp-caption alignnone" style="width: 471px"><a href="http://blog.delphi-jedi.net/wp-content/uploads/2010/07/StartMenuWin7Clear.png" rel="lightbox[751]" title="StartMenuWin7Clear"><img class="size-full wp-image-752 " title="StartMenuWin7Clear" src="http://blog.delphi-jedi.net/wp-content/uploads/2010/07/StartMenuWin7Clear.png" alt="Windows 7 Taskbar with plain Icons" width="461" height="30" /></a><p class="wp-caption-text">Windows 7 Taskbar with plain Icons</p></div>
<p>As you can see, some of the applications are already started and they don&#8217;t have their icon but some of them have. I don&#8217;t see the reason though. Do you?</p>
<p>BTW: This goes on in the start menu, on the desktop, and the favorite list in Windows Explorer.</p>
<p>Happy working&#8230;.  <img src='http://blog.delphi-jedi.net/wp-includes/images/smilies/icon_twisted.gif' alt=':twisted:' class='wp-smiley' /> </p>
<p>EDIT:</p>
<p>A <a href="http://code.google.com/p/linkiconshim/" target="_blank">possible fix</a> was supplied by external programmers. Maybe this will be the only option for the last few people who are using Windows 2000 still.</p>
<p><br class="spacer_" /></p>
<!-- PHP 5.x -->]]></content:encoded>
			<wfw:commentRss>http://blog.delphi-jedi.net/2010/07/19/windows-lnk-exploit/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Useful scripts for MSVC and C++ Builder users …</title>
		<link>http://blog.delphi-jedi.net/2010/06/24/useful-scripts-for-msvc-and-c-builder-users-%e2%80%a6/</link>
		<comments>http://blog.delphi-jedi.net/2010/06/24/useful-scripts-for-msvc-and-c-builder-users-%e2%80%a6/#comments</comments>
		<pubDate>Thu, 24 Jun 2010 12:10:57 +0000</pubDate>
		<dc:creator>Christian Wimmer</dc:creator>
				<category><![CDATA[Common]]></category>

		<guid isPermaLink="false">http://blog.delphi-jedi.net/?p=742</guid>
		<description><![CDATA[Assarbad wrote this script some time ago to compile and link C++ projects on the command line easier. I adapted the cmd script for VC++2010 and also for C++ Builder 2009/2010 and now I have been using it for quite some time. So I wanted to give it back to the community. Feel free to [...]]]></description>
			<content:encoded><![CDATA[<p>Assarbad wrote this <a href="http://blog.assarbad.net/20090116/useful-script-for-msvc-users/" target="_blank">script</a> some time ago to compile and link C++ projects on the command line easier. I adapted the cmd script for VC++2010 and also for C++ Builder 2009/2010 and now I have been using it for quite some time. So I wanted to give it back to the community.</p>
<p><span id="more-742"></span>Feel free to use it since it is public domain.</p>
<p><a href="http://blog.delphi-jedi.net/wp-content/uploads/2010/06/scripts.zip">Download C++ Environment Scripts</a></p>
<p>By default the scripts setup the environment to the newest compiler found on your system. In this way you can just call msbuild and build your projects.</p>
<p><br class="spacer_" /></p>
<!-- PHP 5.x -->]]></content:encoded>
			<wfw:commentRss>http://blog.delphi-jedi.net/2010/06/24/useful-scripts-for-msvc-and-c-builder-users-%e2%80%a6/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>New JEDI News Server</title>
		<link>http://blog.delphi-jedi.net/2010/03/22/new-jedi-news-server/</link>
		<comments>http://blog.delphi-jedi.net/2010/03/22/new-jedi-news-server/#comments</comments>
		<pubDate>Mon, 22 Mar 2010 15:24:27 +0000</pubDate>
		<dc:creator>Christian Wimmer</dc:creator>
				<category><![CDATA[Common]]></category>

		<guid isPermaLink="false">http://blog.delphi-jedi.net/?p=719</guid>
		<description><![CDATA[As you maybe already know, the old news server for JEDI related questions crashed some time ago. Unfortunately, the old host could not undo the crash and thus some JEDI members created a new server (Thanks you!). The new server location is: news.delphi-jedi.org Please adapt your news reader accordingly. However, it is a pity that [...]]]></description>
			<content:encoded><![CDATA[<p>As you maybe already know, the old news server for JEDI related questions crashed some time ago. Unfortunately, the old host could not undo the crash and thus some JEDI members created a new server (Thanks you!). The new server location is: <span style="font-size: medium;"><strong>news.delphi-jedi.org </strong></span></p>
<p><span id="more-719"></span>Please adapt your news reader accordingly. However, it is a pity that the old messages cannot be restored and maybe never will without an backup.</p>
<p>Furthermore, the server itself may still be changed but the address will stay the same.</p>
<p><br class="spacer_" /></p>
<!-- PHP 5.x -->]]></content:encoded>
			<wfw:commentRss>http://blog.delphi-jedi.net/2010/03/22/new-jedi-news-server/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Embarcadero Forum Access</title>
		<link>http://blog.delphi-jedi.net/2010/03/22/embarcadero-forum-access/</link>
		<comments>http://blog.delphi-jedi.net/2010/03/22/embarcadero-forum-access/#comments</comments>
		<pubDate>Mon, 22 Mar 2010 09:50:57 +0000</pubDate>
		<dc:creator>Christian Wimmer</dc:creator>
				<category><![CDATA[Common]]></category>

		<guid isPermaLink="false">http://blog.delphi-jedi.net/?p=715</guid>
		<description><![CDATA[If you are accessing the Embarcadero Forums and such through an Offline Reader like Mozilla Thunderbird, you probably have had a connection problem for some time now. I don&#8217;t know what the reason is. However, as a solution instead, use the address forums.embarcadero.com and don&#8217;t forget to activate SSL. I couldn&#8217;t make a connection without [...]]]></description>
			<content:encoded><![CDATA[<p>If you are accessing the Embarcadero Forums and such through an Offline Reader like Mozilla Thunderbird, you probably have had a connection problem for some time now. I don&#8217;t know what the reason is. However, as a solution instead, use the address <strong>forums.embarcadero.com</strong> and don&#8217;t forget to activate SSL. I couldn&#8217;t make a connection without it.</p>
<p><span id="more-715"></span>UPDATE:</p>
<p>It looks to me as if only the unsecured access is not accepted. Instead only SSL is available regardless of the address (so both works).<br />
I got some mails from people who couldn&#8217;t answer the threads I participate. So they sent me mails directly. </p>
<p>A shame that Kaster&#8217;s thread wasn&#8217;t replicated by e.g. Nick. His blog is far more often read by people than this Announce forum (which was afterwards effectively unavailable to me and others).<br />
Furthermore some forums look to me a little bit more abandoned than usual. So the activity seems to be lower.</p>
<!-- PHP 5.x -->]]></content:encoded>
			<wfw:commentRss>http://blog.delphi-jedi.net/2010/03/22/embarcadero-forum-access/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Site Recommendation: History of Windows</title>
		<link>http://blog.delphi-jedi.net/2010/03/13/site-recommondation-history-of-windows/</link>
		<comments>http://blog.delphi-jedi.net/2010/03/13/site-recommondation-history-of-windows/#comments</comments>
		<pubDate>Fri, 12 Mar 2010 23:13:27 +0000</pubDate>
		<dc:creator>Christian Wimmer</dc:creator>
				<category><![CDATA[Common]]></category>
		<category><![CDATA[Recommendation]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://blog.delphi-jedi.net/?p=697</guid>
		<description><![CDATA[If you are interested in the history of Windows, as I am, you should read the article The Secret Origin of Windows by Tandy Trower the product manager of Windows 1.0. This article gives a deep insight into the journey Tandy and his developers had to endure to bring a product on the market that [...]]]></description>
			<content:encoded><![CDATA[<p>If you are interested in the history of Windows, as I am, you should read the article<a href="http://technologizer.com/2010/03/08/the-secret-origin-of-windows/" target="_blank"> <strong>The Secret Origin of Windows</strong></a> by Tandy Trower the product manager of Windows 1.0. This article gives a deep insight into the journey Tandy and his developers had to endure to bring a product on the market that should change the world (although it took a while).</p>
<p><span id="more-697"></span>Tandy also mentions the competitor Borland with its famous Turbo Pascal (that I also used) and how it got Bill Gates to tremble.</p>
<p><cite>At $50 for the Borland product vs. the Microsoft $400 compiler, it was a bit like comparing a VW to a Porsche. But while Turbo Pascal was lighter weight for serious development, it was almost as quick for programming and debugging as Microsoft’s BASIC interpreters</cite></p>
<p>I wonder if the comment about the speed is true?</p>
<p>And did you know that Microsoft had been using the language Pascal for their projects until they developed C ?</p>
<p>Read more about <a onclick="pageTracker._trackPageview ('/outgoing/http_technologizer_com_2010_03_08_the_secret_origin_of_windows_');" rel="nofollow" href="http://technologizer.com/2010/03/08/the-secret-origin-of-windows/" target="_blank">The Secret Origin of Windows</a></p>
<p><br class="spacer_" /></p>
<!-- PHP 5.x -->]]></content:encoded>
			<wfw:commentRss>http://blog.delphi-jedi.net/2010/03/13/site-recommondation-history-of-windows/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Site Recommendation: Terminal Session and Desktops</title>
		<link>http://blog.delphi-jedi.net/2010/03/05/site-recommendation-terminal-session-and-desktops/</link>
		<comments>http://blog.delphi-jedi.net/2010/03/05/site-recommendation-terminal-session-and-desktops/#comments</comments>
		<pubDate>Fri, 05 Mar 2010 18:24:46 +0000</pubDate>
		<dc:creator>Christian Wimmer</dc:creator>
				<category><![CDATA[Common]]></category>
		<category><![CDATA[Recommendation]]></category>
		<category><![CDATA[Russinovich]]></category>
		<category><![CDATA[Session]]></category>

		<guid isPermaLink="false">http://blog.delphi-jedi.net/?p=674</guid>
		<description><![CDATA[Many Windows Programmers still have trouble when it comes to sessions, window stations and desktops. They frequently get mixed up and we can see a lot of question on the Internet about e.g. how to spawn processes in all logged-on user desktops (rather than sessions).  Hence, I have listed some articles that you can read [...]]]></description>
			<content:encoded><![CDATA[<p>Many Windows Programmers still have trouble when it comes to sessions, window stations and desktops. They frequently get mixed up and we can see a lot of question on the Internet about e.g. how to spawn processes in all logged-on user desktops (rather than sessions).  Hence, I have listed some articles that you can read to get a better understanding of such things like a Terminal Sessions.</p>
<p><span id="more-674"></span></p>
<p>To understand the concept of Window Sessions, Stations and Desktop it is not necessary to read all articles to the end. I think the beginning is just fine.</p>
<ul>
<li><strong>Pushing the Limits of Windows: USER and GDI Objects</strong><br />
 Mark Russinovich writes about USER and GDI objects but he also gives a basic introduction how sessions, windowstations and desktops are related.  </p>
<ul>
<li><a href="http://blogs.technet.com/markrussinovich/archive/2010/02/24/3315174.aspx" target="_blank">Part 1 </a></li>
<li>Part 2  (still writing)</li>
</ul>
</li>
<li><strong>Desktop Heap Overview</strong><br />
 The guys from<strong> Advanced Windows Debugging and Troubleshooting</strong> explain how it is possible that a desktop can run out of heap. It is a quite technical article but it gives a nice insight into some of the Windows internals.</p>
<ul>
<li><a href="http://blogs.msdn.com/ntdebugging/archive/2007/01/04/desktop-heap-overview.aspx" target="_blank">Part1</a></li>
<li><a href="http://blogs.msdn.com/ntdebugging/archive/2007/07/05/desktop-heap-part-2.aspx" target="_blank">Part2</a></li>
</ul>
</li>
</ul>
<p>I often prefer such blog articles to MSDN articles because blog articles are much more fun to read.</p>
<!-- PHP 5.x -->]]></content:encoded>
			<wfw:commentRss>http://blog.delphi-jedi.net/2010/03/05/site-recommendation-terminal-session-and-desktops/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Reminder to You</title>
		<link>http://blog.delphi-jedi.net/2010/02/15/reminder-to-you/</link>
		<comments>http://blog.delphi-jedi.net/2010/02/15/reminder-to-you/#comments</comments>
		<pubDate>Mon, 15 Feb 2010 18:28:13 +0000</pubDate>
		<dc:creator>Christian Wimmer</dc:creator>
				<category><![CDATA[Common]]></category>

		<guid isPermaLink="false">http://blog.delphi-jedi.net/?p=640</guid>
		<description><![CDATA[I had some trouble writing these lines because usually I do not want to publish criticism. But Oliver told me that it would be a good idea and I don&#8217;t want to disagree . Valid for all open source projects, also the JEDI API&#38;WSCL projects heavily depend on their users. This is not a company [...]]]></description>
			<content:encoded><![CDATA[<p>I had some trouble writing these lines because usually I do not want to publish criticism. But <a href="http://blog.assarbad.net/" target="_blank">Oliver</a> told me that it would be a good idea and I don&#8217;t want to disagree <img src='http://blog.delphi-jedi.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  .</p>
<p><span id="more-640"></span><span style="font-size: large;">Valid for all open source projects</span>, also the JEDI API&amp;WSCL projects heavily depend on their users. This is not a company where people work all day to make a  great project. I and other members of JEDI use our spare time after real work to bring forward projects such as JEDI.</p>
<p><span style="font-size: large;">Unfortunately, time has changed </span>and less and less people want to provide their skills and manpower in projects like JEDI&#8230;and I am not talking about JEDI API exclusively. That is a pity because we will not provide you with source code forever. Instead the process will come to a halt and we will see more and more questions in newsgroup asking why the project doesn&#8217;t work anymore in Delphi 2020 (or similar).</p>
<p><span style="font-size: large;">I don&#8217;t get it.</span> There are many new API functions in Vista and Windows 7. And I see a lot of people writing conversions from C to Delphi so they can use the new functionality. But instead of donating these sources to JEDI API they post it to their local forum or use it in their project as an internal unit. Usually, I come along and ask these people if they want to donate their source to JEDI API. And the chat goes like this:</p>
<p><em>Christian: &#8220;Hey, I am from JEDI API. Maybe you heard from us. It would be great if your conversion could be integrated into JEDI. Do you agree?&#8221;</em></p>
<p><em>X: &#8220;Yeah, I&#8217;m using your projects a lot. And of course, I would like to see my source integrated into JEDI.&#8221;</em></p>
<p><em>C: &#8220;Well, I need your source code to be converted to some standards we use. I will send you more information about this easy process. If you have further question just ask.&#8221;</em></p>
<p><em>X: &#8220;Eh? Sorry, but I don&#8217;t have time to put more effort into this. Can&#8217;t you just do it yourself?&#8221;</em></p>
<p>Let me answer: <em>Well, If we could do it ourselves we would already have done it. </em>But that means that we would need to give up our jobs and private life to convert over 20.000 functions, interfaces and types only for this project.</p>
<p>Did you know that there is a <a href="http://jedi-apilib.svn.sourceforge.net/viewvc/jedi-apilib/jwapi/trunk/Win32API/_JwaTemplate.pas?revision=857&amp;view=markup" target="_blank">template</a> that shows you how to create a JEDI API file?</p>
<p>Also it often happens that I don&#8217;t hear anything from them. Therefore these conversions never get integrated because I need an explicit agreement.</p>
<p><span style="font-size: large;">On the other hand</span> there are many people who like just to use the source code in their own project because it makes it easier to write good programs. <br />
 May I ask what <span style="text-decoration: underline;">you</span> did to keep alive the project that you gained from?  I have to say from experience that the donations in source and money (in relation to current software prices) are that rare that zero (0) would describe it best. Luckily, this is not entirely true but it is very close to the truth.</p>
<p><span style="font-size: large;">Fortunately, there are a lot of companies</span> which are <strong>generous</strong> and allow us to use their products for free. You can find the list  in the sponsors section of this blog. With a monetary donation of nearly zero we could never use their products. I cannot stop saying: &#8220;<strong>Thank you!</strong>&#8220;</p>
<p><span style="font-size: large;">Also </span>let me use this article to thank all the people who helped or are still helping in these projects. I want to thank them again and again and again! And let me thank the donators again (I wrote them a mail).</p>
<p>&#8211;</p>
<p>Christian</p>
<!-- PHP 5.x -->]]></content:encoded>
			<wfw:commentRss>http://blog.delphi-jedi.net/2010/02/15/reminder-to-you/feed/</wfw:commentRss>
		<slash:comments>24</slash:comments>
		</item>
		<item>
		<title>ACTRL_ACCESS Diagram</title>
		<link>http://blog.delphi-jedi.net/2010/02/11/actrl_access-diagram/</link>
		<comments>http://blog.delphi-jedi.net/2010/02/11/actrl_access-diagram/#comments</comments>
		<pubDate>Thu, 11 Feb 2010 12:08:22 +0000</pubDate>
		<dc:creator>Christian Wimmer</dc:creator>
				<category><![CDATA[Common]]></category>
		<category><![CDATA[JEDI Windows Security Code Lib]]></category>
		<category><![CDATA[ACL]]></category>
		<category><![CDATA[COM]]></category>
		<category><![CDATA[interface]]></category>
		<category><![CDATA[JWSCL]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://blog.delphi-jedi.net/?p=631</guid>
		<description><![CDATA[I had some trouble with this rather complicated COM structure called ACTRL_ACCESS. So I post a diagram to show its design. Otherwise it would be a pity to leave it on my private hard drive. The ACTRL_ACCESS structure is used by the interface method IAccessControl::GetAllAccessRights (and others) which is rather hard to implement yourself because [...]]]></description>
			<content:encoded><![CDATA[<p>I had some trouble with this rather complicated COM structure called ACTRL_ACCESS. So I post a diagram to show its design. Otherwise it would be a pity to leave it on my private hard drive.</p>
<p><span id="more-631"></span></p>
<p>The <a href="http://msdn.microsoft.com/en-us/library/ms693447%28VS.85%29.aspx">ACTRL_ACCESS</a> structure is used by the interface method <a href="http://msdn.microsoft.com/en-us/library/ms688536%28VS.85%29.aspx">IAccessControl::GetAllAccessRights</a> (and others) which is rather hard to implement yourself because the structure must be created in a single block of memory that can be freed by CoTaskMemFree.</p>
<p>So here is how it looks like</p>
<div id="attachment_632" class="wp-caption alignnone" style="width: 427px"><a href="http://blog.delphi-jedi.net/wp-content/uploads/2010/02/IAccessControl_GetAllAccessRights-structures.png" rel="lightbox[631]" title="IAccessControl_GetAllAccessRights structures"><img class="size-full wp-image-632 " title="IAccessControl_GetAllAccessRights structures" src="http://blog.delphi-jedi.net/wp-content/uploads/2010/02/IAccessControl_GetAllAccessRights-structures.png" alt="ACTRL_ACCESS design diagram" width="417" height="399" /></a><p class="wp-caption-text">ACTRL_ACCESS design diagram</p></div>
<p>Luckily, JWSCL will provide an implementation of IAccessControl so don&#8217;t worry.</p>
<p><br class="spacer_" /></p>
<!-- PHP 5.x -->]]></content:encoded>
			<wfw:commentRss>http://blog.delphi-jedi.net/2010/02/11/actrl_access-diagram/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Programming Habits</title>
		<link>http://blog.delphi-jedi.net/2010/01/14/programming-habits/</link>
		<comments>http://blog.delphi-jedi.net/2010/01/14/programming-habits/#comments</comments>
		<pubDate>Thu, 14 Jan 2010 16:45:29 +0000</pubDate>
		<dc:creator>Christian Wimmer</dc:creator>
				<category><![CDATA[Common]]></category>

		<guid isPermaLink="false">http://blog.delphi-jedi.net/?p=612</guid>
		<description><![CDATA[I&#8217;m writing this article because I want to share programming habits with you. What habit did prove to be a good one for you? Share yours then, please. I always add &#8220;RaiseLastOsError&#8221; to every Windows API call. if not ImpersonateLoggedOnUser(token) then &#160;&#160;RaiseLastOsError; In this way you don&#8217;t miss any failed call and wonder what is [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m writing this article because I want to share programming habits with you. What habit did prove to be a good one for you? Share yours then, please. <span id="more-612"></span></p>
<h3>I always add &#8220;RaiseLastOsError&#8221; to every Windows API call.</h3>
<p><pre><pre class="brush:delphi">if not ImpersonateLoggedOnUser(token) then
&nbsp;&nbsp;RaiseLastOsError;
</pre></pre></p>
<p>In this way you don&#8217;t miss any failed call and wonder what is happening (I can recall a lot of forum threads that ask about this). <br />
 RaiseLastOsError generates an EOSError exception that contains the error number and text in its message. It also stores the GetLastError value in its property ErrorCode.</p>
<p>One more good thing is that a caller of the function, where this code is implemented, cannot ignore an error value. The API function ImpersonateLoggedOnUser is very problematic because if it fails all subsequent calls are made on the security token of the process instead of the thread. So a client could access more things than usual. So if we had a function that implements the example</p>
<p><pre><pre class="brush:delphi">function MyImpersonateUserToken(UserName : String; out UserData : PUserData) : Boolean;
begin
&nbsp;&nbsp;//get user token here
&nbsp;&nbsp;//get user information from token here and store it into UserData

&nbsp;&nbsp;result := ImpersonateLoggedOnUser(token);
</pre></pre></p>
<p>As you can see a caller can just do the following</p>
<p><pre><pre class="brush:delphi">MyImpersonateUserToken(UserName, UserData);
If UserData.Groups.IsMemberOf(&#039;Administrators&#039;) then
</pre></pre></p>
<p>Be aware that the example is only fictional. However I have seen many production codes that call WinAPI without error checking. The WinAPI usually (and the code above definitely) does not touch any of the output parameters if they fail. So you probably get an Access Violation (best case) or it works randomly (worst case). See that UserData is not initialized here.   But what about this one:</p>
<p><pre><pre class="brush:delphi">procedure MyImpersonateUserToken(UserName : String; out UserData : PUserData);
begin
&nbsp;&nbsp;//get user token here
&nbsp;&nbsp;if not GetUserToken then
&nbsp;&nbsp;&nbsp;&nbsp;raiseLastOsError;
&nbsp;&nbsp;//get user information from token here and store it into UserData
&nbsp;&nbsp;if not GetTokenInformation then
&nbsp;&nbsp;&nbsp;&nbsp;raiseLastOsError; 

&nbsp;&nbsp;if not ImpersonateLoggedOnUser(token) then
&nbsp;&nbsp;&nbsp;&nbsp;raiseLastOsError;
</pre></pre></p>
<p>You see that the function is really a procedure now that throws exceptions in case of failure. In this way the code following the function call MyImpersonateUserToken isn&#8217;t executed at all. Instead, we need to wrap an exception trap around the function call to let the code continue.</p>
<p><pre><pre class="brush:delphi">try
&nbsp;&nbsp;MyImpersonateUserToken(UserName, UserData);
except
end;

if UserData.Groups.IsMemberOf(&#039;Administrators&#039;) then
</pre></pre></p>
<p>Okay, everbody should see that this is a really ******* code and should not be left in this way.</p>
<p>If you make an habit from this you won&#8217;t miss the old way. Instead it takes less time to implement and I don&#8217;t mention the time searching for memory leaks.</p>
<p>Furthermore, I think it looks much better and besides of that it is really easy to read and understand.<br />
 However, the most important reason (for me) is that any user who calls this function incorrectly (e.g. user not found) gets a nasty exception thrown into the face.</p>
<p>These are the reasons why JWSCL throws exceptions in 99,99% of its methods instead of returning error values.<br class="spacer_" /></p>
<h4>I always use try/finally for memory allocations</h4>
<p>Programmers have a hard to find memory leaks. There are libraries (like JWSCL) that support smart pointers but Delphi comes also with &#8220;smart pointers&#8221; (besides interfaces). Although it needs some more work. If you have translated code from C to Delphi you have seen it maybe. I&#8217;m talking about &#8220;goto&#8221; statements in C code.</p>
<p><pre><pre class="brush:c">{
&nbsp;&nbsp;...
&nbsp;&nbsp;if (!GetTokenInformation(...))
&nbsp;&nbsp;&nbsp;&nbsp;goto exit_1;

goto exit_0;
:exit_1
&nbsp;&nbsp;CloseHandle(hToken);

:exit_0
return (result);
}
</pre></pre></p>
<p>In Delphi we don&#8217;t use goto because we were told that it is  bad habit. So we directly put the exit after each failed function called.</p>
<p><pre><pre class="brush:delphi">begin
&nbsp;&nbsp;...
&nbsp;&nbsp;if not GetToken(hToken) then
&nbsp;&nbsp;begin
&nbsp;&nbsp;&nbsp;&nbsp;result := true;
&nbsp;&nbsp;&nbsp;&nbsp;exit;
&nbsp;&nbsp;end;
&nbsp;&nbsp;if (not GetTokenInformation(...)) then
&nbsp;&nbsp;begin
&nbsp;&nbsp;&nbsp;&nbsp;CloseHandle(hToken);
&nbsp;&nbsp;&nbsp;&nbsp;result := FALSE;
&nbsp;&nbsp;&nbsp;&nbsp;exit;
&nbsp;&nbsp;end;

&nbsp;&nbsp;CloseHandle(hToken);
&nbsp;&nbsp;result := TRUE;
end;
</pre></pre></p>
<p>In more complex code you can easily miss a failure code path or miss to close a handle or free an object. So why don&#8217;t do it this way?</p>
<p><pre><pre class="brush:delphi">&nbsp;&nbsp;...
&nbsp;&nbsp;if not GetToken(hToken) then
&nbsp;&nbsp;&nbsp;&nbsp;raiseLastError;

&nbsp;&nbsp;try
&nbsp;&nbsp;&nbsp;&nbsp;if (not GetTokenInformation(...)) then
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;raiseLastError;

&nbsp;&nbsp;&nbsp;&nbsp;if GetMeOutOfHere() then
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;exit;
&nbsp;&nbsp;finally
&nbsp;&nbsp;&nbsp;&nbsp;CloseHandle(hToken);
&nbsp;&nbsp;end;
end;
</pre></pre></p>
<p>The try/finally statement ensures that the code within finally is executed. It does not matter that an exception is raised (we know that already). Even if we call &#8220;exit&#8221; the finally part is also executed.</p>
<p>However, you need to make sure that the variables within finally are valid.</p>
<p>1. CloseHandle throws an exception if the handle is not valid. This only happens if it detects an attached debugger.</p>
<p>2. Free, FreeAndNil, FreeMem, Dispose will throw an exception depending on the content of the given pointer. In worst case nothing happens and you get garbage results anywhere else in your application.</p>
<p>So the correct way is to trap every allocated variable (pointer, class) in a separate try/finally statement.</p>
<p><pre><pre class="brush:delphi">New(Ptr);
try
&nbsp;&nbsp;MyClass := TMyClass.Create;
&nbsp;&nbsp;try
&nbsp;&nbsp;&nbsp;&nbsp;...
&nbsp;&nbsp;finally
&nbsp;&nbsp;&nbsp;&nbsp;FreeAndNil(MyClass);
&nbsp;&nbsp;end;
finally
&nbsp;&nbsp;Dispose(Ptr);
&nbsp;&nbsp;Ptr := nil;
end;
</pre></pre></p>
<p>Make it an habit to implement the finally part immediately. Delphi helps you by adding the finally part automatically.</p>
<p><pre><pre class="brush:delphi">New(Ptr);
try
&nbsp;&nbsp;(1)
finally
&nbsp;&nbsp;Dispose(Ptr);
&nbsp;&nbsp;Ptr := nil;
end;
</pre></pre></p>
<p>Now continue at position (1).</p>
<p>One more tip:  If you have a lot of source lines between try/finally you can also put a comment behind finally to show the initial call.</p>
<p><pre><pre class="brush:delphi">New(Ptr);
try
&nbsp;&nbsp;... many lines ...
finally //New(Ptr);
&nbsp;&nbsp;Dispose(Ptr);
&nbsp;&nbsp;Ptr := nil;
end;
</pre></pre></p>
<p>In this way you don&#8217;t mix up the variable names allocated and freed. And we also don&#8217;t mix up the allocation types (e.g. GetMem &lt;&gt; Dispose)</p>
<p><br class="spacer_" /></p>
<h3>Your programming habits</h3>
<p>If you want to share your habits you can do this by leaving a comment. Or better you can write your own article and link it here so a conection is made.</p>
<p>Looking forward to hearing from you!</p>
<p><br class="spacer_" /></p>
<p>Christian</p>
<!-- PHP 5.x -->]]></content:encoded>
			<wfw:commentRss>http://blog.delphi-jedi.net/2010/01/14/programming-habits/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
	</channel>
</rss>
