<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/atom.xsl" media="screen"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-US"><title type="html">Maarten's blog</title><subtitle type="html" /><id>http://blogs.msdn.com/maartenb/atom.xml</id><link rel="alternate" type="text/html" href="http://blogs.msdn.com/maartenb/default.aspx" /><link rel="self" type="application/atom+xml" href="http://blogs.msdn.com/maartenb/atom.xml" /><generator uri="http://communityserver.org" version="2.1.61025.2">Community Server</generator><updated>2008-07-10T21:50:16Z</updated><entry><title>Disabling a Shim (part II)</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/maartenb/archive/2009/07/29/disabling-a-shim-part-ii.aspx" /><id>http://blogs.msdn.com/maartenb/archive/2009/07/29/disabling-a-shim-part-ii.aspx</id><published>2009-07-29T19:15:18Z</published><updated>2009-07-29T19:15:18Z</updated><content type="html">&lt;p&gt;Follow-up from the research on &lt;a href="http://blogs.msdn.com/maartenb/archive/2009/07/24/disabling-a-shim.aspx"&gt;how to disable a per-application shim&lt;/a&gt;. When I saw the output from the shim infrastructure in DebugView, I mistakenly assumed that the application was shimmed. It apparently only means that the application is found in the AppCompat system database. It does &lt;em&gt;not&lt;/em&gt; mean that the shim is actually still in place. 
&lt;/p&gt;&lt;p&gt;Which leaves me with the question, how do I easily verify that an application is not shimmed (short of the earlier mentioned shotgun approach of turning the whole shim engine off)? Someone who does this for a living told me that one way you can tell is whether aclayers.dll is loaded in the process. He also told me that getting an application shim free is not that easy. There are all kinds of watchdogs in the system monitoring and instrumenting applications. 
&lt;/p&gt;&lt;p&gt;When an application entry is disabled in &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=24DA89E9-B581-47B0-B45E-492DD6DA2971&amp;amp;displaylang=en"&gt;ACT&lt;/a&gt;, I see with Process Explorer two environment variables that indicate to me they have something to do with Application Compatibility or shimming:  __COMPAT_LAYER = VistaSetup and SHIM_DEBUG_LEVEL = 9. The last one was added by me for the logging. I also see AcGeneral.dll and apphelp.dll loaded in the process. And it is wrapped in a job (you can tell by looking at the process properties in Process Explorer; there is a Job tab). 
&lt;/p&gt;&lt;p&gt;When I reenable the entry, I see  __COMPAT_LAYER=VistaSetup &lt;strong&gt;WinXPSp2_GW&lt;/strong&gt; and the same SHIM_DEBUG_LEVEL=9. This WinXPSp2_GW matches the entry in the ACT database. This somewhat confirms that disabling an entry does indeed have the desired effect. Also an additional dll was loaded: the before mentioned aclayers.dll. 
&lt;/p&gt;&lt;p&gt;When the &lt;a href="http://msdn.microsoft.com/en-us/library/bb756937.aspx"&gt;PCA&lt;/a&gt; notices your application as a setup, it will flag it in the registry. This was my case and I was thinking maybe, the VistaSetup CompatLayer comes from there. I made sure the application was not flagged anywhere under (\AppCompatFlags\Compatibility Assistant\Persisted.) No difference. VistaSetup was still there. 
&lt;/p&gt;&lt;p&gt;Then I disabled the Program Compatibility Assistant service. The effect of that was that the process is no longer wrapped inside a job. However the service restarts quickly. I had to disable it to make sure it didn't get in the way. Still the VistaSetup was there as an environment variable. 
&lt;/p&gt;&lt;p&gt;My current assumption is that the VistaSetup layer is coming from the fact that there is no Windows 7 &lt;a href="http://msdn.microsoft.com/en-us/library/dd371711(VS.85).aspx"&gt;switchback entry in the manifest&lt;/a&gt;. It apparently is also detected as a setup. I will need to verify it by adding the switchback GUID. That is for next time. &lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9852246" width="1" height="1"&gt;</content><author><name>maartenb</name><uri>http://blogs.msdn.com/members/maartenb.aspx</uri></author></entry><entry><title>Logo doc</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/maartenb/archive/2009/07/28/logo-doc.aspx" /><id>http://blogs.msdn.com/maartenb/archive/2009/07/28/logo-doc.aspx</id><published>2009-07-29T03:09:00Z</published><updated>2009-07-29T03:09:00Z</updated><content type="html">&lt;P&gt;When I go to connect and download the &lt;A href="https://connect.microsoft.com/site/sitehome.aspx?SiteID=831" mce_href="https://connect.microsoft.com/site/sitehome.aspx?SiteID=831"&gt;Windows 7 Software Logo&lt;/A&gt; Requirements v1.7.docx, it downloads a zip file. Unzipping the file gives me a somewhat familiar view. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;IMG src="http://blogs.msdn.com/photos/maartenb/images/9851542/original.aspx" mce_src="http://blogs.msdn.com/photos/maartenb/images/9851542/original.aspx"&gt;&lt;/P&gt;
&lt;P&gt;I've seen this before. This looks like a &lt;A href="http://en.wikipedia.org/wiki/Open_Packaging_Convention" mce_href="http://en.wikipedia.org/wiki/Open_Packaging_Convention"&gt;OPC document&lt;/A&gt;. Since OPC is XML wrapped in Zip format it would make sense. I renamed the file to docx. Now I can open it. &lt;/P&gt;
&lt;P&gt;By the way, what is really nice is that apparently Wordpad is the default handler for docx files on Windows 7. &lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9851544" width="1" height="1"&gt;</content><author><name>maartenb</name><uri>http://blogs.msdn.com/members/maartenb.aspx</uri></author></entry><entry><title>Windows 7 Software Logo Voucher</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/maartenb/archive/2009/07/28/windows-7-software-logo-voucher.aspx" /><id>http://blogs.msdn.com/maartenb/archive/2009/07/28/windows-7-software-logo-voucher.aspx</id><published>2009-07-28T23:43:11Z</published><updated>2009-07-28T23:43:11Z</updated><content type="html">&lt;p&gt;For Windows Vista Logo, we used to have vouchers to entice early adaption. An ISV recently asked me for vouchers for Windows 7. Since Windows 7 is a "self-test" there is no need for a voucher. It is virtually free. The only cost might be that an ISV needs to buy a certificate to log in to winqual (which is where you would submit your test results).
&lt;/p&gt;&lt;p&gt;&lt;a href="https://connect.microsoft.com/site/sitehome.aspx?SiteID=831"&gt;https://connect.microsoft.com/site/sitehome.aspx?SiteID=831&lt;/a&gt;&lt;span style="color:#1f497d"&gt;  
&lt;/span&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9851359" width="1" height="1"&gt;</content><author><name>maartenb</name><uri>http://blogs.msdn.com/members/maartenb.aspx</uri></author></entry><entry><title>What happened to my Search</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/maartenb/archive/2009/07/27/what-happened-to-my-search.aspx" /><id>http://blogs.msdn.com/maartenb/archive/2009/07/27/what-happened-to-my-search.aspx</id><published>2009-07-28T00:56:54Z</published><updated>2009-07-28T00:56:54Z</updated><content type="html">&lt;p&gt;I recently upgraded to Windows 7 RTM. When I hit the Windows key, no search results were being returned. Only standard items from control panel etc. The Windows search service appeared not to be running. When I tried to start the service from services.msc, I got an error:
&lt;/p&gt;&lt;p&gt;
 &lt;/p&gt;&lt;p style="margin-left: 36pt"&gt;Windows could not start the Windows Search service on Local Computer.
&lt;/p&gt;&lt;p style="margin-left: 36pt"&gt;Error 1224: The requested operation cannot be performed on a file with a user-mapped section open.
&lt;/p&gt;&lt;p&gt;Since those things always happen when you're urgently working on something else, I decided to just uninstall and reinstall Windows Search from "Turn Windows Features on or off". After a reboot, I was surprised to find that hitting the Windows key resulted in the start menu opening without the search box. It is also fascinating how reliant one becomes on just typing a couple of initial characters and getting a list of suggestions from search. Now I had to reinstall and figure out where that was again. (I normally type Windows Key, then "features" to select Programs And Features. Now I had to navigate the control panel. 
&lt;/p&gt;&lt;p&gt;
 &lt;/p&gt;&lt;p&gt;After reinstalling Windows Search, still (somewhat luckily) the same error. OK. Grumpf. All other projects put aside. &lt;a href="http://technet.microsoft.com/en-us/sysinternals/bb896645.aspx"&gt;ProcMon&lt;/a&gt;. 
&lt;/p&gt;&lt;p&gt;
 &lt;/p&gt;&lt;p&gt;Starting Process Monitor and then trying to restart Windows Search. When the error above pops up, I stopped Procmon. Now filter in ProcMon only on SearchIndexer.exe (the executable name of the Search service). Most of the files that are used by the service either return "SUCCESS" or "FILE LOCKED WITH ONLY READERS". But then I found this result "USER MAPPED FILE". That looked somewhat in line with the error. The path of the file was 
&lt;/p&gt;&lt;p&gt;C:\ProgramData\Microsoft\Search\Data\Applications\Windows\Projects\SystemIndex\Indexer\CiFiles\0001000C.wid. When I tried to use Windows Explorer (first enable viewing Hidden and System files) I had some interesting flickering issues. Folder contents would show up in the right-hand pane, only to disappear with a fraction of a second. One can only investigate so much at a time though. Moving on.  
&lt;/p&gt;&lt;p&gt;
 &lt;/p&gt;&lt;p&gt;With an elevated command prompt I was able to get to the file. I moved the file to my desktop. Restarting the service and Eureka. In the event log a whole bunch of errors and warning were logged. Windows Search complained about the index being corrupt (most likely because the offending file was missing). 
&lt;/p&gt;&lt;p&gt;
 &lt;/p&gt;&lt;p&gt;But search is back and running again. 
&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9850355" width="1" height="1"&gt;</content><author><name>maartenb</name><uri>http://blogs.msdn.com/members/maartenb.aspx</uri></author></entry><entry><title>Performance Impact of /IntegrityCheck</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/maartenb/archive/2009/07/23/performance-impact-of-integritycheck.aspx" /><id>http://blogs.msdn.com/maartenb/archive/2009/07/23/performance-impact-of-integritycheck.aspx</id><published>2009-07-24T03:44:16Z</published><updated>2009-07-24T03:44:16Z</updated><content type="html">&lt;p&gt;You can link binaries with /integritycheck. This will tell the loader to check the signature of the binary at load time. Supposedly signing with page hash (/ph) has a substantial impact on load time. Omitting /ph will require the entire binary to be loaded in order to calculate the hash and verify the signature. I assume /ph does it over the pages as the name implies. 
&lt;/p&gt;&lt;p&gt;From "&lt;a href="http://download.microsoft.com/download/4/4/b/44bb7147-f058-4002-9ab2-ed22870e3fe9/Kernal%20Data%20and%20Filtering%20Support%20for%20Windows%20Server%202008.doc"&gt;Kernel Data and Filtering Support for Windows Server 2008&lt;/a&gt;": 
&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;em&gt;"All ISV kernel and user mode modules must be linked with the &lt;strong&gt;/integritycheck&lt;/strong&gt; flag set at link time.  This will cause the memory manager to enforce a signature check at load time for the referenced code.  This link.exe setting is present in recent versions of the Microsoft Visual Studio® linker.  If the ISV is using alternate tools to link or edit their produced binaries, this flag setting has the effect of setting (ON) IMAGE_DLLCHARACTERISTICS_FORCE_INTEGRITY    (0x0800)   in the image PE header OptionalHeader.DllCharacteristics field. &lt;/em&gt;
		&lt;/li&gt;&lt;li&gt;&lt;em&gt;Digitally signed user mode modules must have cryptographic per-page hash catalogs.  These are generated using the /PH command-line setting to the signtool utility." &lt;/em&gt;
		&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;You add /integritycheck in the Visual Studio linker options in advanced. You can verify in a binary editor that the actual flag is set. I used CFF Explorer. 
&lt;/p&gt;&lt;p&gt;In order to sign, I create a demo certificate: 
&lt;/p&gt;&lt;p style="margin-left: 36pt"&gt;&lt;span style="font-family:Courier New"&gt;Makecert -r -pe -sr localMachine -ss demostore -n "CN=DemoCert" democert.cer &lt;/span&gt;
	&lt;/p&gt;&lt;p&gt;Then you can use signtool.exe to sign the binary with that certificate. 
&lt;/p&gt;&lt;p style="margin-left: 36pt"&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;Signtool Sign /v /s demostore /n DemoCert /t http://timestamp.verisign.com/scripts/timestamp.dll &amp;lt;mydlltosign&amp;gt;.dll&lt;/span&gt;
	&lt;/p&gt;&lt;p&gt;I created to binaries: one signed with /ph and another without. On trying to load the /ph binary I got an error saying the binary was invalid. I checked the signature and all was good. I signed an executable with the same certificate, UAC elevated it and the consent dialog had the signed flavor. Hmm. Cert was added also to the trusted store. 
&lt;/p&gt;&lt;p&gt;From "&lt;a href="http://download.microsoft.com/download/7/E/7/7E7662CF-CBEA-470B-A97E-CE7CE0D98DC2/AppInit_Win7.docx"&gt;AppInit DLLs in Windows 7 and Windows Server 2008 R2&lt;/a&gt;": 
&lt;/p&gt;&lt;p style="margin-left: 18pt"&gt;&lt;em&gt;"The DLL must be signed with the &lt;strong&gt;/ph&lt;/strong&gt; (page-hash) option. Page-hash enforcement verifies the signature on each page as it is loaded into memory. Because of this requirement, the DLL must be signed on a system that is running Windows Vista or a later version of Windows. The DLL should also be signed with the &lt;strong&gt;/t&lt;/strong&gt; (timestamp) option to prevent the digital signature from expiring when the code-signing certificate expires. When you release sign the DLL, you must use the &lt;strong&gt;/ac&lt;/strong&gt; option to reference a cross-certificate. This is required because the signing code path exists in the Windows kernel, which has a hard-coded root of trust. The cross-certificate is required to chain to the issuing certificate authority." &lt;/em&gt;
	&lt;/p&gt;&lt;p&gt;It appears that integrity checking bypasses the trusted store. Most likely for performance reasons but that is my guess. You need to cross link with a Microsoft certificate. Since I didn't have one handy (and I have no idea how one would do it), I rebooted and turned off driver sign checking. Low and behold my binary loaded. 
&lt;/p&gt;&lt;p&gt;The actual performance part was not as easy as hoped. I used &lt;a href="http://msdn.microsoft.com/en-us/library/dd871254.aspx"&gt;x-perf&lt;/a&gt;. But difference between the page-hash signed binary and the no page hash signed binary was inconclusive. Most likely because my binaries were too small. 
&lt;/p&gt;&lt;p&gt;Next time I have a free morning, I'll dive into it. &lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9846568" width="1" height="1"&gt;</content><author><name>maartenb</name><uri>http://blogs.msdn.com/members/maartenb.aspx</uri></author></entry><entry><title>Disabling a Shim</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/maartenb/archive/2009/07/24/disabling-a-shim.aspx" /><id>http://blogs.msdn.com/maartenb/archive/2009/07/24/disabling-a-shim.aspx</id><published>2009-07-24T02:30:13Z</published><updated>2009-07-24T02:30:13Z</updated><content type="html">&lt;p&gt;The other day I was working on an application that we apparently shimmed. I wanted to know if disabling the shim actually changed the behavior. 
&lt;/p&gt;&lt;p&gt;You can download ACT and go hunt for the executable. (For some interesting reason that fully escapes me, you should uncheck every checkbox in the Query dialog to get the search to find anything at all.) When I found the entry and disabled it, there was no change in behavior. That doesn't mean the shim was still in place though. So I needed to know for sure. 
&lt;/p&gt;&lt;p&gt;Digging up the expert knowledge from &lt;a href="http://blogs.msdn.com/cjacks/archive/2008/05/20/enabling-diagnostic-output-from-shims.aspx"&gt;"the" apcompat guy&lt;/a&gt;, gave me the info for getting the logging enabled. Hooking up DebugView and I still see the shim applied. Even flushing the cache didn't prove helpful (&lt;span style="color:#1f497d"&gt;Rundll32 apphelp.dll,ShimFlushCache). &lt;/span&gt;Hmm. Sledgehammer then.&lt;span style="color:#1f497d"&gt;
		&lt;/span&gt;&lt;/p&gt;&lt;p&gt;You can disable the whole shim engine through this setting from GPEdit.msc:
&lt;/p&gt;&lt;p style="margin-left: 36pt"&gt;&lt;span style="font-family:Arial; font-size:10pt"&gt;Administrative Templates \ Windows Components \ Application Compatibility \ Turn off Application Compatibility Engine
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;Setting it to enabled means that the Shim engine is off. Reboot and there you have it. No output in DebugView. 
&lt;/p&gt;&lt;p&gt;Now I need to figure out why I can't disable this thing on a per shim entry basis. &lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9846907" width="1" height="1"&gt;</content><author><name>maartenb</name><uri>http://blogs.msdn.com/members/maartenb.aspx</uri></author></entry><entry><title>Running Idle tasks before XPerf </title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/maartenb/archive/2009/07/21/running-idle-tasks-before-xperf.aspx" /><id>http://blogs.msdn.com/maartenb/archive/2009/07/21/running-idle-tasks-before-xperf.aspx</id><published>2009-07-22T00:41:49Z</published><updated>2009-07-22T00:41:49Z</updated><content type="html">&lt;p&gt;I am working on profiling impacts of software on the performance of the OS. I'm testing on Windows 7 RC 7100 x86. It is predominantly to get a feel for the complexity. I want to know how much effort it would entail to wrap this up into an offering for our partners. I'm running it in a Hyper-V VM but it should give me a solid idea. 
&lt;/p&gt;&lt;p&gt;Last week I spent most of the time with my colleague Mark installing and getting DTM to run. Mark has done this way more and his relentless demeanor gets him into territories that give me nightmares. DTM is one of them but we got it done and I feel somewhat comfortable running the tests. 
&lt;/p&gt;&lt;p&gt;The COSD performance guys have put some nice performance tests together. They ship with the WLK under SPPT. Some of the tests under there can't be run under virtual machines (hibernate), but others can. So I ran three tests: 15 minute idle, boot and shutdown. While I still need to make sense out of the gathered data, one thing I noticed in one of the 15 minute idle traces is a 2% CPU hit by rundll32.exe. Digging through the tons of data that xperf provides, I was able to find that this was in effect System Restore. 
&lt;/p&gt;&lt;p&gt;Going back through &lt;a href="http://www.microsoft.com/whdc/system/sysperf/Vista_perf.mspx"&gt;"Measuring Performance on Windows Vista"&lt;/a&gt;, it is noted there that you can either wait three days or run "rundll32 advapi32.dll,ProcessIdleTasks". That helped.   &lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9843951" width="1" height="1"&gt;</content><author><name>maartenb</name><uri>http://blogs.msdn.com/members/maartenb.aspx</uri></author></entry><entry><title>Application Verifier Locks 0x201 Active Critical Section</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/maartenb/archive/2008/10/16/application-verifier-locks-0x201-active-critical-section.aspx" /><id>http://blogs.msdn.com/maartenb/archive/2008/10/16/application-verifier-locks-0x201-active-critical-section.aspx</id><published>2008-10-16T05:17:15Z</published><updated>2008-10-16T05:17:15Z</updated><content type="html">&lt;p&gt;Suppose you are trying to get your application Vista Certified or OEM Ready. You test your application with Application Verifier and you see this error in the log:
&lt;/p&gt;&lt;p style="margin-left: 48pt"&gt;"&lt;span style="font-family:Arial; font-size:7pt"&gt;&lt;span style="color:blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#990000"&gt;avrf:logEntry Time&lt;/span&gt;&lt;span style="color:blue"&gt;="&lt;/span&gt;&lt;span style="color:black"&gt;&lt;strong&gt;2008-10-15 : 14:18:33&lt;/strong&gt;&lt;/span&gt;&lt;span style="color:blue"&gt;"&lt;/span&gt;&lt;span style="color:#990000"&gt; LayerName&lt;/span&gt;&lt;span style="color:blue"&gt;="&lt;/span&gt;&lt;span style="color:black"&gt;&lt;strong&gt;Locks&lt;/strong&gt;&lt;/span&gt;&lt;span style="color:blue"&gt;"&lt;/span&gt;&lt;span style="color:#990000"&gt; StopCode&lt;/span&gt;&lt;span style="color:blue"&gt;="&lt;/span&gt;&lt;span style="color:black"&gt;&lt;strong&gt;0x201&lt;/strong&gt;&lt;/span&gt;&lt;span style="color:blue"&gt;"&lt;/span&gt;&lt;span style="color:#990000"&gt; Severity&lt;/span&gt;&lt;span style="color:blue"&gt;="&lt;/span&gt;&lt;span style="color:black"&gt;&lt;strong&gt;Error&lt;/strong&gt;&lt;/span&gt;&lt;span style="color:blue"&gt;"&amp;gt;&lt;/span&gt;&lt;span style="color:black"&gt;
			&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 48pt"&gt;&lt;span style="font-size:7pt"&gt;&lt;span style="color:red; font-family:Courier New"&gt;&lt;strong&gt; &lt;/strong&gt;&lt;/span&gt;&lt;span style="font-family:Arial"&gt;&lt;span style="color:black"&gt;
				&lt;/span&gt;&lt;span style="color:blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#990000"&gt;avrf:message&lt;/span&gt;&lt;span style="color:blue"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color:black"&gt;&lt;strong&gt;Unloading DLL containing an active critical section.&lt;/strong&gt;&lt;/span&gt;&lt;span style="color:blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#990000"&gt;avrf:message&lt;/span&gt;&lt;span style="color:blue"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color:black"&gt;
				&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 48pt"&gt;
 &lt;/p&gt;&lt;p style="margin-left: 24pt"&gt;
 &lt;/p&gt;&lt;p&gt;Now what? From the log, this is difficult to debug.
&lt;/p&gt;&lt;p&gt;Little history how you might have arrived here. When you checked the Basics errors in Application Verifier, you got a warning mentioning something along the lines of "For the basic tests you need a debugger". This is because Application Verifier sets break points. If you don't have a default debugger, those breakpoints are ignored hence you need a debugger. Best thing you can do is run your application from the debugger: preferably Windbg since that has some useful extensions that help you navigate the process' memory. You can download it &lt;a href="http://www.microsoft.com/whdc/devtools/debugging/installx86.mspx"&gt;here&lt;/a&gt;. After installing and running you can under File | Open Executable navigate to your application. Hit F5, reproduce the error and break into the debugger. 
&lt;/p&gt;&lt;p&gt;Next best thing is to set Windbg as the interactive debugger (Windbg –I from elevated command prompt). When the application sets a break point (the application verifier layer in this case), the system will see if there is an interactive debugger. If it finds one, it launches it with your application as the target. 
&lt;/p&gt;&lt;p&gt;Good. So now both ways have taken you to this point: 
&lt;/p&gt;&lt;p style="margin-left: 36pt"&gt;&lt;span style="font-family:Courier"&gt;(11e4.1604): Break instruction exception - code 80000003 (!!! second chance !!!)&lt;br/&gt;eax=000001ff ebx=75988844 ecx=77dde7c4 edx=00000000 esi=00000000 edi=000001ff&lt;br/&gt;eip=77db0004 esp=003ee8fc ebp=003eeafc iopl=0         nv up ei pl nz na po nc&lt;br/&gt;cs=0023  ss=002b  ds=002b  es=002b  fs=0053  gs=002b             efl=00000202&lt;br/&gt;ntdll!DbgBreakPoint:&lt;br/&gt;77db0004 cc              int     3
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;You of course need symbols. I explained how &lt;a href="http://blogs.msdn.com/maartenb/archive/2008/10/16/debugging-and-symbols.aspx"&gt;here&lt;/a&gt;.
&lt;/p&gt;&lt;p&gt;Now comes the interesting part. Learn and appreciate the power of "!analyze –v":
&lt;/p&gt;&lt;p style="margin-left: 36pt"&gt;&lt;span style="font-family:Courier"&gt;0:000&amp;gt; !analyze -v&lt;br/&gt;*******************************************************************************&lt;br/&gt;*                                                                             *&lt;br/&gt;*                        Exception Analysis                                   *&lt;br/&gt;*                                                                             *&lt;br/&gt;*******************************************************************************&lt;br/&gt;*** WARNING: Unable to verify checksum for e:\Playground\AVRF\x201\Debug\x201b.exe&lt;br/&gt;APPLICATION_VERIFIER_LOCKS_LOCK_IN_UNLOADED_DLL (201)&lt;br/&gt;Unloading DLL containing an active critical section.&lt;br/&gt;This stop is generated if a DLL has a global variable containing a critical section&lt;br/&gt;and the DLL is unloaded but the critical section has not been deleted. To debug&lt;br/&gt;this stop use the following debugger commands:&lt;br/&gt;    $ du parameter3 - to dump the name of the culprit DLL.&lt;br/&gt;    $ .reload dllname or .reload dllname = parameter4 - to reload the symbols for that DLL.&lt;br/&gt;    $ !cs -s parameter1 - dump information about this critical section.&lt;br/&gt;    $ ln parameter1 - to show symbols near the address of the critical section.&lt;br/&gt;    This should help identify the leaked critical section.&lt;br/&gt;    $ dps parameter2 - to dump the stack trace for this critical section initialization. &lt;br/&gt;Arguments:&lt;br/&gt;Arg1: 718933cc, Critical section address. &lt;br/&gt;Arg2: 00f8a104, Critical section initialization stack trace. &lt;br/&gt;Arg3: 05be6fe4, DLL name address. &lt;br/&gt;Arg4: 71870000, DLL base address.&lt;br/&gt;&lt;/span&gt;
	&lt;/p&gt;&lt;p&gt;The information is fairly self explanatory. In the process a dll is loaded. This dll initializes a critical section and then before deleting the critical section, the dll is unloaded. There are four parameters which are useful mentioned above. And then some complaining about symbols; followed by more useful information. (I think it complains about symbols because it wants private symbols for the OS. I don't have those, but the results are good anyway.) 
&lt;/p&gt;&lt;p&gt;Somewhere halfway, you'll find this:
&lt;/p&gt;&lt;p style="margin-left: 36pt"&gt;&lt;span style="font-family:Courier"&gt;CRITICAL_SECTION:  718933cc -- &lt;span style="color:#1f497d; text-decoration:underline"&gt;(!cs -s 718933cc)
&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;So this is the actual critical section we're leaking. Clicking on the hyperlink gives us: 
&lt;/p&gt;&lt;p style="margin-left: 36pt"&gt;&lt;span style="font-family:Courier"&gt;0:000&amp;gt; !cs -s 718933cc&lt;br/&gt;-----------------------------------------&lt;br/&gt;Critical section   = 0x718933cc (&amp;lt;Unloaded_TheLib.dll&amp;gt;+0x233CC)&lt;br/&gt;DebugInfo          = 0x05c2afe0&lt;br/&gt;NOT LOCKED&lt;br/&gt;LockSemaphore      = 0x0&lt;br/&gt;SpinCount          = 0x00000000&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;Stack trace for DebugInfo = 0x05c2afe0:&lt;br/&gt;&lt;br/&gt;0x77df99b6: ntdll!RtlInitializeCriticalSectionAndSpinCount+0x19&lt;br/&gt;0x75976936: vfbasics!AVrfpInitializeCriticalSectionCommon+0x136&lt;br/&gt;0x75976ab2: vfbasics!AVrfpRtlInitializeCriticalSection+0x12&lt;br/&gt;&lt;strong&gt;0x71881f37: &amp;lt;Unloaded_TheLib.dll&amp;gt;+0x11F37&lt;/strong&gt;&lt;br/&gt;0x7188bc28: &amp;lt;Unloaded_TheLib.dll&amp;gt;+0x1BC28&lt;br/&gt;0x5e82c02c: MSVCR90D!_initterm+0x1C&lt;br/&gt;0x71883131: &amp;lt;Unloaded_TheLib.dll&amp;gt;+0x13131&lt;br/&gt;0x7188351e: &amp;lt;Unloaded_TheLib.dll&amp;gt;+0x1351E&lt;br/&gt;0x71883451: &amp;lt;Unloaded_TheLib.dll&amp;gt;+0x13451&lt;br/&gt;0x75a059c9: verifier!AVrfpStandardDllEntryPointRoutine+0x109&lt;br/&gt;0x75a7859d: vrfcore!VfCoreStandardDllEntryPointRoutine+0x127&lt;br/&gt;0x7598105e: vfbasics!AVrfpStandardDllEntryPointRoutine+0x10E&lt;br/&gt;0x77dcfcc0: ntdll!LdrpCallInitRoutine+0x14&lt;br/&gt;0x77dd9b28: ntdll!LdrpRunInitializeRoutines+0x270&lt;br/&gt;0x77dd95ae: ntdll!LdrpLoadDll+0x4D5&lt;br/&gt;0x77df29db: ntdll!LdrLoadDll+0x22A&lt;br/&gt;0x7598164c: vfbasics!AVrfpLdrLoadDll+0x5C&lt;br/&gt;0x75fc4d50: kernel32!LoadLibraryExW+0x231&lt;br/&gt;0x75fc4dca: kernel32!LoadLibraryW+0x11&lt;br/&gt;0x00f42d50: x201b!Cx201bDlg::OnBnClickedButton1+0x30&lt;br/&gt;
		&lt;/span&gt;&lt;/p&gt;&lt;p&gt;Hmm. Of course. The dll is gone. Which is kind of the crux of this problem. The bold line indicates where the critical section was initialized. If you have multiple critical sections, you might scratch your head which one you're leaking here. So you can try to reload the dll. There is a little snippet how you should be able to do this with .reload etc. I have never been able to do this. If you have, let me know. 
&lt;/p&gt;&lt;p&gt;What I do is spin up an instance of the application in the debugger and make sure that the dll is still loaded. (You can set breakpoints on LoadLibrary to make sure that you are just after the load, and before the Free. Subject for another blog potentially.)  Then, I do a ln (as in &lt;strong&gt;l&lt;/strong&gt;ist &lt;strong&gt;n&lt;/strong&gt;ear) with the address from the bold line in the stack trace. 
&lt;/p&gt;&lt;p style="margin-left: 36pt"&gt;&lt;span style="font-family:Courier"&gt;0:001&amp;gt; ln 71881f37&lt;br/&gt;*** WARNING: Unable to verify checksum for E:\Playground\AVRF\x201\Debug\TheLib.dll&lt;br/&gt;e:\playground\avrf\x201\thelib\thelib.cpp(49)+0x11&lt;br/&gt;(71881ef0)   TheLib!CTheLibApp::CTheLibApp+0x47   |  (71881f70)   TheLib!CTheLibApp::`scalar deleting destructor'
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;There we go. Thelib.cpp(49). Looking at that source line, takes me to the InitializeCriticalSection call of the problematic critical section. 
&lt;/p&gt;&lt;p&gt;Maarten&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9001322" width="1" height="1"&gt;</content><author><name>maartenb</name><uri>http://blogs.msdn.com/members/maartenb.aspx</uri></author></entry><entry><title>Debugging and Symbols</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/maartenb/archive/2008/10/16/debugging-and-symbols.aspx" /><id>http://blogs.msdn.com/maartenb/archive/2008/10/16/debugging-and-symbols.aspx</id><published>2008-10-16T04:33:58Z</published><updated>2008-10-16T04:33:58Z</updated><content type="html">&lt;p&gt;Anytime you want to do anything in a debugger, you need symbols. Best thing you can do is set up an environment variable, so you're done. &lt;a href="http://www.microsoft.com/whdc/devtools/debugging/debugstart.mspx#a"&gt;Here&lt;/a&gt; are public Microsoft symbols. &lt;a href="http://yvesdolce.org/default.aspx"&gt;Yves&lt;/a&gt; has created a little cmd that you can use which I politely copy here since it is handy: &lt;/p&gt;  &lt;p&gt;SetX.exe /M _NT_SYMBOL_PATH &amp;quot;SRV*C:\Symbols\Private*\\Symbols\Symbols;SRV*C:\Symbols\Public*http://msdl.microsoft.com/download/symbols&amp;quot;&lt;/p&gt;  &lt;p&gt;And for more information there is a &lt;a href="http://support.microsoft.com/kb/311503"&gt;KB article.&lt;/a&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9001295" width="1" height="1"&gt;</content><author><name>maartenb</name><uri>http://blogs.msdn.com/members/maartenb.aspx</uri></author></entry><entry><title>DllGetClassObject already defined</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/maartenb/archive/2008/09/11/dllgetclassobject-already-defined.aspx" /><id>http://blogs.msdn.com/maartenb/archive/2008/09/11/dllgetclassobject-already-defined.aspx</id><published>2008-09-12T01:51:03Z</published><updated>2008-09-12T01:51:03Z</updated><content type="html">&lt;p&gt;When you upgrade your project from VC2005 to VC2008 you might get these errors:
&lt;/p&gt;&lt;p&gt;&lt;span style="color:#080808; font-family:Courier; font-size:10pt"&gt;mfcs90u.lib(oleexp.obj) : error LNK2005: _DllGetClassObject@12 already defined in d.obj&lt;br/&gt;mfcs90u.lib(oleexp.obj) : error LNK2005: _DllCanUnloadNow@0 already defined in d.obj
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#080808; font-size:10pt"&gt;Strictly in release builds though. 
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-size:10pt"&gt;&lt;span style="color:#080808"&gt;You can &lt;/span&gt;&lt;span style="color:black"&gt;add "AFX_MANAGE_STATE(AfxGetStaticModuleState());" to the first line of InitInstance() in dllmain.cpp. 
&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#080808; font-size:10pt"&gt;
		&lt;/span&gt; &lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8945639" width="1" height="1"&gt;</content><author><name>maartenb</name><uri>http://blogs.msdn.com/members/maartenb.aspx</uri></author></entry><entry><title>Application Verifier Logs for a Service</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/maartenb/archive/2008/08/20/application-verifier-logs-for-a-service.aspx" /><id>http://blogs.msdn.com/maartenb/archive/2008/08/20/application-verifier-logs-for-a-service.aspx</id><published>2008-08-20T21:35:59Z</published><updated>2008-08-20T21:35:59Z</updated><content type="html">&lt;p&gt;If you have a service and have told AppVerifier to monitor it, you might wonder where the logs are and how you can see them. (Two separate questions). You can find the logs here "&lt;span style="color:red; font-size:9pt"&gt;c:\windows\system32\config\systemprofile\appverifierlogs&lt;/span&gt;" (or the corresponding directory given the system drive and bitness of your application). 
&lt;/p&gt;&lt;p&gt;Now if you want to see them in AppVerifier, the easiest way is to just copy them over to the current user profile and then do a view logs from AppVerifier. &lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8881880" width="1" height="1"&gt;</content><author><name>maartenb</name><uri>http://blogs.msdn.com/members/maartenb.aspx</uri></author></entry><entry><title>OEM Ready Links</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/maartenb/archive/2008/08/20/oem-ready-links.aspx" /><id>http://blogs.msdn.com/maartenb/archive/2008/08/20/oem-ready-links.aspx</id><published>2008-08-20T19:18:38Z</published><updated>2008-08-20T19:18:38Z</updated><content type="html">&lt;p&gt;While I'm trying to find out how to fix the portals, here are some links to documents we frequently use. 
&lt;/p&gt;&lt;ul&gt;&lt;li&gt;OEM Ready program: &lt;a href="http://msdn.microsoft.com/en-us/windowsvista/cc315067.aspx"&gt;http://msdn.microsoft.com/en-us/windowsvista/cc315067.aspx&lt;/a&gt;
		&lt;/li&gt;&lt;li&gt;There is a Manual for the tool, but it is not linked from anywhere as far as I can tell: &lt;a href="http://go.microsoft.com/?linkid=9093231"&gt;http://go.microsoft.com/?linkid=9093231&lt;/a&gt;&lt;span style="text-decoration:underline"&gt;
			&lt;/span&gt;
		&lt;/li&gt;&lt;li&gt;Here is Jay's video on Channel 9: &lt;a href="http://channel9.msdn.com/posts/philpenn/The-Microsoft-OEM-Ready-Certification-Tool/"&gt;http://channel9.msdn.com/posts/philpenn/The-Microsoft-OEM-Ready-Certification-Tool/&lt;/a&gt;
		&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;  &lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8881524" width="1" height="1"&gt;</content><author><name>maartenb</name><uri>http://blogs.msdn.com/members/maartenb.aspx</uri></author></entry><entry><title>Shared Components</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/maartenb/archive/2008/08/19/shared-components.aspx" /><id>http://blogs.msdn.com/maartenb/archive/2008/08/19/shared-components.aspx</id><published>2008-08-20T00:43:04Z</published><updated>2008-08-20T00:43:04Z</updated><content type="html">&lt;p&gt;If you need to install components that are shared between multiple applications, you want them to go to &lt;a href="http://msdn.microsoft.com/en-us/library/s2esdf4x(VS.80).aspx"&gt;Common Files&lt;/a&gt;. I found a decent description in this doc: "&lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=ba73b169-a648-49af-bc5e-a2eebb74c16b&amp;amp;DisplayLang=en"&gt;Windows Vista Application Development Requirements for User Account Control Compatibility".&lt;/a&gt;You should stay out of system32. &lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8879832" width="1" height="1"&gt;</content><author><name>maartenb</name><uri>http://blogs.msdn.com/members/maartenb.aspx</uri></author></entry><entry><title>How Do I know if Windbg I actually took effect?</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/maartenb/archive/2008/07/10/how-do-i-know-if-windbg-i-actually-took-effect.aspx" /><id>http://blogs.msdn.com/maartenb/archive/2008/07/10/how-do-i-know-if-windbg-i-actually-took-effect.aspx</id><published>2008-07-11T00:59:20Z</published><updated>2008-07-11T00:59:20Z</updated><content type="html">&lt;p&gt;So you're ready to test your application with Application Verifier. The OEM Ready and Certified for Windows Vista (CFWV) test documents specify you type Windbg –I from an elevated command prompt. So you add your application to Application Verifier, add the specific tests under basic and miscellaneous and start your app. You run through your "normal operations" and exit the application. Nothing happened. 
&lt;/p&gt;&lt;p&gt;Now you have a lingering doubt: did my app not trigger any AppVerif breakpoints? Or did I not set it up right? Hmm.
&lt;/p&gt;&lt;p&gt;Here is a little test app. Copy this in a C command line app and build; add the application.exe to AppVerif as in the test steps and it should break in with a NULL handle stop code 303.
&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;&lt;span style="color:blue"&gt;#include&lt;/span&gt;
			&lt;span style="color:#a31515"&gt;"stdafx.h"
&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;&lt;span style="color:blue"&gt;#include&lt;/span&gt;
			&lt;span style="color:#a31515"&gt;"windows.h"
&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;
 &lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;&lt;span style="color:blue"&gt;int&lt;/span&gt; _tmain(&lt;span style="color:blue"&gt;int&lt;/span&gt; argc, _TCHAR* argv[])
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;{
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;    HANDLE h = NULL;
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;
 &lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;    WaitForSingleObject( h, 0 );
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;
 &lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;    wprintf(L&lt;span style="color:#a31515"&gt;"Okiedokie\n\r"&lt;/span&gt;);
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;
 &lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;    &lt;span style="color:blue"&gt;return&lt;/span&gt; 0;
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;}&lt;/span&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8718839" width="1" height="1"&gt;</content><author><name>maartenb</name><uri>http://blogs.msdn.com/members/maartenb.aspx</uri></author></entry><entry><title>How to Roll Back WinDbg –I</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/maartenb/archive/2008/07/10/how-to-roll-back-windbg-i.aspx" /><id>http://blogs.msdn.com/maartenb/archive/2008/07/10/how-to-roll-back-windbg-i.aspx</id><published>2008-07-10T23:50:16Z</published><updated>2008-07-10T23:50:16Z</updated><content type="html">&lt;p&gt;For &lt;a href="http://msdn.microsoft.com/en-us/windowsvista/cc315067.aspx"&gt;OEM Ready&lt;/a&gt; tests (and for Certified for Windows Vista) one of the requirements is to set up an interactive debugger. The documentation specifies Windbg since it allows you to do use extensions such as "!analyze –v" which will give you a ton of information. One question that then comes up is "How do get back my machine back to its original state before I ran WinDbg –I?" 
&lt;/p&gt;&lt;p&gt;Those are the registry keys in question that "WinDbg –I" changes: 
&lt;/p&gt;&lt;ul&gt;&lt;li&gt;\\HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\AeDebug
&lt;/li&gt;&lt;li&gt;\\HKEY_LOCAL_MACHINE\Software\Wow6432Node\Microsoft\Windows NT\CurrentVersion\AeDebug
&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;When you set WinDbg –I, Windbg will add a new string value "Debugger" with a path to windbg.exe.     There is also an Auto string value added. 
&lt;/p&gt;&lt;p&gt;The recommendation is to back up the registry key before running WinDbg –I. On one of my clean systems the key was existent but the Debugger and Auto values were missing. Removing those effectively rolled back my system to the state it was in before. But don't take my observation as official guidance. 
&lt;/p&gt;&lt;p&gt;On a final note, if you absolutely don't like WinDbg, you can use Visual Studio as your interactive debugger. Under Tools/Options/Debugging you will find a Just-In-Time section. If you click the "Native" checkbox, your application will break in to Visual Studio when a breakpoint is encountered. &lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8718593" width="1" height="1"&gt;</content><author><name>maartenb</name><uri>http://blogs.msdn.com/members/maartenb.aspx</uri></author></entry></feed>