<?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>Ticklish Techs</title>
	<atom:link href="http://www.ticklishtechs.net/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ticklishtechs.net</link>
	<description>a mostly .NET but also some other cool techs blog</description>
	<lastBuildDate>Thu, 04 Mar 2010 17:47:47 +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>Be careful when using GetCallingAssembly() and always use the release build for testing</title>
		<link>http://www.ticklishtechs.net/2010/03/04/be-careful-when-using-getcallingassembly-and-always-use-the-release-build-for-testing/</link>
		<comments>http://www.ticklishtechs.net/2010/03/04/be-careful-when-using-getcallingassembly-and-always-use-the-release-build-for-testing/#comments</comments>
		<pubDate>Thu, 04 Mar 2010 17:46:24 +0000</pubDate>
		<dc:creator>Benjamin Schröter</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[debugging]]></category>
		<category><![CDATA[dotnet]]></category>
		<category><![CDATA[dotnet3.5]]></category>

		<guid isPermaLink="false">http://www.ticklishtechs.net/2010/03/04/be-careful-when-using-getcallingassembly-and-always-use-the-release-build-for-testing/</guid>
		<description><![CDATA[This looks like such a innocent method but it lead to big trouble in one of my projects. But lets start with when someone would use this method that is declared as a static method in the Assembly class. In the MSDN you can read:
Returns the Assembly of the method that invoked the currently executing [...]]]></description>
			<content:encoded><![CDATA[<p>This looks like such a innocent method but it lead to big trouble in one of my projects. But lets start with when someone would use this method that is declared as a static method in the <code>Assembly</code> class. In the MSDN you can <a href="http://msdn.microsoft.com/en-us/library/system.reflection.assembly.getcallingassembly.aspx">read</a>:</p>
<blockquote><p>Returns the Assembly of the method that invoked the currently executing method.</p></blockquote>
<p>In our project we had an assembly with a lot of helper methods. On of these gets resources from the calling assembly. In various places of our code we called this method to get icons or other resources. This method used exactly this <code>GetCallingAssembly()</code> method to figure out what assembly to look for resources.</p>
<p>That worked pretty good in debug mode but exceptions were thrown in release mode. We could not understand what is going on. It became even worse: when we build a release version and tried to debug that version (using Visual Studio Debugger) in worked again. It looked like a <a href="http://en.wikipedia.org/wiki/Heisenbug#Heisenbug">heisenbug</a>.</p>
<p>It took us some time to figure out what is also written in <a href="http://msdn.microsoft.com/en-us/library/system.reflection.assembly.getcallingassembly%28VS.85%29.aspx">MSDN</a>:</p>
<blockquote><p>If the method that calls the <code>GetCallingAssembly</code> method is expanded inline by the compiler (that is, if the compiler inserts the function body into the emitted Microsoft intermediate language (MSIL), rather than emitting a function call), then the assembly returned by the <code>GetCallingAssembly</code> method is the assembly containing the inline code. This might be different from the assembly that contains the original method. To ensure that a method that calls the <code>GetCallingAssembly</code> method is not inlined by the compiler, you can apply the <code>MethodImplAttribute</code> attribute with <code>MethodImplOptions.NoInlining</code>.</p></blockquote>
<p>The JIT compiler moves code around to optimize for performance. Small methods (up to about 56 Byte IL-Code if I remember it right) can be inlined where the method call was before. But the compiler does this only in release, not in debug mode. Also when attaching the debugger to our release build the JIT compiler stopped inlining to enable debugging and our bug was gone.</p>
<p>After understanding this, the fix is easy. Just don’t allow the compiler to inline that particular method that calls <code>Assembly.GetCallingAssembly()</code>. Then the method stays in the assembly where the source code is written and everything will be fine.</p>
<pre class="code">[<span style="color: #2b91af;">MethodImplAttribute</span>(<span style="color: #2b91af;">MethodImplOptions</span>.NoInlining)]
<span style="color: blue;">public void </span>SomeFunction(<span style="color: blue;">int </span>i)
{
    <span style="color: green;">// ...
    </span><span style="color: blue;">var </span>a = <span style="color: #2b91af;">Assembly</span>.GetCallingAssembly();
    <span style="color: green;">// ...
</span>}</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>This attribute does the trick and I recommend to use it on all methods that call <code>GetCallingAssembly()</code> and can be called form another assembly and need the <em>real </em>calling assembly.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ticklishtechs.net/2010/03/04/be-careful-when-using-getcallingassembly-and-always-use-the-release-build-for-testing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A Change event for Dependency Properties</title>
		<link>http://www.ticklishtechs.net/2010/02/15/a-change-event-for-dependency-properties/</link>
		<comments>http://www.ticklishtechs.net/2010/02/15/a-change-event-for-dependency-properties/#comments</comments>
		<pubDate>Mon, 15 Feb 2010 11:38:16 +0000</pubDate>
		<dc:creator>Benjamin Schröter</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[dotnet]]></category>
		<category><![CDATA[dotnet3.5]]></category>
		<category><![CDATA[wpf]]></category>

		<guid isPermaLink="false">http://www.ticklishtechs.net/2010/02/15/a-change-event-for-dependency-properties/</guid>
		<description><![CDATA[WPF comes with Dependency Properties and everybody using WPF will know about these new kind of properties. When you define your own Dependency Properties in your own class you can pretty easy add a property change event handler:
public int MyProperty
{
    get { return (int)GetValue(MyPropertyProperty); }
    set { SetValue(MyPropertyProperty, value); [...]]]></description>
			<content:encoded><![CDATA[<p>WPF comes with Dependency Properties and everybody using WPF will know about these new kind of properties. When you define your own Dependency Properties in your own class you can pretty easy add a property change event handler:</p>
<pre class="code"><span style="color: blue;">public int </span>MyProperty
{
    <span style="color: blue;">get </span>{ <span style="color: blue;">return </span>(<span style="color: blue;">int</span>)GetValue(MyPropertyProperty); }
    <span style="color: blue;">set </span>{ SetValue(MyPropertyProperty, <span style="color: blue;">value</span>); }
}
<span style="color: blue;">public static readonly </span><span style="color: #2b91af;">DependencyProperty </span>MyPropertyProperty =
    <span style="color: #2b91af;">DependencyProperty</span>.Register(<span style="color: #a31515;">"MyProperty"</span>,
                        <span style="color: blue;">typeof</span>(<span style="color: blue;">int</span>),
                        <span style="color: blue;">typeof</span>(<span style="color: #2b91af;">MainWindow</span>),
                        <span style="color: blue;">new </span><span style="color: #2b91af;">UIPropertyMetadata</span>(0,
                            <strong>MyPropertyvalueChangeCallback</strong>));

<span style="color: blue;">private static void </span><strong>MyPropertyvalueChangeCallback</strong>
                        (<span style="color: #2b91af;">DependencyObject </span>d,
                         <span style="color: #2b91af;">DependencyPropertyChangedEventArgs </span>e)
{
}</pre>
<p>But how to add such a event handler to an already existing Dependency Property or somewhere else then in the defining class? E.g. to an property of a WPF-Control that was not build by you. Take a standard WPF-TextBox; both the <code>Text</code> and the <code>FontSize</code> properties are Dependency Properties but the <code>TextBox</code>-class only provides a change event for the <code>Text</code>-property. Nevertheless you can get a change event for any Dependency Property:</p>
<pre class="code"><span style="color: #2b91af;">DependencyPropertyDescriptor </span>dpd =
    <span style="color: #2b91af;">DependencyPropertyDescriptor</span>.FromProperty
        (<span style="color: #2b91af;">Control</span>.FontSizeProperty, <span style="color: blue;">typeof </span>(<span style="color: #2b91af;">TextBox</span>));
dpd.AddValueChanged(someTextBox, SomeTextBoxFontSizeChanged);</pre>
<p>Every time the FontSizeProperty on the instance <code>someTextBox</code> changes the given method is called. It’s that easy and you can implement this code everywhere not only within the class that defines the property.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ticklishtechs.net/2010/02/15/a-change-event-for-dependency-properties/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Foxit Reader vs. Acrobat Reader: the default program problem</title>
		<link>http://www.ticklishtechs.net/2010/02/07/foxit-reader-vs-acrobat-reader-the-default-program-problem/</link>
		<comments>http://www.ticklishtechs.net/2010/02/07/foxit-reader-vs-acrobat-reader-the-default-program-problem/#comments</comments>
		<pubDate>Sun, 07 Feb 2010 11:52:12 +0000</pubDate>
		<dc:creator>Benjamin Schröter</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[foxit]]></category>
		<category><![CDATA[pdf]]></category>
		<category><![CDATA[windows7]]></category>

		<guid isPermaLink="false">http://www.ticklishtechs.net/2010/02/07/foxit-reader-vs-acrobat-reader-the-default-program-problem/</guid>
		<description><![CDATA[I’m a big fan of the Foxit pdf Reader. It is just so damn fast in comparison to Acrobat Reader when opening pdf documents. Yesterday I had to go through a bunch of pdfs each containing only one or two pages to find a specific one. While waiting for Acrobat Reader to open a file [...]]]></description>
			<content:encoded><![CDATA[<p>I’m a big fan of the <a href="http://www.foxitsoftware.com/pdf/reader/">Foxit pdf Reader</a>. It is just so damn fast in comparison to Acrobat Reader when opening pdf documents. Yesterday I had to go through a bunch of pdfs each containing only one or two pages to find a specific one. While waiting for Acrobat Reader to open a file I could open, check an close a few files with Foxit. If you are not using Foxit Reader give it a try&#8230;</p>
<p>But for some pdf features you will need the original Adobe Reader. E.g. some documents with fields to enter data, with scripts or DRM secured files won’t open in Foxit.</p>
<p>I always have both installed on my machine and Foxit is the default application for opening pdf documents. But this setting changed some time ago on my Windows 7 64 bit machine.</p>
<p>I reset the default program for pdf in windows control panel to Foxit and all icons of pdf documents changed to the Foxit one. I can double click a file and Foxit opens&#160; &#8211; great. But in the very moment Foxit comes up the default program is set to Acrobat Reader again. This happens all the time.</p>
<p>I’m not sure what’s going on here and what is involved. I was blaming Acrobat and searched for a solution on the Acrobat side of the problem. Nothing.</p>
<p>In the end an update of Foxit to the current version fixes my problems.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ticklishtechs.net/2010/02/07/foxit-reader-vs-acrobat-reader-the-default-program-problem/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Don&#8217;t respect .inf-files too much</title>
		<link>http://www.ticklishtechs.net/2010/01/19/dont-respect-inf-files-too-much/</link>
		<comments>http://www.ticklishtechs.net/2010/01/19/dont-respect-inf-files-too-much/#comments</comments>
		<pubDate>Mon, 18 Jan 2010 23:50:55 +0000</pubDate>
		<dc:creator>Wolfram Bernhardt</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[administration]]></category>
		<category><![CDATA[driver]]></category>
		<category><![CDATA[windows7]]></category>

		<guid isPermaLink="false">http://www.ticklishtechs.net/2010/01/19/dont-respect-inf-files-too-much/</guid>
		<description><![CDATA[When I get a new laptop that always triggers a little cascade in my home network. I have three machines: An older laptop serves as a server, a quadcore desktop pc provides gaming power and the a newer laptop accompanies me wherever I go.
Some day ago I replaced the old server laptop (with WinXP) by [...]]]></description>
			<content:encoded><![CDATA[<p>When I get a new laptop that always triggers a little cascade in my home network. I have three machines: An older laptop serves as a server, a quadcore desktop pc provides gaming power and the a newer laptop accompanies me wherever I go.</p>
<p>Some day ago I replaced the old server laptop (with WinXP) by a newer one, now running Win7.&#160; My printer (<a href="http://www.brother.de/g3.cfm/s_page/65190/s_level/24390/s_product/DCP120CG1">Brother DCP-120C</a>) is a little aged now and it’s not a network printer. So I attached it to the server (via USB) and thus it’s accessible in the entire network.</p>
<p>Attaching the printer to Win7 worked flawlessly. Importing the printer (which involves copying the drivers) to another Win7-machine was not a problem either.</p>
<p>But my quadcore still runs WinXP and wouldn’t accept the drivers from the Win7-server. Instead a dialog asks me to provide the appropriate driver manually.</p>
<p>Okay, so I downloaded the latest DCP-120C-drivers for WinXP, unzipped them and guided XP to the .inf-files. XP said: “No, I can’t see the right drivers.”</p>
<p>Unfortunately there is no way to force WinXP to use certain printer-drivers. So I spend ten minutes playing the old yes-no-game before I took a look at the .inf-file. I have never dealt with .inf-files a lot but I noticed this line:</p>
<p><font face="Courier New">     <br /></font><font face="Courier New"><strong>&quot;Brother DCP-120C Printer&quot;&#160;&#160; = BRDP120C.PPD, BrotherDCP-120C65FA</strong>       <br /></font></p>
<p>Hmm… okay… it is there. My Brother DCP-120C Printer. Fine. Why doesn’t WinXP recognize it? I found another .inf-file in the driver-package with these line:</p>
<p><font face="Courier New">     <br /></font><font face="Courier New"><strong>&quot;Brother DCP-120C USB Printer&quot;&#160;&#160; = BRDP120C.PPD…        <br /></strong></font></p>
<p>Hmm… now the name is DCP-120C <strong>USB</strong> Printer. Do the funny name string make any dfference? I took a closer look at the printer device that was recognized by my server:</p>
<p><a href="http://www.ticklishtechs.net/wp-content/uploads/2010/01/image1.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.ticklishtechs.net/wp-content/uploads/2010/01/image_thumb1.png" width="121" height="129" /></a> </p>
<p>Okay, nice, there is no “Printer” in the name… can it be… well… I copied the line in the .inf-file and replaced “Printer” by “USB”:</p>
<p><font face="Courier New"><strong>&quot;Brother DCP-120C Printer&quot;&#160;&#160; = BRDP120C.PPD, BrotherDCP-120C65FA</strong>       <br /></font><font face="Courier New"><strong>&quot;Brother DCP-120C USB&quot;&#160;&#160; = BRDP120C.PPD, BrotherDCP-120C65FA</strong> </font></p>
<p><font face="Courier New"></font></p>
<p>Bingo! That did the trick. </p>
<p>When accessing printers installed on other network computers, the printer drivers really seem to be recognized by their name. That hurts a bit, but knowing it may help solving driver problem from time to time.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ticklishtechs.net/2010/01/19/dont-respect-inf-files-too-much/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>VMWare Workstation demands Administrator rights &#8211; even if you have those</title>
		<link>http://www.ticklishtechs.net/2010/01/19/vmware-workstation-demands-administrator-rights-even-if-you-have-those/</link>
		<comments>http://www.ticklishtechs.net/2010/01/19/vmware-workstation-demands-administrator-rights-even-if-you-have-those/#comments</comments>
		<pubDate>Mon, 18 Jan 2010 22:53:09 +0000</pubDate>
		<dc:creator>Wolfram Bernhardt</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[administration]]></category>
		<category><![CDATA[VMWare]]></category>

		<guid isPermaLink="false">http://www.ticklishtechs.net/2010/01/19/vmware-workstation-demands-administrator-rights-even-if-you-have-those/</guid>
		<description><![CDATA[Whenever I move my system to a new laptop I create a virtual machine from my old system. Sometimes it is easier to access stuff I forget to copy from a running system than from mounted backup devices.
To create virtual machines from a running system I use VMWare Workstation, which outperforms VirtualPC by far (imho).
Some [...]]]></description>
			<content:encoded><![CDATA[<p>Whenever I move my system to a new laptop I create a virtual machine from my old system. Sometimes it is easier to access stuff I forget to copy from a running system than from mounted backup devices.</p>
<p>To create virtual machines from a running system I use <a href="http://www.vmware.com/products/workstation/">VMWare Workstation</a>, which outperforms VirtualPC by far (imho).</p>
<p>Some days ago I tried to create a VM from a Win7/64 system. I was quiet surprised when VMWare Workstation told me, I needed Administrator rights:</p>
<p><a href="http://www.ticklishtechs.net/wp-content/uploads/2010/01/image.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.ticklishtechs.net/wp-content/uploads/2010/01/image_thumb.png" width="474" height="405" /></a> </p>
<p>&#160;</p>
<p>So what – I have administrative rights. But the Workstation didn’t believe me. Since that held me from moving to my new laptop I was really p*ssed.</p>
<p><a href="http://communities.vmware.com/thread/232530;jsessionid=AA54EA753EB5F4F329275A1F7112657F">Luckily some smart guy found this solution.</a></p>
<p>I think this is clearly a bug, but so far VmWare Workstation demand Administrator-rights in the literal sense: It only accepts, when you are logged in as THE Administrator:</p>
<ul>
<li>start <font face="Courier New">c:\Windows\system32\cmd.exe</font> from explorer using &quot;execute as administrator&quot;. </li>
<li>type <font face="Courier New">net user Administrator /active:yes</font></li>
<li>logoff &amp; reboot </li>
<li>login as Administrator </li>
<li>create your image </li>
<li>Complain at <a href="http://www.vmware.com/support/contacts/file-sr.html">VMWare</a>. </li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.ticklishtechs.net/2010/01/19/vmware-workstation-demands-administrator-rights-even-if-you-have-those/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Acronis True Image Home 2010 hangs with Windows 7</title>
		<link>http://www.ticklishtechs.net/2010/01/19/acronis-true-image-home-2010-hangs-with-windows-7/</link>
		<comments>http://www.ticklishtechs.net/2010/01/19/acronis-true-image-home-2010-hangs-with-windows-7/#comments</comments>
		<pubDate>Mon, 18 Jan 2010 22:17:32 +0000</pubDate>
		<dc:creator>Wolfram Bernhardt</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Acronis True Image]]></category>
		<category><![CDATA[driver]]></category>
		<category><![CDATA[internet]]></category>
		<category><![CDATA[windows7]]></category>

		<guid isPermaLink="false">http://www.ticklishtechs.net/2010/01/19/acronis-true-image-home-2010-hangs-with-windows-7/</guid>
		<description><![CDATA[I am a great fan of Acronis True Image. I am using it for a long time and it has saved my skin more than once. So I was glad to hear that the new version (True Image 2010) was designed to work with Win 7. And so it did.
Last week I got a new [...]]]></description>
			<content:encoded><![CDATA[<p>I am a great fan of Acronis True Image. I am using it for a long time and it has saved my skin more than once. So I was glad to hear that the new version (<a href="http://www.acronis.de/homecomputing/products/trueimage/index.html">True Image 2010</a>) was designed to work with Win 7. And so it did.</p>
<p>Last week I got a new laptop and today I tried to backup my fresh installation ov Win7/64. Each time True Image caused my entire system to freeze after five seconds of backing up. No reaction at all, the only way out way a hard button-press reset. I tried different options without results. (Which made me panic, because on what else can you rely when not on your backup tool?) &#8211; </p>
<p><a href="http://kb.acronis.com/content/6529">Fortunately I found the solution here.</a> </p>
<p>There is a new driver for hdd-image snapshots. Installed it, True Image 2010 works again. </p>
<p>Phew!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ticklishtechs.net/2010/01/19/acronis-true-image-home-2010-hangs-with-windows-7/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Shell-Lib reloaded: Another OS, another bug.</title>
		<link>http://www.ticklishtechs.net/2010/01/10/shell-lib-reloaded-another-os-another-bug/</link>
		<comments>http://www.ticklishtechs.net/2010/01/10/shell-lib-reloaded-another-os-another-bug/#comments</comments>
		<pubDate>Sun, 10 Jan 2010 14:38:06 +0000</pubDate>
		<dc:creator>Wolfram Bernhardt</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[dotnet]]></category>
		<category><![CDATA[marshalling]]></category>
		<category><![CDATA[windows7]]></category>

		<guid isPermaLink="false">http://www.ticklishtechs.net/2010/01/10/shell-lib-reloaded-another-os-another-bug/</guid>
		<description><![CDATA[Some time ago we blogged about a nifty little .net assembly that enables you to access the basic Windows shell operations in shell32.dll . You may want to do so especially in Win7 because your file operations integrate with the fancy Win7 dialogs, the flashing progress bar etc. 
The problem we blogged about in the [...]]]></description>
			<content:encoded><![CDATA[<p>Some time ago we blogged about a nifty little .net assembly that enables you to access the basic <a href="http://www.ticklishtechs.net/2007/09/02/windows-shell32dll-shfileoperation-marshalling-and-hnamemappings/">Windows shell operations</a> in shell32.dll . You may want to do so especially in Win7 because your file operations integrate with the fancy Win7 dialogs, the flashing progress bar etc. </p>
<p>The problem we blogged about in <a href="http://www.ticklishtechs.net/2007/09/02/windows-shell32dll-shfileoperation-marshalling-and-hnamemappings/">the former post</a> was a missing &quot;Pack&quot;-instruction in the marshalling-description of a structure. I guess we didn&#8217;t test it with WinXP64&#8230; but some days ago we tests it with Win7/64 and it failed. We figured out that we introduced a new bug that occurred on 64 bit machines only. After some more testing we found out that: </p>
<ul>
<li>The original code (without Pack-value) crashes on 32 bit machines (as described in the former post). </li>
<li>The original code (without Pack-value) works fine on 64 bit machines (but we don&#8217;t think the original developer had 64 bits 7 years ago <img src='http://www.ticklishtechs.net/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />  ). </li>
<li>Our fixed code (with Pack=2) works fine on 32 bit machines. </li>
<li>Our fixed code (with Pack=2) crashes on 64 bit machines. </li>
</ul>
<p>It seems that the &quot;SHFILEOPSTRUCT&quot; structure in shell32.dll has different layouts in Win7/64 and Win7/32. I guess the guys at MS aim for performance and tell the compiler to optimize. The compiler optimizes by assuming the optimal Pack-value, which usually is the byte-width of the processor; 4 for 32bit, 8 for 64bit. </p>
<h3>What effect does the Pack-value have at all?</h3>
<p>The &quot;Pack&quot;-value controls the alignment of the starting addresses of each single member of a structure (often called &quot;offset&quot;). </p>
<p>Let&#8217;s say you have this struct: </p>
<p> <code>
<p>struct MammaMia      <br />{       <br />&#160;&#160;&#160; public int16 sweet16;       <br />&#160;&#160;&#160; public byte bite;       <br />&#160;&#160;&#160; public string tanga;       <br />} </p>
<p> </code>
<p>Usually you don&#8217;t care for the exact way your data is stored in memory, but when you pass it from .NET to the Win-API you have to make sure Win-API receives and returns exactly the right format. This process is called &quot;Marshalling&quot;. </p>
<p>One crucial instruction for doing so is the StructLayout attribute. </p>
<p> <code>
<p>[StructLayout(LayoutKind.Sequential, Pack = 1)]      <br />struct MammaMia       <br />{       <br />&#160;&#160;&#160; public int16 sweet16;       <br />&#160;&#160;&#160; public byte bite;       <br />&#160;&#160;&#160; public string tanga;       <br />} </p>
<p> </code>
<p>(Note: There are a lot more options for the StructLayout attribute and a lot more attributes that help you at marshalling.) </p>
<p><strong>LayoutKind.Sequential</strong> means that your data is represented in memory in the same order as you declared it: First &quot;sweet16&quot;, than &quot;bite&quot; and then &quot;tanga&quot;. </p>
<p><strong>Pack=1</strong> tells .NET that every byte can be the starting point of the next member. So .NET produces this structure in memory:</p>
<p><strong></strong></p>
<table border="0" cellspacing="0" cellpadding="2" width="197">
<tbody>
<tr>
<td valign="top" width="50"><strong>Pack=1</strong></td>
<td valign="top" width="145">&#160;</td>
</tr>
<tr>
<td valign="top" width="50">byte</td>
<td valign="top" width="145">data</td>
</tr>
<tr>
<td valign="top" width="50">0</td>
<td valign="top" width="145">sweet16</td>
</tr>
<tr>
<td valign="top" width="50">1</td>
<td valign="top" width="145">sweet16</td>
</tr>
<tr>
<td valign="top" width="50">2</td>
<td valign="top" width="145">bite</td>
</tr>
<tr>
<td valign="top" width="50">3</td>
<td valign="top" width="145">tanga</td>
</tr>
<tr>
<td valign="top" width="50">4</td>
<td valign="top" width="145">tanga</td>
</tr>
<tr>
<td valign="top" width="50">…</td>
<td valign="top" width="145">…</td>
</tr>
<tr>
<td valign="top" width="50">20</td>
<td valign="top" width="145">last character of tanga</td>
</tr>
</tbody>
</table>
<p>&#160;</p>
<p>&#160;</p>
<p>Now <strong>Pack=2</strong> makes sure that only every 2nd byte can be the starting point of the next member. That leads &#8211; of course &#8211; to unused bytes in memory: </p>
<table border="0" cellspacing="0" cellpadding="2" width="197">
<tbody>
<tr>
<td valign="top" width="50"><strong>Pack=2</strong></td>
<td valign="top" width="145">&#160;</td>
</tr>
<tr>
<td valign="top" width="50">byte</td>
<td valign="top" width="145">data</td>
</tr>
<tr>
<td valign="top" width="50">0</td>
<td valign="top" width="145">sweet16</td>
</tr>
<tr>
<td valign="top" width="50">1</td>
<td valign="top" width="145">sweet16</td>
</tr>
<tr>
<td valign="top" width="50">2</td>
<td valign="top" width="145">bite</td>
</tr>
<tr>
<td valign="top" width="50">3</td>
<td valign="top" width="145">??? (unused)</td>
</tr>
<tr>
<td valign="top" width="50">4</td>
<td valign="top" width="145">tanga</td>
</tr>
<tr>
<td valign="top" width="50">5</td>
<td valign="top" width="145">tanga</td>
</tr>
<tr>
<td valign="top" width="50">…</td>
<td valign="top" width="145">…</td>
</tr>
<tr>
<td valign="top" width="50">21</td>
<td valign="top" width="145">last character of tanga</td>
</tr>
</tbody>
</table>
<p>&#160;</p>
<p>&#160;</p>
<p>The higher the Pack-value, the more unused bytes you get:</p>
<table border="0" cellspacing="0" cellpadding="2" width="197">
<tbody>
<tr>
<td valign="top" width="50"><strong>Pack=4</strong></td>
<td valign="top" width="145">&#160;</td>
</tr>
<tr>
<td valign="top" width="50">byte</td>
<td valign="top" width="145">data</td>
</tr>
<tr>
<td valign="top" width="50">0</td>
<td valign="top" width="145">sweet16</td>
</tr>
<tr>
<td valign="top" width="50">1</td>
<td valign="top" width="145">sweet16</td>
</tr>
<tr>
<td valign="top" width="50">2</td>
<td valign="top" width="145">??? (unused)</td>
</tr>
<tr>
<td valign="top" width="50">3</td>
<td valign="top" width="145">??? (unused)</td>
</tr>
<tr>
<td valign="top" width="50">4</td>
<td valign="top" width="145">bite</td>
</tr>
<tr>
<td valign="top" width="50">5</td>
<td valign="top" width="145">??? (unused)</td>
</tr>
<tr>
<td valign="top" width="50">6</td>
<td valign="top" width="145">??? (unused)</td>
</tr>
<tr>
<td valign="top" width="50">7</td>
<td valign="top" width="145">??? (unused)</td>
</tr>
<tr>
<td valign="top" width="50">8</td>
<td valign="top" width="145">tanga</td>
</tr>
<tr>
<td valign="top" width="50">9</td>
<td valign="top" width="145">tanga</td>
</tr>
<tr>
<td valign="top" width="50">…</td>
<td valign="top" width="145">…</td>
</tr>
<tr>
<td valign="top" width="50">25</td>
<td valign="top" width="145">last character of tanga</td>
</tr>
</tbody>
</table>
<p>&#160;</p>
<p>Is this a waste of memory? Sure. But processors can access those addresses a bit faster than other addresses. So it&#8217;s an performance/memory tradeoff. </p>
<p>After some more testing, I figured out that the correct Pack-value for Win7/64 is 8, while the correct Pack-value for Win7/32 is 2 (see former post). Why 2? I&#8217;d expect 4 here. I don&#8217;t know and Microsoft wouldn&#8217;t provide the source code I guess.    <br />Maybe in former Windows version they preferred a middle-course between performance and saving memory. </p>
<h3>The simple solution</h3>
<p>Now it was obvious how to make die ShellLib-assembly work with 32 and 64bit: Check what machine we run on and use a different marshalling. Since I had to declare different structs here, the major code is copying data back and forth, not very interesting.</p>
<p>The only interesting part here is: How do you check on what kind of machine you run? I was looking for some property at System.Environment, but didn’t find anything. Then <a href="http://blog.aheil.de/">Andreas</a> pointed me to <a href="http://blogs.msdn.com/kstanton/archive/2004/04/20/116923.aspx">this</a> post and the solution is too simple to cross one’s mind:</p>
<p>“Just do a <strong>IntPtr.Size</strong> (static method) and since IntPtr is designed to be an integer whose size is platform specific, it will be <strong>8 if you are on a 64-bit machine and 4 if you are on a 32-bit machine</strong>.“</p>
<p>You can find more information and our fixed code soon at the <a href="http://www.codeproject.com/KB/shell/csdoesshell2.aspx">codeproject.com</a> .</p>
<h3>Epilog</h3>
<p>You can also do the marshalling all by yourself, starting with memory allocation and ending with freeing memory, just like in the old times. But this is another story and will be told later. </p>
<p>Maybe.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ticklishtechs.net/2010/01/10/shell-lib-reloaded-another-os-another-bug/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Lenovo Integrated Camera again working on Windows 7</title>
		<link>http://www.ticklishtechs.net/2010/01/01/lenovo-integrated-camera-again-working-on-windows-7/</link>
		<comments>http://www.ticklishtechs.net/2010/01/01/lenovo-integrated-camera-again-working-on-windows-7/#comments</comments>
		<pubDate>Fri, 01 Jan 2010 11:56:09 +0000</pubDate>
		<dc:creator>Benjamin Schröter</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[driver]]></category>
		<category><![CDATA[Lenovo]]></category>
		<category><![CDATA[windows]]></category>
		<category><![CDATA[windows7]]></category>

		<guid isPermaLink="false">http://www.ticklishtechs.net/2010/01/01/lenovo-integrated-camera-again-working-on-windows-7/</guid>
		<description><![CDATA[My Lenovo X200 notebook comes with an integrated webcam and I’m using it pretty often for Skype calls etc. But some time ago it stopped working. After reinstalling drivers, taking to the Lenovo support hotline, installing exactly the driver I was told to it was still broken. Yesterday a Lenovo technician cam to replace the [...]]]></description>
			<content:encoded><![CDATA[<p>My Lenovo X200 notebook comes with an integrated webcam and I’m using it pretty often for Skype calls etc. But some time ago it stopped working. After reinstalling drivers, taking to the Lenovo support hotline, installing exactly the driver I was told to it was still broken. Yesterday a Lenovo technician cam to replace the camera (I’m so glad to have on-site support and do not need to send the notebook in), but in the end the new webcam behaves exactly as the first one &#8211; just not working.</p>
<p>So I started to debug the problem by myself and figured the following out. Maybe this is just an issue on my machine with my other software installed but maybe this is helpful for someone else.</p>
<p>The driver from the Lenovo webpage is build by the camera vendor Ricoh. That driver package just does not work on my Windows 7 64bit machine. The out-of-the-box Windows 7 driver works just fine!</p>
<p>Find the Camera device in Device Manager</p>
<p><a href="http://www.ticklishtechs.net/wp-content/uploads/2010/01/a.png"><img style="display: inline; border: 0px;" title="device manager" src="http://www.ticklishtechs.net/wp-content/uploads/2010/01/a_thumb.png" border="0" alt="device manager" width="240" height="188" /></a></p>
<p>On the properties sheet choose Update driver</p>
<p><a href="http://www.ticklishtechs.net/wp-content/uploads/2010/01/b.png"><img style="display: inline; border: 0px;" title="Integrated Camera Properties" src="http://www.ticklishtechs.net/wp-content/uploads/2010/01/b_thumb.png" border="0" alt="Integrated Camera Properties" width="328" height="364" /></a></p>
<p>Then “Browse my computer for driver software” and  “Let me pick from a list of device drivers on my computer”</p>
<p><a href="http://www.ticklishtechs.net/wp-content/uploads/2010/01/d.png"><img style="display: inline; border: 0px;" title="Update Driver Software I" src="http://www.ticklishtechs.net/wp-content/uploads/2010/01/d_thumb.png" border="0" alt="Update Driver Software I" width="364" height="268" /></a></p>
<p><a href="http://www.ticklishtechs.net/wp-content/uploads/2010/01/e.png"><img style="display: inline; border: 0px;" title="Update Driver Software II" src="http://www.ticklishtechs.net/wp-content/uploads/2010/01/e_thumb.png" border="0" alt="Update Driver Software II" width="364" height="268" /></a></p>
<p>On my machine it only shows up one compatible “USB Video Device” – just use that driver:</p>
<p><a href="http://www.ticklishtechs.net/wp-content/uploads/2010/01/f.png"><img style="display: inline; border: 0px;" title="Update Driver Software III" src="http://www.ticklishtechs.net/wp-content/uploads/2010/01/f_thumb.png" border="0" alt="Update Driver Software III" width="364" height="268" /></a></p>
<p>If Windows does not find this single one you can select it from the larger list by unchecking “Show compatible hardware” and choosing “Microsoft” / “USB Video Device”:</p>
<p><a href="http://www.ticklishtechs.net/wp-content/uploads/2010/01/g.png"><img style="display: inline; border: 0px;" title="Update Driver Software VI" src="http://www.ticklishtechs.net/wp-content/uploads/2010/01/g_thumb.png" border="0" alt="Update Driver Software VI" width="364" height="268" /></a></p>
<p>For some reason it does not always work the moment I installed the new driver and I had to reboot the machine. After installing the driver the device in device manager is called “USB Video Device” but after the reboot it is for some reason renamed to “Integrated Camera” but still using the Windows driver (that is the important part, you can check it in the properties sheet from within device manager). From now on it was working fine.</p>
<p>After some time Windows suddenly replaced this driver with the Ricoh one and the camera was broken again. To prevent Windows from doing so I uninstalled the driver package from “Programs and Features” in Control Panel.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ticklishtechs.net/2010/01/01/lenovo-integrated-camera-again-working-on-windows-7/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Trackpoint Scrolling in iTunes, Thunderbird, etc.</title>
		<link>http://www.ticklishtechs.net/2009/12/27/trackpoint-scrolling-in-itunes-thunderbird-etc/</link>
		<comments>http://www.ticklishtechs.net/2009/12/27/trackpoint-scrolling-in-itunes-thunderbird-etc/#comments</comments>
		<pubDate>Sun, 27 Dec 2009 07:51:00 +0000</pubDate>
		<dc:creator>Benjamin Schröter</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[driver]]></category>
		<category><![CDATA[Lenovo]]></category>
		<category><![CDATA[thunderbird]]></category>
		<category><![CDATA[Trackpoint]]></category>

		<guid isPermaLink="false">http://www.ticklishtechs.net/2009/12/27/trackpoint-scrolling-in-itunes-thunderbird-etc/</guid>
		<description><![CDATA[I’m using a Lenovo laptop and I’m a big fan of the Trackpoint mouse replacement. That is this small red thing in the middle of the keyboard some notebooks are equipped with instead of a touchpad. In fact my notebook does not even has a touchpad. 
You can use the Trackpoint for scrolling like a [...]]]></description>
			<content:encoded><![CDATA[<p>I’m using a Lenovo laptop and I’m a big fan of the <a href="http://xkcd.com/243/">Trackpoint</a> mouse replacement. That is this small red thing in the middle of the keyboard some notebooks are equipped with instead of a touchpad. In fact my notebook does not even has a touchpad. </p>
<p>You can use the Trackpoint for scrolling like a mouse wheel when pressing the middle button and moving the Trackpoint up or down. Everybody using it will know what I’m talking about, anybody else does not need to read to the end. </p>
<p>But in some applications the scrolling does not work at all what is very annoying. I had the most trouble with Thunderbird and iTunes – just no scrolling. </p>
<p>And here is a fix for that issue. There is a file (<code>C:\Program Files\Lenovo\ TrackPoint\tp4table.dat</code>) on your machine when you have installed the Trackpoint software from Lenovo. Just edit that file and add some additional rows for the application with broken scrolling. </p>
<table border="1">
<tbody>
<tr>
<td>
<pre>; Apple ITunes
*,*,itunes.exe,*,*,*,WheelStd,0,9

; Mozilla Thunderbird
*,*,thunderbird.exe,*,*,*,WheelStd,0,9</pre>
</td>
</tr>
</tbody>
</table>
<p>&#160;</p>
<p>Remember to open the file with an editor as Administrator otherwise it would not work. I had to reboot my machine after that change. I just tested this change on a Windows 7 64 bit machine but it should work on 32 bit or other versions of Windows as well. Maybe the same fix applies also to non-Lenovo notebooks but I cannot tell. If someone out there tested it, please comment.</p>
<p>More on this topic and templates for some more applications (Picasa, Safar, Windows Live Mail, Windows Live Writer) can be found at <a title="http://forums.lenovo.com/t5/X-Series-ThinkPad-Laptops/Fixing-Trackpoint-Scroll-for-ITunes-Picasa-Safari-Windows-Live/m-p/124378" href="http://forums.lenovo.com/t5/X-Series-ThinkPad-Laptops/Fixing-Trackpoint-Scroll-for-ITunes-Picasa-Safari-Windows-Live/m-p/124378">http://forums.lenovo.com/t5/X-Series-ThinkPad-Laptops/Fixing-Trackpoint-Scroll-for-ITunes-Picasa-Safari-Windows-Live/m-p/124378</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ticklishtechs.net/2009/12/27/trackpoint-scrolling-in-itunes-thunderbird-etc/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How to get a IWin32Window from a WPF Window?</title>
		<link>http://www.ticklishtechs.net/2009/12/22/how-to-get-a-iwin32window-from-a-wpf-window/</link>
		<comments>http://www.ticklishtechs.net/2009/12/22/how-to-get-a-iwin32window-from-a-wpf-window/#comments</comments>
		<pubDate>Tue, 22 Dec 2009 12:53:34 +0000</pubDate>
		<dc:creator>Benjamin Schröter</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[dotnet]]></category>
		<category><![CDATA[wpf]]></category>

		<guid isPermaLink="false">http://www.ticklishtechs.net/2009/12/22/how-to-get-a-iwin32window-from-a-wpf-window/</guid>
		<description><![CDATA[When building applications that mix WPF and Winforms windows (e.g. because you are using a Winforms dialog within a WPF application) you will sometimes need a System.Windows.Forms.IWin32Window interface from an WPF System.Windows.Window. This will be useful when using the WinForms OpenFileDialog and wanting to provide a parent window to the ShowDialog() method that only accepts [...]]]></description>
			<content:encoded><![CDATA[<p>When building applications that mix WPF and Winforms windows (e.g. because you are using a Winforms dialog within a WPF application) you will sometimes need a <a title="IWin32Window Interface" href="http://msdn2.microsoft.com/215475ec.aspx">System.Windows.Forms.IWin32Window</a> interface from an WPF <a title="Window Class" href="http://msdn2.microsoft.com/ms590112.aspx">System.Windows.Window</a>. This will be useful when using the WinForms <a title="OpenFileDialog Class" href="http://msdn2.microsoft.com/y1kh29w3.aspx">OpenFileDialog</a> and wanting to provide a parent window to the <a title="OpenFileDialog..::.ShowDialog Method " href="http://msdn2.microsoft.com/bb552427.aspx">ShowDialog()</a> method that only accepts IWin32Window as parent.</p>
<p>The <code>IWin32Window</code> interface declares only one read-only property named <code>Handle</code> that must be provided by the WPF Window. </p>
<h3>Implementing the Interface</h3>
<p>It is very simple to just add this interface to an existing WPF Window and implementing the single property:</p>
<pre class="code"><span style="color: blue">public partial class </span><span style="color: #2b91af">Window1 </span>: <span style="color: #2b91af">Window</span>, <span style="color: #2b91af">IWin32Window
</span>{
   <span style="color: blue">public </span><span style="color: #2b91af">IntPtr </span>Handle
   {
      <span style="color: blue">get
      </span>{
         <span style="color: blue">var </span>interopHelper = <span style="color: blue">new </span><span style="color: #2b91af">WindowInteropHelper</span>(<span style="color: blue">this</span>);
         <span style="color: blue">return </span>interopHelper.Handle;
      }
   }
}</pre>
<p>&#160;</p>
<h3>Using a wrapper class</h3>
<p>It does not look as a very good solution to add such an interface to each and every <code>Window</code> in you whole application only to be able to be the parent of a dialog. So instead of implementing the interface directly you could build a wrapper class that implements this interface and use this wrapper when opening a dialog:</p>
<pre class="code"><span style="color: blue">public class </span><span style="color: #2b91af">Wpf32Window </span>: <span style="color: #2b91af">IWin32Window
</span>{
    <span style="color: blue">public </span><span style="color: #2b91af">IntPtr </span>Handle { <span style="color: blue">get</span>; <span style="color: blue">private set</span>; }

    <span style="color: blue">public </span>Wpf32Window(<span style="color: #2b91af">Window </span>wpfWindow)
    {
        Handle = <span style="color: blue">new </span><span style="color: #2b91af">WindowInteropHelper</span>(wpfWindow).Handle;
    }
}</pre>
<p>Opening the dialog will now look like: </p>
<pre class="code">d.ShowDialog( <span style="color: blue">new </span><span style="color: #2b91af">Wpf32Window</span>(<span style="color: blue">this</span>) );</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<h3>The grand solution to this problem</h3>
<p>I like the wrapper solution more than implementing an interface to each and every window but I do not like the changed <code>ShowDialog()</code> call. It just does not look natural any more. To solve this I created an extension Method to be used with the wrapper class:</p>
<pre class="code"><span style="color: blue">public static class </span><span style="color: #2b91af">CommonDialogExtensions
</span>{
    <span style="color: blue">public static </span><span style="color: #2b91af">DialogResult </span>ShowDialog
                               (<span style="color: blue">this </span><span style="color: #2b91af">CommonDialog </span>dialog,
                                     <span style="color: #2b91af">Window </span>parent)
    {
        <span style="color: blue">return </span>dialog.ShowDialog(<span style="color: blue">new </span><span style="color: #2b91af">Wpf32Window</span>(parent));
    }
}</pre>
<p><a href="http://11011.net/software/vspaste"></a>Now the call to open a WinForms dialog with an WPF parent looks as it should look like:</p>
<pre class="code">d.ShowDialog(<span style="color: blue">this</span>);</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ticklishtechs.net/2009/12/22/how-to-get-a-iwin32window-from-a-wpf-window/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
