<?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>Dave Amenta .com &#187; Quick Tips</title>
	<atom:link href="http://www.daveamenta.com/category/qtip/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.daveamenta.com</link>
	<description>Indisposable By Default</description>
	<lastBuildDate>Sun, 18 Jul 2010 16:48:18 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Reasons to jailbreak iPhone: LockLight</title>
		<link>http://www.daveamenta.com/2009-11/reasons-to-jailbreak-iphone-locklight/</link>
		<comments>http://www.daveamenta.com/2009-11/reasons-to-jailbreak-iphone-locklight/#comments</comments>
		<pubDate>Mon, 23 Nov 2009 02:34:34 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Quick Tips]]></category>
		<category><![CDATA[Cydia]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[LockLight]]></category>

		<guid isPermaLink="false">http://www.daveamenta.com/?p=238</guid>
		<description><![CDATA[LockLight is now one of the top reasons I jailbreak.  This awesome tweak will allow you to open the iPhone Flashlight with full screen brightness right from the lock screen&#8211;without even looking!

The tweak is called LockLight, and is in the ModMyI repository in Cydia.  Searching for LockLight should bring up the application.

LockLight uses the Cydget [...]]]></description>
			<content:encoded><![CDATA[<p>LockLight is now one of the top reasons I jailbreak.  This awesome tweak will allow you to open the iPhone Flashlight with <strong>full screen brightness</strong> right from the lock screen&#8211;without even looking!</p>
<p><a href="http://www.daveamenta.com/wp-content/uploads/2009/11/IMG_0063.PNG"><img class="aligncenter size-medium wp-image-239" src="http://www.daveamenta.com/wp-content/uploads/2009/11/IMG_0063-200x300.PNG" alt="" width="200" height="300" /></a></p>
<p>The tweak is called <strong>LockLight</strong>, and is in the ModMyI repository in Cydia.  Searching for <strong>LockLight</strong> should bring up the application.</p>
<p><a href="http://www.daveamenta.com/wp-content/uploads/2009/11/IMG_0065.PNG"><img class="aligncenter size-medium wp-image-240" src="http://www.daveamenta.com/wp-content/uploads/2009/11/IMG_0065-200x300.PNG" alt="" width="200" height="300" /></a></p>
<p>LockLight uses the Cydget platform, which allows for multiple lock screen views.  Cydget is configurable in Settings.<br />
<a href="http://www.daveamenta.com/wp-content/uploads/2009/11/IMG_0067.PNG"><img class="aligncenter size-medium wp-image-242" src="http://www.daveamenta.com/wp-content/uploads/2009/11/IMG_0067-200x300.PNG" alt="" width="200" height="300" /></a></p>
<p>Configure Cydget such that <strong>AwayView </strong>is first, and <strong>LockLight</strong> is lower down in the list.  Unfortunately this tweak works best with just LockLight and AwayView, but there are other cool Cydget views that are worth looking at, such as <strong>CyCalc</strong>.</p>
<p><a href="http://www.daveamenta.com/wp-content/uploads/2009/11/IMG_0068.PNG"><img class="aligncenter size-medium wp-image-243" src="http://www.daveamenta.com/wp-content/uploads/2009/11/IMG_0068-200x300.PNG" alt="" width="200" height="300" /></a></p>
<p>Once you&#8217;ve configured Cydget, Respring your device and enjoy using LockLight!</p>
<p><strong>LockLight Activation:</strong></p>
<p>To start using LockLight, press the power or home button to view the lock screen.  Tap the home button to cycle through your enabled Cydgets.  If just LockLight and AwayView are enabled, tapping the home button will alternate between the two.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.daveamenta.com/2009-11/reasons-to-jailbreak-iphone-locklight/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Awesome Windows 7 Logon background</title>
		<link>http://www.daveamenta.com/2009-11/awesome-windows-7-logon-background/</link>
		<comments>http://www.daveamenta.com/2009-11/awesome-windows-7-logon-background/#comments</comments>
		<pubDate>Fri, 20 Nov 2009 22:27:35 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Quick Tips]]></category>
		<category><![CDATA[Logon]]></category>
		<category><![CDATA[Windows 7]]></category>

		<guid isPermaLink="false">http://www.daveamenta.com/?p=223</guid>
		<description><![CDATA[Just something I thought may be good enough to share.

Click for full sized image.
How To: Set logon background in Windows 7:
- Save the image as backgroundDefault.jpg.
- Place the image in c:\Windows\System32\oobe\info\backgrounds\
Note that you&#8217;ll need to create the  info and backgrounds folders.
- Open gpedit.msc, the Group Policy editor and Navigate to:
Computer Configuration -> Administrative Templates -> System [...]]]></description>
			<content:encoded><![CDATA[<p>Just something I thought may be good enough to share.</p>
<p><a href="http://www.daveamenta.com/wp-content/uploads/2009/11/backgroundDefault.jpg"><img class="aligncenter size-full wp-image-225" src="http://www.daveamenta.com/wp-content/uploads/2009/11/backgroundDefault_small.jpg" alt="" width="400" height="250" /></a><br />
Click for full sized image.</p>
<p><strong>How To: Set logon background in Windows 7:</strong></p>
<p>- Save the image as <strong>backgroundDefault.jpg</strong>.</p>
<p>- Place the image in <strong>c:\Windows\System32\oobe\info\backgrounds\</strong></p>
<p>Note that you&#8217;ll need to create the <strong> info</strong> and <strong>backgrounds</strong> folders.</p>
<p>- Open <strong>gpedit.msc</strong>, the Group Policy editor and Navigate to:</p>
<p>Computer Configuration -> Administrative Templates -> System -> Logon</p>
<p>- Set the <strong>Always use custom logon background</strong> policy to <strong>Enabled</strong>.</p>
<p>Windows will now load the custom background each time the logon screen is invoked.</p>
<p>Screenshot of Windows 7 Logon UI:</p>
<p><a href="http://www.daveamenta.com/wp-content/uploads/2009/11/win7logon.png"><img class="aligncenter size-medium wp-image-232" src="http://www.daveamenta.com/wp-content/uploads/2009/11/win7logon-300x194.png" alt="" width="300" height="194" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.daveamenta.com/2009-11/awesome-windows-7-logon-background/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>iPhone 3.1 Jailbreak &#8220;No Service&#8221; fix.</title>
		<link>http://www.daveamenta.com/2009-10/iphone-3-1-jailbreak-no-service-fix/</link>
		<comments>http://www.daveamenta.com/2009-10/iphone-3-1-jailbreak-no-service-fix/#comments</comments>
		<pubDate>Thu, 01 Oct 2009 06:10:26 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Quick Tips]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Jailbreak]]></category>
		<category><![CDATA[pwnagetool]]></category>

		<guid isPermaLink="false">http://www.daveamenta.com/?p=154</guid>
		<description><![CDATA[After upgrading my iPhone with pwnage tool 3.1, I no longer had AT&#38;T cellular service.  The phone would not display the AT&#38;T Carrier text, and data could only be transferred via WiFi.  The text would alternate between Searching&#8230; and No Service.
I&#8217;ve realized that the issue is that pwnage tool will automatically select &#8220;Activate&#8221; when [...]]]></description>
			<content:encoded><![CDATA[<p>After upgrading my iPhone with pwnage tool 3.1, I no longer had AT&amp;T cellular service.  The phone would not display the AT&amp;T Carrier text, and data could only be transferred via WiFi.  The text would alternate between <strong>Searching&#8230;</strong> and <strong>No Service</strong>.</p>
<p>I&#8217;ve realized that the issue is that pwnage tool will automatically select &#8220;Activate&#8221; when Jailbreaking the firmware image.</p>
<p>In order to use your iPhone with OS 3.1 and AT&amp;T, remember not to select <strong>Activate</strong> when jailbreaking.</p>
<p><img class="aligncenter size-full wp-image-156" title="pwn_gens" src="http://www.daveamenta.com/wp-content/uploads/2009/10/pwn_gens.jpg" alt="pwn_gens" width="382" height="336" /></p>
<p>Select General to modify Activation options.</p>
<p><img class="aligncenter size-full wp-image-155" title="pwn_gen" src="http://www.daveamenta.com/wp-content/uploads/2009/10/pwn_gen.jpg" alt="pwn_gen" width="381" height="336" /></p>
<p>Remember to <em>unselect</em> <strong>Activate the Phone</strong>.  This will allow the iPhone to work on AT&amp;T with the proper activation.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.daveamenta.com/2009-10/iphone-3-1-jailbreak-no-service-fix/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Ping remote host in Javascript using WMI</title>
		<link>http://www.daveamenta.com/2009-09/ping-remote-host-in-javascript-using-wmi/</link>
		<comments>http://www.daveamenta.com/2009-09/ping-remote-host-in-javascript-using-wmi/#comments</comments>
		<pubDate>Sun, 27 Sep 2009 19:17:52 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Quick Tips]]></category>
		<category><![CDATA[Ping]]></category>
		<category><![CDATA[WMI]]></category>

		<guid isPermaLink="false">http://www.daveamenta.com/?p=142</guid>
		<description><![CDATA[I&#8217;ve been working on a simple Windows Sidebar Gadget that will determine if a remote host is online or not.  For the connectivity test I chose ping, since it&#8217;s lightweight and unlikely to disturb any services on a device.
Ping using WMI

function Ping&#40;host&#41;
&#123;
	var wmi = GetObject&#40;&#34;Winmgmts:&#34;&#41;;
	var eStatus = new Enumerator&#40;wmi.ExecQuery&#40;
&#34;Select StatusCode from Win32_PingStatus Where Address='&#34; [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been working on a simple Windows Sidebar Gadget that will determine if a remote host is online or not.  For the connectivity test I chose ping, since it&#8217;s lightweight and unlikely to disturb any services on a device.</p>
<p><strong>Ping using WMI</strong></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> Ping<span style="color: #009900;">&#40;</span>host<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> wmi <span style="color: #339933;">=</span> GetObject<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Winmgmts:&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> eStatus <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Enumerator<span style="color: #009900;">&#40;</span>wmi.<span style="color: #660066;">ExecQuery</span><span style="color: #009900;">&#40;</span>
<span style="color: #3366CC;">&quot;Select StatusCode from Win32_PingStatus Where Address='&quot;</span> <span style="color: #339933;">+</span> host <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;'&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">return</span> eStatus.<span style="color: #000066; font-weight: bold;">item</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">StatusCode</span> <span style="color: #339933;">==</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The function Ping will return true if the host is online, false otherwise.  Optionally, a Timeout parameter may be specified in the WMI query.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.daveamenta.com/2009-09/ping-remote-host-in-javascript-using-wmi/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Faster Windows Gadget development &amp; testing</title>
		<link>http://www.daveamenta.com/2009-09/faster-windows-gadget-development-testing/</link>
		<comments>http://www.daveamenta.com/2009-09/faster-windows-gadget-development-testing/#comments</comments>
		<pubDate>Sun, 27 Sep 2009 19:12:29 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Quick Tips]]></category>
		<category><![CDATA[Gadget]]></category>
		<category><![CDATA[Sidebar]]></category>

		<guid isPermaLink="false">http://www.daveamenta.com/?p=140</guid>
		<description><![CDATA[Testing and debugging of Windows Sidebar Gadgets may be painful if you wish to test or debug a gadget that has a configuration.  Removing and re-creating a gadget by dragging it out of the Gadget window will delete any saved configuration.  I&#8217;ve found that I would like to restart the sidebar and refresh [...]]]></description>
			<content:encoded><![CDATA[<p>Testing and debugging of Windows Sidebar Gadgets may be painful if you wish to test or debug a gadget that has a configuration.  Removing and re-creating a gadget by dragging it out of the Gadget window will delete any saved configuration.  I&#8217;ve found that I would like to restart the sidebar and refresh all the gadgets at once.  Restarting the Sidebar process is also the only way to flush the image cache.  If you&#8217;re having caching problems, restarting the Sidebar will reload the data from disk.</p>
<p>To restart the sidebar with just a click &#8211; create the following batch file:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">taskkill <span style="color: #000000; font-weight: bold;">/</span>F <span style="color: #000000; font-weight: bold;">/</span>IM sidebar.exe <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #ff0000;">&quot;c:\Program Files\Windows Sidebar\sidebar.exe&quot;</span></pre></div></div>

<p>Save the file as restart_sidebar.bat.  Elevation is not required to restart the sidebar.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.daveamenta.com/2009-09/faster-windows-gadget-development-testing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C#: Don&#8217;t display the startup form.</title>
		<link>http://www.daveamenta.com/2009-09/c-dont-display-the-startup-form/</link>
		<comments>http://www.daveamenta.com/2009-09/c-dont-display-the-startup-form/#comments</comments>
		<pubDate>Sat, 26 Sep 2009 23:13:18 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[Quick Tips]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Win32]]></category>

		<guid isPermaLink="false">http://www.daveamenta.com/?p=25</guid>
		<description><![CDATA[Something that often seems to be a problem with beginning C# developers is the display of the initial form.  Normally one would always want the startup form to be displayed as soon as possible&#8211;but sometimes the application lives in the tray, or should not initially display a window.
One may first think that an event in [...]]]></description>
			<content:encoded><![CDATA[<p>Something that often seems to be a problem with beginning C# developers is the display of the initial form.  Normally one would always want the startup form to be displayed as soon as possible&#8211;but sometimes the application lives in the tray, or should not initially display a window.</p>
<p>One may first think that an event in System.Windows.Forms.Form can be handled, and the form may be directed to Hide.  Unfortunately, this won&#8217;t work as expected, the Form will always get the SW_SHOW message when Application.Run() is executed.</p>
<p>When creating a new project, Visual Studio will generate a Program.cs which looks similar to the following:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">namespace</span> CamOn
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">static</span> <span style="color: #FF0000;">class</span> Program
    <span style="color: #000000;">&#123;</span>
        <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// The main entry point for the application.</span>
        <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
        <span style="color: #000000;">&#91;</span>STAThread<span style="color: #000000;">&#93;</span>
        <span style="color: #0600FF;">static</span> <span style="color: #0600FF;">void</span> Main<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            Application.<span style="color: #0000FF;">EnableVisualStyles</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            Application.<span style="color: #0000FF;">SetCompatibleTextRenderingDefault</span><span style="color: #000000;">&#40;</span><span style="color: #0600FF;">false</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            Application.<span style="color: #0000FF;">Run</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">new</span> Form1<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>When Application.Run is invoked with a Form parameter, it will create <em>and show</em> the window.  The easiest way to override this behavior is to simply not call Application.Run with the form:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">namespace</span> CamOn
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">static</span> <span style="color: #FF0000;">class</span> Program
    <span style="color: #000000;">&#123;</span>
        <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// The main entry point for the application.</span>
        <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
        <span style="color: #000000;">&#91;</span>STAThread<span style="color: #000000;">&#93;</span>
        <span style="color: #0600FF;">static</span> <span style="color: #0600FF;">void</span> Main<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            Application.<span style="color: #0000FF;">EnableVisualStyles</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            Application.<span style="color: #0000FF;">SetCompatibleTextRenderingDefault</span><span style="color: #000000;">&#40;</span><span style="color: #0600FF;">false</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #008000;">new</span> Form1<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            Application.<span style="color: #0000FF;">Run</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Form1 will still be created and pump messages &#8211; but it won&#8217;t initially be shown.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.daveamenta.com/2009-09/c-dont-display-the-startup-form/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Get to your Windows desktop faster &#8211; secure automatic logon.</title>
		<link>http://www.daveamenta.com/2009-09/get-to-your-windows-desktop-faster-secure-automatic-logon/</link>
		<comments>http://www.daveamenta.com/2009-09/get-to-your-windows-desktop-faster-secure-automatic-logon/#comments</comments>
		<pubDate>Sat, 26 Sep 2009 22:09:52 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Quick Tips]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[Winlogon]]></category>

		<guid isPermaLink="false">http://www.daveamenta.com/?p=114</guid>
		<description><![CDATA[The common advice for automatically locking the computer after logging in is to create a batch file and add it to the startup folder.  Unfortunately the experience isn&#8217;t very elegant, or secure.  The desktop and shell will appear while applications are loading, long before the computer will lock itself.  The possibility exists [...]]]></description>
			<content:encoded><![CDATA[<p>The common advice for automatically locking the computer after logging in is to create a batch file and add it to the startup folder.  Unfortunately the experience isn&#8217;t very elegant, or secure.  The desktop and shell will appear while applications are loading, long before the computer will lock itself.  The possibility exists for someone to tamper with the computer while it is in this intermediate loading state.</p>
<p>A solution to this problem is to lock the computer sooner in the logon process.  There are several good places within the logon process to put a task, but the one that may execute the soonest is certainly Userinit.  Userinit is the first program which is executed after logon.</p>
<blockquote><p>From MSDN:  http://msdn.microsoft.com/en-us/library/aa378750(VS.85).aspx</p>
<p>Userinit.exe is an application that is executed when the user has logged on. It runs in the newly logged-on user&#8217;s context and on the application desktop. Its purpose is to set up the user&#8217;s environment, including restoring network uses, establishing profile settings such as fonts and screen colors, and running logon scripts. After completing those tasks, Userinit.exe executes the user shell programs. The shell programs inherit the environment that Userinit.exe sets up. The specific shell programs that Userinit.exe executes are stored in the Shell key value under the Winlogon registry key.</p></blockquote>
<p><strong>Add the lock command to Userinit</strong></p>
<p>Create a batch file that will lock the computer:</p>
<blockquote><p>rundll32.exe user32.dll,LockWorkStation</p></blockquote>
<p>Name the file lock.bat and place it in the System Root.  (c:\windows\system32).</p>
<p>Open regedit and navigate to:</p>
<blockquote><p>HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon</p></blockquote>
<p>The registry value Userinit should contain the path to Userinit.exe</p>
<blockquote><p>C:\Windows\system32\userinit.exe</p></blockquote>
<p>Change the value to contain the lock batch file <em>before</em> the Userinit.exe, with a comma between.</p>
<blockquote><p>C:\Windows\System32\lock.bat, C:\Windows\system32\userinit.exe</p></blockquote>
<p><a href="http://www.daveamenta.com/wp-content/uploads/2009/09/reg_lock.png"><img class="size-large wp-image-116" title="reg_lock" src="http://www.daveamenta.com/wp-content/uploads/2009/09/reg_lock-1024x555.png" alt="Windows Registry at Winlogon key" width="500" height="275" /></a></p>
<p>Log off to see the result.  Note that using a batch file does not discriminate between automatic logon, and user-initiated logon.  One could write a program that would only call LockWorkStation if the computer was up for less than 10 minutes.</p>
<p><strong>To enable automatic logon</strong></p>
<p>If automatic logon isn&#8217;t already enabled, execute <strong>control userpasswords2</strong> at the Run prompt, and uncheck <em>Users must enter a username and password to use this computer</em>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.daveamenta.com/2009-09/get-to-your-windows-desktop-faster-secure-automatic-logon/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Set Digsby Status from Command Line</title>
		<link>http://www.daveamenta.com/2008-07/set-digsby-status-from-command-line/</link>
		<comments>http://www.daveamenta.com/2008-07/set-digsby-status-from-command-line/#comments</comments>
		<pubDate>Wed, 02 Jul 2008 03:03:33 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Quick Tips]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[CLI]]></category>
		<category><![CDATA[Digsby]]></category>
		<category><![CDATA[DigsbyStatus]]></category>
		<category><![CDATA[DigsbyTwitter]]></category>
		<category><![CDATA[Twitter]]></category>

		<guid isPermaLink="false">http://www.daveamenta.com/?p=76</guid>
		<description><![CDATA[There was a request today on the Digsby forums about setting the status based on a twitter feed.  I thought this was a great idea, since this is something I could use.  Normally I don&#8217;t use status message at all &#8211; but I do twitter.
I set to work figuring out how to set the status [...]]]></description>
			<content:encoded><![CDATA[<p>There was a request today on the <a href="http://www.digsby.com">Digsby</a> forums about setting the status based on a twitter feed.  I thought this was a great idea, since this is something I could use.  Normally I don&#8217;t use status message at all &#8211; but I do twitter.</p>
<p>I set to work figuring out how to set the status from outside the application.  I went with the same approach that I had used before, simulating a local user via Win32 Window messages.  This is a great solution because it doesn&#8217;t interfere with any actions that a user may be performing locally &#8211; you don&#8217;t even know it is happening.</p>
<p>I broke this project up into the two logical components, the part that gets the twitter feed and the part that actually does the work of setting the status.  What I&#8217;ve come up with is a little command line utility to set the status.</p>
<p>It can be used like so:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">DigsbyStatus.<span style="color: #202020;">exe</span> <span style="color: #ff0000;">&quot;This is my new status message&quot;</span></pre></div></div>

<p>Or, to clear the status:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">DigsbyStatus.<span style="color: #202020;">exe</span> <span style="color: #ff0000;">&quot;&quot;</span></pre></div></div>

<p>Quotes are needed as to simulate a &#8220;blank&#8221; argument.  The status classification can&#8217;t be changed, so you will still be available or away based on the protocol and the last state of the computer.  I figure someone else might find this useful to, say, update status based on some unsupported media player.</p>
<p>Download: <a href="/download/DigsbyStatus_100.zip">DigsbyStatus_100.zip</a> [10KB]</p>
]]></content:encoded>
			<wfw:commentRss>http://www.daveamenta.com/2008-07/set-digsby-status-from-command-line/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>C#: WebClient Usage</title>
		<link>http://www.daveamenta.com/2008-05/c-webclient-usage/</link>
		<comments>http://www.daveamenta.com/2008-05/c-webclient-usage/#comments</comments>
		<pubDate>Sat, 10 May 2008 02:38:35 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[Quick Tips]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[WebClient]]></category>

		<guid isPermaLink="false">http://www.daveamenta.com/?p=45</guid>
		<description><![CDATA[Microsoft has provided a great utility since .NET 1.0 for doing quick I/O via websites.  The WebClient class provides basic functionality for downloading from and uploading to webservers.  the WebClient example on MSDN leaves a lot to be desired, especially for beginners.  I&#8217;d like to expand on that, as well as provide some example code.
C#: [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.daveamenta.com/wp-content/uploads/2008/05/filesave-150x150.png" border="0" alt="" align="right" />Microsoft has provided a great utility since .NET 1.0 for doing quick I/O via websites.  The <strong>WebClient</strong> class provides basic functionality for downloading from and uploading to webservers.  the WebClient example on MSDN leaves a lot to be desired, especially for beginners.  I&#8217;d like to expand on that, as well as provide some example code.</p>
<p><strong>C#: Using WebClient to fetch a page:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">        <span style="color: #008080; font-style: italic;">// create a new instance of WebClient</span>
        WebClient client <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> WebClient<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">// set the user agent to IE6</span>
        client.<span style="color: #0000FF;">Headers</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;user-agent&quot;</span>, <span style="color: #666666;">&quot;Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.0.3705;)&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #0600FF;">try</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #008080; font-style: italic;">// actually execute the GET request</span>
            <span style="color: #FF0000;">string</span> ret <span style="color: #008000;">=</span> client.<span style="color: #0000FF;">DownloadString</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;http://www.google.com/&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">// ret now contains the contents of the webpage</span>
            Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;First 256 bytes of response: &quot;</span> <span style="color: #008000;">+</span> ret.<span style="color: #0000FF;">Substring</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">0</span>,<span style="color: #FF0000;">265</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
        <span style="color: #0600FF;">catch</span> <span style="color: #000000;">&#40;</span>WebException we<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #008080; font-style: italic;">// WebException.Status holds useful information</span>
            Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span>we.<span style="color: #0000FF;">Message</span> <span style="color: #008000;">+</span> <span style="color: #666666;">&quot;<span style="color: #008080; font-weight: bold;">\n</span>&quot;</span> <span style="color: #008000;">+</span> we.<span style="color: #0000FF;">Status</span>.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
        <span style="color: #0600FF;">catch</span> <span style="color: #000000;">&#40;</span>NotSupportedException ne<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #008080; font-style: italic;">// other errors</span>
            Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span>ne.<span style="color: #0000FF;">Message</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span></pre></div></div>

<p><em>(This code uses DownloadString, you can also use DownloadData for a more binary-friendly version)</em></p>
<p>This is great for fetching simple pages that have data encoded in the querystring, but there are some problems with the basic <em>DownloadString</em> method of WebClient.  It&#8217;s synchronous, so it will <em>block</em> until the operation completes.  So for slow connections, or large files, this would need to run in another thread.  There is a better way.  But first, here&#8217;s another example of another basic, but important, method, <em>DownloadFile</em>.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">        <span style="color: #008080; font-style: italic;">// create a new instance of WebClient</span>
        WebClient client <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> WebClient<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">// set the user agent to IE6</span>
        client.<span style="color: #0000FF;">Headers</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;user-agent&quot;</span>, <span style="color: #666666;">&quot;Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.0.3705;)&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #0600FF;">try</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #008080; font-style: italic;">// actually execute the GET request</span>
            client.<span style="color: #0000FF;">DownloadFile</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;http://www.google.com/&quot;</span>,<span style="color: #666666;">&quot;google_fetch.txt&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">// ret now contains the contents of the webpage</span>
            Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;File Saved.&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
        <span style="color: #0600FF;">catch</span> <span style="color: #000000;">&#40;</span>WebException we<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #008080; font-style: italic;">// WebException.Status holds useful information</span>
            Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span>we.<span style="color: #0000FF;">Message</span> <span style="color: #008000;">+</span> <span style="color: #666666;">&quot;<span style="color: #008080; font-weight: bold;">\n</span>&quot;</span> <span style="color: #008000;">+</span> we.<span style="color: #0000FF;">Status</span>.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
        <span style="color: #0600FF;">catch</span> <span style="color: #000000;">&#40;</span>NotSupportedException ne<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #008080; font-style: italic;">// other errors</span>
            Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span>ne.<span style="color: #0000FF;">Message</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span></pre></div></div>

<p>This example is almost identical to the above, aside from the <em>client.DownloadFile</em> method.  This will save the file to disk, instead of returning a string&#8211;often what you would end up doing with the string anyway.</p>
<p><strong>But can I send POST data?<br />
</strong></p>
<p>Yes!  Using WebClient.UploadString or WebClient.UploadData you can POST data to the server easily.  I&#8217;ll show an example using UploadData, since UploadString is used in the same manner as DownloadString.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">            <span style="color: #FF0000;">byte</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> bret <span style="color: #008000;">=</span> client.<span style="color: #0000FF;">UploadData</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;http://www.website.com/post.php&quot;</span>, <span style="color: #666666;">&quot;POST&quot;</span>,
                <span style="color: #000000;">System.<span style="color: #0000FF;">Text</span></span>.<span style="color: #0000FF;">Encoding</span>.<span style="color: #0000FF;">ASCII</span>.<span style="color: #0000FF;">GetBytes</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;field1=value1&amp;amp;field2=value2&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #FF0000;">string</span> sret <span style="color: #008000;">=</span> <span style="color: #000000;">System.<span style="color: #0000FF;">Text</span></span>.<span style="color: #0000FF;">Encoding</span>.<span style="color: #0000FF;">ASCII</span>.<span style="color: #0000FF;">GetString</span><span style="color: #000000;">&#40;</span>bret<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p><em>UploadData</em> returns a byte array (byte[]) which contains the contents of the page.  This can easily be converted to a string by using the <em>System.Text.Encoding.ASCII.GetString()</em> method.  You can also use the other encoding types in <em>System.Text.Encoding</em> (such as UTF8) to do the same.</p>
<p>Also note the use of <em>GetBytes()</em>, the <em>UploadData</em> method will only take a byte array as a buffer for the upload.  This works well if you are uploading a binary file.</p>
<p><strong>What about the asynchronous methods of WebClient?</strong></p>
<p>WebClient provides asynchronous methods for fetching webpages as well, they are named similarly to the synchronous methods, DownloadFileAsync, DownloadDataAsync, DownloadStringAsync, UploadFileAsync, UploadDataAsync, UploadStringAsync, and UploadValuesAsync.</p>
<p>In order to execute an Async request, you will need to attach event handlers before the method is executed.  Without these event handlers you will not have any sense of when the operation finishes, or what stage it is at.</p>
<p><strong>C# WebClient Asynchronous call example:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">void</span> do_upload<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
   WebClient client <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> WebClient<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
   <span style="color: #008080; font-style: italic;">// add event handlers for completed and progress changed</span>
   client.<span style="color: #0000FF;">UploadProgressChanged</span> <span style="color: #008000;">+=</span> <span style="color: #008000;">new</span> UploadProgressChangedEventHandler<span style="color: #000000;">&#40;</span>client_UploadProgressChanged<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
   client.<span style="color: #0000FF;">UploadFileCompleted</span> <span style="color: #008000;">+=</span> <span style="color: #008000;">new</span> UploadFileCompletedEventHandler<span style="color: #000000;">&#40;</span>client_UploadFileCompleted<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
  <span style="color: #008080; font-style: italic;">// carry out the operation as normal</span>
   client.<span style="color: #0000FF;">UploadFileAsync</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;http://www.daveamenta.com/up.php&quot;</span>, <span style="color: #666666;">@&quot;c:\somefile.bin&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #0600FF;">void</span> client_UploadProgressChanged<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> sender, UploadProgressChangedEventArgs e<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
   Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span>e.<span style="color: #0000FF;">ProgressPercentage</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #0600FF;">void</span> client_UploadFileCompleted<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> sender, UploadFileCompletedEventArgs e<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
   <span style="color: #0600FF;">if</span><span style="color: #000000;">&#40;</span>e.<span style="color: #0000FF;">Result</span> <span style="color: #008000;">!=</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
      Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">System.<span style="color: #0000FF;">Text</span></span>.<span style="color: #0000FF;">Encoding</span>.<span style="color: #0000FF;">ASCII</span>.<span style="color: #0000FF;">GetString</span><span style="color: #000000;">&#40;</span>e.<span style="color: #0000FF;">Result</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
   <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>The call to <em>client.DownloadFileAsync</em> will no longer <em>block</em> the thread, and will execute in the background, periodically calling the event handlers to display progress.  The other methods can be used in this same way.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.daveamenta.com/2008-05/c-webclient-usage/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>What is P/Invoke (PInvoke)?</title>
		<link>http://www.daveamenta.com/2008-05/what-is-pinvoke-pinvoke/</link>
		<comments>http://www.daveamenta.com/2008-05/what-is-pinvoke-pinvoke/#comments</comments>
		<pubDate>Fri, 09 May 2008 00:54:33 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Quick Tips]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[PInvoke]]></category>
		<category><![CDATA[Win32]]></category>

		<guid isPermaLink="false">http://www.daveamenta.com/?p=28</guid>
		<description><![CDATA[P/Invoke, or Pinvoke stands for Platform Invocation Services.  PInvoke is a feature of the Microsoft .NET Frameowrk that allows a developer to make calls to native code inside Dynamic Link Libraries (DLL&#8217;s).  When Pinvoking, the .NET framework (or Common Language Routine) will load the DLL and handle the type conversions automatically.  The most common use [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.daveamenta.com/wp-content/uploads/2008/05/vs01.png"><img class="alignright size-medium wp-image-36" title="vs01" src="http://www.daveamenta.com/wp-content/uploads/2008/05/vs01-300x198.png" alt="" width="300" height="198" align="right" /></a>P/Invoke, or Pinvoke stands for <strong>Platform Invocation Services</strong>.  PInvoke is a feature of the Microsoft .NET Frameowrk that allows a developer to make calls to native code inside <em>Dynamic Link Libraries</em> (DLL&#8217;s).  When Pinvoking, the .NET framework (or <em>Common Language Routine</em>) will load the DLL and handle the type conversions automatically.  The most common use of P/Invoke is to use a feature of Windows that is only contained in the Win32 API.  The API in Windows is extremely extensive and only some of the features are encapsulated in .NET libraries.  For example, <em>Form.Show();</em> is really a wrapper for the <em>ShowWindow()</em> API found in shell32.dll.</p>
<p><strong>ShowWindow Declaration API for C#:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #000000;">&#91;</span>DllImport<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;user32.dll&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
<span style="color: #0600FF;">static</span> <span style="color: #0600FF;">extern</span> <span style="color: #FF0000;">bool</span> ShowWindow<span style="color: #000000;">&#40;</span>IntPtr hWnd, <span style="color: #FF0000;">int</span> nCmdShow<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p>Note the use of the <em>DllImport</em> attribute.  This attribute, coupled with <em>extern</em> tells the .NET CLR where it can find the native declaration for ShowWindow.  shell32.dll must be registered on the system for this to work properly.</p>
<p><strong>Note:</strong> Remember import the <em>System.Runtime.InteropServices</em> namespace!  This is where the [DLLImport] attribute is found.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Runtime.InteropServices</span><span style="color: #008000;">;</span></pre></div></div>

<p><strong>How are P/Invoked methods called?</strong></p>
<p>Methods that are loaded in using DLLImport are Pinvoked by simply treating them as native .NET functions, and calling them as you would call any other.  Win32 API do tend to use data types that are not used often in .NET, for example &#8211; the <em>IntPtr</em> datatype, which is actually a pointer to an integer&#8211;in this case, a <strong>Window Handle</strong>.  nCmdShow is an integer that represents the <em>show command</em>.  But what values of nCmdShow mean what?  These can either be found on MSDN, or PInvoke.net.</p>
<p><strong>C# Constants for ShowWindow in shell32.dll:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">  <span style="color: #0600FF;">const</span> <span style="color: #FF0000;">int</span>        SW_HIDE            <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span>
  <span style="color: #0600FF;">const</span> <span style="color: #FF0000;">int</span>        SW_SHOWNORMAL      <span style="color: #008000;">=</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">;</span>
  <span style="color: #0600FF;">const</span> <span style="color: #FF0000;">int</span>        SW_NORMAL          <span style="color: #008000;">=</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">;</span>
  <span style="color: #0600FF;">const</span> <span style="color: #FF0000;">int</span>        SW_SHOWMINIMIZED   <span style="color: #008000;">=</span> <span style="color: #FF0000;">2</span><span style="color: #008000;">;</span>
  <span style="color: #0600FF;">const</span> <span style="color: #FF0000;">int</span>        SW_SHOWMAXIMIZED   <span style="color: #008000;">=</span> <span style="color: #FF0000;">3</span><span style="color: #008000;">;</span>
  <span style="color: #0600FF;">const</span> <span style="color: #FF0000;">int</span>        SW_MAXIMIZE        <span style="color: #008000;">=</span> <span style="color: #FF0000;">3</span><span style="color: #008000;">;</span>
  <span style="color: #0600FF;">const</span> <span style="color: #FF0000;">int</span>        SW_SHOWNOACTIVATE  <span style="color: #008000;">=</span> <span style="color: #FF0000;">4</span><span style="color: #008000;">;</span>
  <span style="color: #0600FF;">const</span> <span style="color: #FF0000;">int</span>        SW_SHOW            <span style="color: #008000;">=</span> <span style="color: #FF0000;">5</span><span style="color: #008000;">;</span>
  <span style="color: #0600FF;">const</span> <span style="color: #FF0000;">int</span>        SW_MINIMIZE        <span style="color: #008000;">=</span> <span style="color: #FF0000;">6</span><span style="color: #008000;">;</span>
  <span style="color: #0600FF;">const</span> <span style="color: #FF0000;">int</span>        SW_SHOWMINNOACTIVE <span style="color: #008000;">=</span> <span style="color: #FF0000;">7</span><span style="color: #008000;">;</span>
  <span style="color: #0600FF;">const</span> <span style="color: #FF0000;">int</span>        SW_SHOWNA          <span style="color: #008000;">=</span> <span style="color: #FF0000;">8</span><span style="color: #008000;">;</span>
  <span style="color: #0600FF;">const</span> <span style="color: #FF0000;">int</span>        SW_RESTORE         <span style="color: #008000;">=</span> <span style="color: #FF0000;">9</span><span style="color: #008000;">;</span>
  <span style="color: #0600FF;">const</span> <span style="color: #FF0000;">int</span>        SW_SHOWDEFAULT     <span style="color: #008000;">=</span> <span style="color: #FF0000;">10</span><span style="color: #008000;">;</span>
  <span style="color: #0600FF;">const</span> <span style="color: #FF0000;">int</span>        SW_FORCEMINIMIZE   <span style="color: #008000;">=</span> <span style="color: #FF0000;">11</span><span style="color: #008000;">;</span>
  <span style="color: #0600FF;">const</span> <span style="color: #FF0000;">int</span>        SW_MAX             <span style="color: #008000;">=</span> <span style="color: #FF0000;">11</span><span style="color: #008000;">;</span></pre></div></div>

<p>These constants can be used to call <em>ShowWindow()</em>.  So in our origional example of <em>Form.Show()</em>, the P/Invoked way of doing this would be:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">ShowWindow<span style="color: #000000;">&#40;</span>Form.<span style="color: #0000FF;">Handle</span>, SW_SHOW<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p>This isn&#8217;t nearly as clean as the Object-Oriented way of using<em> Form.Show()</em>, but this is what is actually happening under the hood of .NET.</p>
<p><strong>Why would I ever want something so overly complicated?</strong></p>
<p><em>ShowWindow</em> is an example of an API that has been wrapped nicely by the .NET CLR, it is unlikely that you will ever need to import and call it.  But something more useful might be: <a href="http://www.daveamenta.com/2008-05/c-delete-a-file-to-the-recycle-bin/" target="_blank">Deleting a file to the recycle bin</a>.</p>
<p><strong>What resources are out there for PInvoking?</strong></p>
<p>The best resource I have found is <a href="http://www.pinvoke.net" target="_blank">PInvoke.net</a>, which has declarations for both VB.NET and C# for commonly used Win32 API.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.daveamenta.com/2008-05/what-is-pinvoke-pinvoke/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
