<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="https://www.w3.org/2005/Atom" xmlns:sy="https://purl.org/rss/1.0/modules/syndication/" xmlns:dc="https://purl.org/dc/elements/1.1/" xmlns:content="https://purl.org/rss/1.0/modules/content/" xmlns:wfw="https://wellformedweb.org/CommentAPI/" xmlns:slash="https://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>Emre's blog</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/emreknlk/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/emreknlk/feed.xml</link>
    <description />
    <lastBuildDate>Wed, 17 Apr 2019 03:21:14 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>The debuggee is ready to run</title>
      <link>https://docs.microsoft.com/archive/blogs/emreknlk/the-debuggee-is-ready-to-run</link>
      <pubDate>Mon, 20 Feb 2012 10:29:27 GMT</pubDate>
      <dc:creator><![CDATA[emreknlk]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/emreknlk/2012/02/20/the-debuggee-is-ready-to-run/</guid>
      <description><![CDATA[Today, when I typed !analyze -v to my windbg window, I got this response back:
0: kd&gt; !analyze...]]></description>
      <content:encoded><![CDATA[<p>Today, when I typed !analyze -v to my windbg window, I got this response back:</p>
<p>0: kd&gt; !analyze -v<br />The debuggee is ready to run</p>
<p>I saw on the forums that a couple of poeple hit this issue and couldn't find a solution. Well, I was lucky enough, after trying these I got it back working</p>
<p>1: kd&gt; .ecxr<br />Unable to get exception context, HRESULT 0x8000FFFF<br />Break instruction exception - code 80000003 (first chance)<br />windbg&gt; .hh <br />3: kd&gt; .cxr</p>
<p>So, if you hit that message, try running .ecxr and .cxr commands on your windbg command window. Hope that helps!</p>]]></content:encoded>
    </item>
    <item>
      <title>Start Debugging with Windbg</title>
      <link>https://docs.microsoft.com/archive/blogs/emreknlk/start-debugging-with-windbg</link>
      <pubDate>Sun, 27 Mar 2011 17:06:37 GMT</pubDate>
      <dc:creator><![CDATA[emreknlk]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/emreknlk/2011/03/27/start-debugging-with-windbg/</guid>
      <description><![CDATA[Hey folks, I’m a big fan of Windbg. It’s really powerful and you can do much more things than you...]]></description>
      <content:encoded><![CDATA[<p><font size="2"></font></p>  <p align="justify"><font size="2">Hey folks, I’m a big fan of Windbg. It’s really powerful and you can do much more things than you can do with another other debugger!</font></p>  <p align="justify"><font size="2">In this blog post I’m going to show you different methods to start debugging with windbg. </font></p>  <p align="justify"><font size="2"><font size="2"><font style="font-weight: bold">Start by launching the process with Windbg</font></font></font></p>  <p align="justify"><font size="2">This is easy. If you need to debug a simple application and you have the exe path, you can launch it with Windbg either from the command line or from the UI. All you need to do is launching Windbg and clicking “Open Executable” menu item from the File menu. You can then provide executable path and arguments to the process. Once you click Open, your debugging session starts.</font></p>  <p align="justify"><font size="2"><strong>Start by attaching the process to Windbg</strong></font></p>  <p align="justify"><font size="2">If you have a process that’s already running, you can use this option to start debugging with Windbg. This option is useful when debugging services or processes that cannot be restarted. To do so, launch the Windbg and select “Attach to a Process” menu item from the File menu. Windbg will display a list of processes that you can select any to attach it to the debugger. Once you click OK, your debugging session starts.</font></p>  <p align="justify"><font size="2"><strong>Start by using Gflags</strong></font></p>  <p align="justify"><font size="2">This is a little bit advanced. You can use gflags.exe, a utility tool for processes, to start the process under Windbg. Here is how it works: You write the executable name to the GFLAGS under Image File tab and it displays you a bunch of options. In the below image, I launched the gflags.exe as administrator, switched to Image File tab and wrote notepad.exe as image name. When I clicked the TAB key, it displayed options associated with the notepad executable. The Debugger option should be filled to point to Windbg.exe path in your system.</font></p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/28/72/metablogapi/6521.image_7FA01ED7.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-28-72-metablogapi/6521.image_5F00_7FA01ED7.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/28/72/metablogapi/7510.image_thumb_3DB93989.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-28-72-metablogapi/7510.image_5F00_thumb_5F00_3DB93989.png" width="393" height="381" /></a></p>  <p align="justify"><font size="2">Now, whenever notepad.exe launches in the system, it will be started as attached to Windbg. GFLAGS is very useful when you are debugging a process and when you don’t know when it will be started or by whom it will be started. </font></p>  <p align="justify"><font size="2"><strong>Start by child debugging</strong></font></p>  <p align="justify"><font size="2">Windbg has a command to enable child debugging for any process. All you need to do is to write below command to the Windbg command line in parent process’ debugging session:</font></p>  <p align="justify"><font size="2">.childdbg 1</font></p>  <p align="justify"><font size="2">So, where can you use this method? Let’s assume that you are going to debug a service process running as SYSTEM. Normally, you can use the attach the process to Windbg method after service starts. However, what if you want to debug the service start up? In this case you can’t use the attach method because you would miss the service startup. You can’t use GFLAGS either because the service is running as SYSTEM and Windbg will start in another desktop (SYSTEM user’s desktop) and won’t be available to you. </font></p>  <p align="justify"><font size="2">So, here is what you can do:</font></p>  <p align="justify"><font size="2">- Attach the services.exe to Windbg by using attach to a process method.</font></p>  <p align="justify"><font size="2">- Run “.childdbg 1” command in the Windbg command window. This will enable the child debugging for services.exe</font></p>  <p align="justify"><font size="2">- Start the service you want to debug. What will happen is that new service will start and the Windbg console that’s attached to the services.exe process will break, indicating that a new process is started. Now you will have the ability to debug the new process in the same Windbg program. </font></p>  <p><font size="2"><strong>Start by setting the Windbg as default postmortem debugger</strong></font></p>  <p align="justify"><font size="2">You can run “Windbg –I” command from a command line tool to set your Windbg as default postmortem debugger. This is useful when running application verifier to verify your process. In case of any appverifier stop, Windbg will be automatically launched and attached to the process.</font></p>  <p align="justify"><font size="2"><strong>Start by setting MsiBreak environment variable</strong></font></p>  <p align="justify"><font size="2">Have you ever needed to debug a custom action in your installer? Windows Installer uses MsiBreak environment variable to give you a chance to debug your custom action. Basically, you need to create an environment variable named MsiBreak and set its value to the custom action name. When the custom action is being executed during the install time, you will be asked to attach the process to the debugger. You can use attaching process to Windbg method to start debugging your custom action.</font></p>  <p align="justify"><font size="2">In this post, I tried to cover different methods to start debugging a process in user mode. If you haven’t tried Windbg already, I strongly recommend to start using it!</font></p>  <p><font size="2"></font></p>  <p><font size="2"></font></p>  <p><font size="2">&#160;</font></p>]]></content:encoded>
    </item>
    <item>
      <title>Have you tried Server App-V yet?</title>
      <link>https://docs.microsoft.com/archive/blogs/emreknlk/have-you-tried-server-app-v-yet</link>
      <pubDate>Fri, 25 Mar 2011 11:06:08 GMT</pubDate>
      <dc:creator><![CDATA[emreknlk]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/emreknlk/2011/03/25/have-you-tried-server-app-v-yet/</guid>
      <description><![CDATA[&#160;  Hello everyone,   Have you heard about Server App-V? Do you want to learn more about it ?...]]></description>
      <content:encoded><![CDATA[<p>&#160;</p>  <p align="justify"><font size="2">Hello everyone, </font></p>  <p align="justify"><font size="2">Have you heard about Server App-V? Do you want to learn more about it ? SCVMM 2012 Beta was announced at MMS this week. With the SCVMM 2012, enterprises can use a very cool feature, Server App-V, to dramatically simplify the deployment scenarios in their datacenters by taking full advantage of virtualization!</font></p>  <p align="justify"><font size="2">To read more about the SCVMM 2012, you can check out the team blog of SCVMM: <a title="https://blogs.technet.com/b/scvmm/" href="https://blogs.technet.com/b/scvmm/">https://blogs.technet.com/b/scvmm/</a> I love how these guys blog. There are a lot of good contents on it. So, give it a try and learn more about SCVMM 2012!</font></p>  <p align="justify"><font size="2">Now, going back to Server App-V, you should definitely check out the Server App-V team blog. It has been created on technet and the purpose of the team blog is to enlighten folks about the Server App-V, it’s purpose, use-cases, customer scenarios, benefits and so on. Here is the link to the team blog: <a title="https://blogs.technet.com/b/serverappv/" href="https://blogs.technet.com/b/serverappv/">https://blogs.technet.com/b/serverappv/</a>&#160;</font></p>]]></content:encoded>
    </item>
    <item>
      <title>sprintf/wsprintf Replacement</title>
      <link>https://docs.microsoft.com/archive/blogs/emreknlk/sprintfwsprintf-replacement</link>
      <pubDate>Thu, 09 Dec 2010 12:07:13 GMT</pubDate>
      <dc:creator><![CDATA[emreknlk]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/emreknlk/2010/12/09/sprintfwsprintf-replacement/</guid>
      <description><![CDATA[&#160;  Are you thinking about using wsprintf method to create a string buffer? Think twice before...]]></description>
      <content:encoded><![CDATA[<p>&#160;</p>  <p>Are you thinking about using wsprintf method to create a string buffer? Think twice before doing anything wrong! MSDN documentation explicitly warns programmers to not use this API. </p>  <p>So, what alternative we can use instead? </p>  <p>sstream header gives us wstringstream class to create our own string streams. It’s easy, convenient and object oriented. Let’s try a simple example:</p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/28/72/metablogapi/0285.image_7F8E7830.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-28-72-metablogapi/0285.image_5F00_7F8E7830.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/28/72/metablogapi/3010.image_thumb_4F8426AF.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-28-72-metablogapi/3010.image_5F00_thumb_5F00_4F8426AF.png" width="698" height="221" /></a></p>  <p>Above example demonstrates how you can concatenate a string buffer and an integer to form a single string. </p>  <p>In short, do not use banned APIs such as wsprintf. There are multiple ways of doing something and choose the safest and cleanest one!</p>]]></content:encoded>
    </item>
    <item>
      <title>Avoid Manual Memory Management</title>
      <link>https://docs.microsoft.com/archive/blogs/emreknlk/avoid-manual-memory-management</link>
      <pubDate>Thu, 09 Dec 2010 08:46:00 GMT</pubDate>
      <dc:creator><![CDATA[emreknlk]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/emreknlk/2010/12/09/avoid-manual-memory-management/</guid>
      <description><![CDATA[&nbsp;
This post is all about how to avoid freeing a memory block that is allocated by us manually....]]></description>
      <content:encoded><![CDATA[<p>&nbsp;</p>
<p>This post is all about how to avoid freeing a memory block that is allocated by us manually. Attempting to free the allocations manually may result in memory leaks, access violations, unreadable code, and maintenance problems. For example, look at the below code piece:</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/28/72/metablogapi/4130.image_23CF32EB.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-28-72-metablogapi/4130.image_5F00_23CF32EB.png"><img height="276" width="592" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/28/72/metablogapi/3568.image_thumb_13DFEE27.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-28-72-metablogapi/3568.image_5F00_thumb_5F00_13DFEE27.png" alt="image" border="0" title="image" style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" /></a></p>
<p align="justify">Do you see the problem(s) here ? Anytime something goes wrong, we have to remember to delete the pointer. Otherwise memory will be leaked. What happens if someone else visits this code and modifies it in the future ? It&rsquo;s very likely that another return path will be introduced and ptr won&rsquo;t be freed. Even if all the delete operators are used correctly, an inner method may throw intentionally or unintentionally and leave the memory allocated in the process. One final problem is the readability of this code. We make it unnecessarily longer and hard to read by trying to handle all the delete operations. What would our function look like if it allocates multiple variables!</p>
<p>Here is another typical problem:</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/28/72/metablogapi/4645.image_60A3B4BD.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-28-72-metablogapi/4645.image_5F00_60A3B4BD.png"><img height="66" width="244" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/28/72/metablogapi/0844.image_thumb_59184550.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-28-72-metablogapi/0844.image_5F00_thumb_5F00_59184550.png" alt="image" border="0" title="image" style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" /></a></p>
<p align="justify">First, I am really against using raw pointers to allocate memory. Second, passing the raw pointer from one scope to another is something we should avoid. In some cases, multiple objects may want to share same memory block. For example, if you have an object dynamically created in the heap and if multiple objects want to consume this object, you start passing this object around.. </p>
<p align="justify">To make our operations safer and cleaner we can use shared_ptr when we create the objects. shared_ptr holds a reference count to the object and frees it when the last reference goes away. Two popular shared_ptr classes are in the tr1 and boost library.</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/28/72/metablogapi/6712.image_6D3161D9.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-28-72-metablogapi/6712.image_5F00_6D3161D9.png"><img height="73" width="291" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/28/72/metablogapi/2273.image_thumb_50B46FF9.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-28-72-metablogapi/2273.image_5F00_thumb_5F00_50B46FF9.png" alt="image" border="0" title="image" style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" /></a></p>
<p align="justify">This is much better. We allocate a memory block for MyClass object by using a shared_ptr. So we don&rsquo;t need to call delete operator on it; shared_ptr will automatically free it when the last reference goes out of scope. foo method&rsquo;s input parameter is also a type of shared_ptr so when we pass the ptr object to the foo, it&rsquo;s reference count will increment&nbsp;&nbsp; by one preventing other shared_ptr objects freeing the MyClass object.</p>
<p align="justify">Sometimes, all we need to do is to create a buffer and use it in the same function and get rid of it quickly. In these cases, we can either use auto_ptr or a vector object. </p>
<p align="justify">auto_ptr is useful when we need to allocate a class object. For example; auto_ptr&lt;MyClass&gt; ptr = new MyClass();</p>
<p align="justify">When auto_ptr goes out of scope, it will delete the object automatically for us. Unlike shared_ptr, auto_ptr does not keep a reference count so you should not pass auto_ptrs around. This will very likely cause an access violation since each auto_ptr destructor will try to free the memory block.</p>
<p align="justify">vector object is useful when you want to allocate an array of primitive type variables. I generally use vector class to create string buffers or BYTE buffers. When object goes out of scope, it will again free the memory for us.&nbsp; std::vector&lt;wchar_t&gt; buffer(size, L&rsquo;\0&rsquo;); creates a buffer of wchar_t in <em>size</em> length and fills the buffer with NULLs for us.</p>
<p align="justify">In conclusion, avoid using raw pointers and delete operator in your code. There are beautiful smart pointers and techniques to do memory management automatically. </p>]]></content:encoded>
    </item>
    <item>
      <title>Remove MAX_PATH Limitations</title>
      <link>https://docs.microsoft.com/archive/blogs/emreknlk/remove-max_path-limitations</link>
      <pubDate>Fri, 03 Dec 2010 13:11:00 GMT</pubDate>
      <dc:creator><![CDATA[emreknlk]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/emreknlk/2010/12/03/remove-max_path-limitations/</guid>
      <description><![CDATA[&nbsp;
As technology advances, applications increase their complexity. As a result, installers...]]></description>
      <content:encoded><![CDATA[<p>&nbsp;</p>
<p>As technology advances, applications increase their complexity. As a result, installers deploy more and more files and folders to the install directories.&nbsp; Software developers should not rely on the Window&rsquo;s MAX_PATH constant when developing their applications. Many Windows APIs don&rsquo;t support file paths that are longer than MAX_PATH in length directly. However, they do support these files under some rules. I recommend you to follow this guideline when working with file APIs.</p>
<p>1 : Never use MAX_PATH constant in the code. Most of us tend to allocate buffers with a magic number. However, this is not a good practice as it may introduce security threats and reduce the robustness of program. Instead, use a vector object as a buffer. You will have the power of changing its size based on your file path length.</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/28/72/metablogapi/1030.image_0B30316F.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-28-72-metablogapi/1030.image_5F00_0B30316F.png"><img height="131" width="244" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/28/72/metablogapi/5141.image_thumb_08A6FFB1.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-28-72-metablogapi/5141.image_5F00_thumb_5F00_08A6FFB1.png" alt="image" border="0" title="image" style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" /></a></p>
<p>2 : Prepend <a href="file://\\?\">\\?\</a> characters to the file paths that are longer than MAX_PATH. Most Windows APIs support file paths that are longer than MAX_PATH in length IFF file path contains <a href="file://\\?\">\\?\</a> prefix. However, do not prepend this prefix to the file paths that are less than MAX_PATH in length as prepending this prefix causes APIs to skip some validations that are valuable for the program.</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/28/72/metablogapi/8204.image_4321FF85.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-28-72-metablogapi/8204.image_5F00_4321FF85.png"><img height="252" width="536" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/28/72/metablogapi/5141.image_thumb_4D7323E5.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-28-72-metablogapi/5141.image_5F00_thumb_5F00_4D7323E5.png" alt="image" border="0" title="image" style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" /></a></p>
<p>3: Of course, do not use Windows APIs that do not support file paths that are longer than MAX_PATH in length. Some APIs fail even if you prepend the <a href="file://\\?\">\\?\</a> prefix to the file path. SHFileOperation is one example to these APIs. </p>
<p>4: Wrap the Windows APIs to your own functions so that you will have one entry to control if you need to make any change to the API.&nbsp; </p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/28/72/metablogapi/7536.image_20E9F3FF.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-28-72-metablogapi/7536.image_5F00_20E9F3FF.png"><img height="254" width="538" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/28/72/metablogapi/0777.image_thumb_2B3B185F.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-28-72-metablogapi/0777.image_5F00_thumb_5F00_2B3B185F.png" alt="image" border="0" title="image" style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" /></a></p>
<p>5: Write unit test! To ensure that your code works fine for any file paths with any lengths, write your unit test and validate your code.</p>]]></content:encoded>
    </item>
    <item>
      <title>Debugging Process Crashes</title>
      <link>https://docs.microsoft.com/archive/blogs/emreknlk/debugging-process-crashes</link>
      <pubDate>Thu, 02 Dec 2010 13:03:21 GMT</pubDate>
      <dc:creator><![CDATA[emreknlk]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/emreknlk/2010/12/02/debugging-process-crashes/</guid>
      <description><![CDATA[&#160;  Did I tell you Windbg is a great tool to debug native processes ? However, we still have to...]]></description>
      <content:encoded><![CDATA[<p>&#160;</p>  <p>Did I tell you Windbg is a great tool to debug native processes ? However, we still have to know how to approach the problem. Today, I wanted to debug user mode process crash. When I see a crash, I generally start the process under windbg and run the following command from debugger command window:</p>  <p>sxe eh</p>  <p>This enables the windbg catching first chance exceptions. Normally, first chance exceptions don’t cause a crash so you may not need this command at all but I like seeing what’s going on during execution. If first chance exceptions could not be handled, a second chance exception occurs and now you are in trouble. If you don’t have debugger attached to your process, you see that Window’s pop-up message saying that your process died… </p>  <p>Anyway, catching second-chance exceptions are easy. Windbg does this for you. However, today I encountered with another type of crash. The process just died. No crash message, no dump file, no nothing…. As usual I launched my dear lover, windbg, and attached to the process. I run the process and it died again and I didn’t receive any exception message from the debugger output. I then tried to put breakpoint to ExitProcess function and launched process monitor to see what was going on during crash. Still no luck…</p>  <p>Later, I happened to remember that some windows APIs call invoke_watson when an exception occurs. If you also register your unhandled exception filter, your filter can get called during invoke watson call. After a quick bing, I found the API that’s responsible for executing the filter and put a breakpoint to the API:</p>  <p>bp kernel32!UnhandledExceptionFilter</p>  <p>I let my process go again and voila! The breakpoint hit and I checked the call stack. In my case, the error was coming from swprintf_s API. It tends to validate parameters and call invalid parameter handler if buffer is not allocated in enough size. So, at the end of the day I was happy because I could debug my case and I used a different method to debug a process crash…</p>]]></content:encoded>
    </item>
  </channel>
</rss>