Why AfxGetThread() returns NULL in AfxWinMain()?

Recently I worked with one of my colleague on an interesting scenario in which the MFC application was crashing on startup. The next step was to run the application under WinDbg. After running the application under WinDbg we saw that we are actually access violating an address which was indeed a NULL pointer. The access…

2

Troubleshooting "Not a valid win32 Application" error at the startup.

Recently, we came across a very interesting issue. A purely native application written in C++ was failing with “Not a valid win32 application” error at the startup on Windows XP machine.   There are a few basic checks that we do to troubleshoot this error. We did the following checks: 1)      Checked if all the modules…

2

Porting C++ native code to managed (/clr) – Threads

In native world, one interacts with OS directly by calling Win32 APIs for managing resources (like allocating/deallocating memory,opening/closing handles). In managed world one  relies on CLR totally or at times partially for doing the same( eg GC does memory management for us).Due to lack of understanding of the way CLR does the work for us,  we may at times conclude…

1

Marshalling Complicated Structures using PInvoke

This article talks about marshaling structures using PInvoke which has a pointer to an array of another structure as a member. When calling native functions in a managed application, a frequent question that comes to mind is how to marshal a nested complicated structure.  Recently I came across a scenario where we have to marshal…

3

Troubleshooting Manifest-Related Issues

After migrating to Visual Studio 2008 SP1 and building the application, the manifest file of application and all the dependent DLL’s contain RTM version. In Visual Studio 2008 SP1, by design, the manifest for the created exe links it to the RTM version of the CRT. In Visual Studio 2005 SP1, by design, the manifest…

8

Sort function of STL Gives Unexpected Output when Vector is a Type Derived from _com_ptr_t

  C++ code which contains an STL vector containing types derived  from  the_com_ptr_t  COM smart pointer class and using the std:sort() function to sort interface pointers may give unexpected sort output._com_ptr_t COM smart pointer derived types are commonly created when using the ‘#import’ keyword in C++ to import a COM type library. For example: #import…

2

Troubleshooting CRT heap corruption

This article focuses on troubleshooting a heap corruption caused by writing into the next allocated block. Heap corruption comes into notice when the overridden memory is accessed, leaving in a state where it becomes hard to figure out the original code that is overriding the memory.   In this scenario, call stack could look like…


Robots are back!

  Robots will soon be in action moving around you, to make your life easier. This is not the tagline from the Hollywood movie “I, Robot” but is a real life fact! Yes, this is a dream come true. In the third week of November 2008, we proudly introduced Microsoft® Robotics Developer Studio 2008 (RDS),…


A chalktalk on .NET troubleshooting at Vitual Tech Days

This was my yet another venture with Microsoft Evangelism team. I was invited as the Speaker on .NET troubleshooting in the chalktalk session where developers all across logged in to the live meeting and threw a lot of questions on me. The DPE team recorded all the sessions during the event and they are available for…