Nov 052013

Recently had a customer who was complaining about high memory usage on Windows 8.1. The application consumed about 140 MB on a Windows 8.1 OS as compared to a meager 3 to 4 MB on a Windows 7 or 8 machine.

Hmm interesting. Being experienced in troubleshooting for sometime now this smelled to me like an issue with some kind of debug flag settings. So immediately checked with customer if he has accidently left some GFlags setting configured.

Reminded me of a customer who had an issue wherein all the application on his box started showing high memory usage, eventually this turned out to be an issue with a system wide flag configured via GFlags. GFlags is a helpful tool but please do remember to undo the changes once you’re done with the debugging. Probably stick a sticky somewhere which will hint you to turn off these settings.

So coming back to this incident, hmm why would the application consume high memory on Windows 8.1. Note: He had the application compiled using VS2008.

Checked memory dump of Test.exe running on Windows 8.1 in our debugger and saw that it has some heap validation features enabled. This is the reason why huge amount of memory is being consumed since these heap validation features will require extra memory.

0:000> !heap
Index   Address  Name      Debugging options enabled
  1:   00300000                 tail checking free checking validate parameters
  2:   00c20000                 tail checking free checking validate parameters
  3:   00200000                 tail checking free checking validate parameters
  4:   02170000                 tail checking free checking validate parameters

I was bit surprised as the customer said he doesn’t have GFlags on his box. So I renamed Test.exe to Test1.exe and this is what the dump shows now. Looks like someone’s enabling heap validation flags on Test.exe.

0:000> !heap
Index   Address  Name      Debugging options enabled
  1:   001d0000                
  2:   00c20000                
  3:   02220000                
  4:   00390000

The application memory usage, after renaming, came down to 3.5 MB.


Eventually we figured out who’s turning the heap validation flags on. The integrated Application Verifier included in the Visual Studio Team Suite and Visual Studio Team System for Developers versions of Visual Studio was turning these features on and that was expected as well. The customer had pro version hence he probably didn’t see the settings in project properties. This is how the project property pages will look like…


So if you have application verified standalone application installed on your box you’ll see your application listed there as Visual Studio turns certain registry settings on/off based on your settings. Once your application starts up these settings will take effect. Troubleshooting is fun isn’t it. Smile

Oct 232013

A customer recently asked this question, thought I’ll share the solution out here. Its not that obvious FYI. When creating an MFC MDI application we have an option to enable tabbed view of MDI documents. Once this is done here’s how the application will look like…



Note that except for the first sample image you have multiple tab groups in the rest of the screenshots , this is an inbuilt facility provided by the tabbing framework of MFC. This is important when selecting a tab programmatically: You’ll also have to decide which tab from which group you would like to select.

In MFC framework tab groups are represented by CMDIClientAreaWnd::GetMDITabGroups() which returns a member variable of type CObList. This is how the code looks like…

const CObList& GetMDITabGroups() const { return m_lstTabbedGroups; }

This is a list of tab controls. Each tab control in this group denotes a tab group. So when activating a tab we’ll have to decide which tab in a tab group should be activated.

Following sample code activates the first tab in all the tab groups. Please note tab index starts at zero.

void CMainFrame::OnViewActivatetab()
    const CObList& TabGrps = m_wndClientArea.GetMDITabGroups();
    for (POSITION pos = TabGrps.GetHeadPosition(); pos != 0;)
        CMFCTabCtrl* pNextWnd = DYNAMIC_DOWNCAST(CMFCTabCtrl, TabGrps.GetNext(pos));
Oct 172013

Some useful links…

Visual Studio 2013 Available Now!
Visual Studio 2013 Highlights
System Requirements and Platform Compatibility
Known issues for Visual Studio 2013 (Readme)
Known issues for .NET Framework 4.5.1 (Readme)
Known issues for Visual Studio Team Foundation Server 2013 (Readme)
Windows Store is now open for submitting apps targeting Windows 8.1

Oct 162013

The crash happens as a result of requesting a non-existent API via GetProcAddress, the API is GetThreadPreferredUILanguages. GetProcAddress returns 0xFFBADD11 (a known issue with windows XP where GetProcAddress returns NON-NULL) which means LDRP_BAD_DLL.

To fix this issue override CWinApp::LoadAppLangResourceDLL and prevent loading of the lang dll or set the WINVER macro to target XP builds so that the code using the non-existent API is not compiled into the application (hope its wrapped in a #define).

Oct 152013

By: Darren Laybourn, Corporate Vice President, Windows Phone

A bigger Start screen for more Live Tiles. A new, customizable Driving Mode. Better accessibility options.

These are just some of the new features and innovations that we’re getting ready to deliver to you in Windows Phone 8 Update 3, which will roll out to existing phones over the next several months. As manager of the engineering team responsible for delivering updates to your Windows Phone, today I wanted to tell you a bit more about what’s included in our third official update of the year—plus describe a new preview program we’re launching to help developers keep their apps running smoothly on our latest software.

It’s been a busy but exciting year for my team—and Windows Phone overall. If you follow the news, you might have seen that our market share in Europe has grown to nearly 10 percent. We’re seeing things really start to accelerate. We believe this is because we continue to advance the platform at a rapid pace. Our hardware partners, meanwhile, have been taking advantage of this innovation by releasing amazing new Windows Phone devices throughout the year.

The story behind No. 3

When we sat down to plan our latest official update to Windows Phone 8, we had three main engineering goals in mind:

  1. Enable incredible new Windows Phone devices.
  2. Enhance the platform with new capabilities for current users and partners.
  3. Improve overall quality.
Support for bigger, higher-resolution screens

So the new update paves the way for future Windows Phone devices with 5- and 6-inch touch screens. The larger, 1080p HD displays on these devices will make Windows Phone even more personal—for example by sporting jumbo-sized Start screens with room for six Live Tiles across instead of four.

A bigger Start screen means the ability to pin even more of the people, info, and apps that matter to you. Built-in apps and Hubs like email, Photos, People, and Music and Videos will also be carefully scaled to take full advantage of the additional real estate on 6-inch screens.

A Start screen with room for as many as six Live Tiles side by side.  Windows Phone 8 Update 3 paves the way for larger Start screens like this on future Windows Phone devices with 5- and 6-inch touch screens.

More powerful hardware

In addition to larger screens, Update 3 will also bring support for the Qualcomm Snapdragon 800 quad-core processor. The added horsepower that this chip delivers should make our already-fluid operating system perform even better.

Driving Mode

A new feature called Driving Mode helps you get from point A to point B with fewer distractions. Working with a connected Bluetooth device, Driving Mode is designed to limit notifications on the lock screen—including texts, calls, and quick status alerts—until you’re safely parked.

A new feature of Windows Phone 8 Update 3 called Driving Mode helps you get from point A to point B with fewer distractions.

You can even configure Driving Mode to send automatic replies to people who call or text when you’re behind the wheel, to let them know you’ll get back to them.

New accessibility features

Another highlight of the new update is Mobile Accessibility for Windows Phone 8, which isn’t a single feature but a suite of apps designed to make Windows Phone easier to see, hear, and use. The apps, which include a screen reader, make it easier for blind and visually impaired users to manage calls and contacts, send texts and emails, browse the web, make Skype and Lync calls, and hear notifications like alarms, calendar events, and low-battery warnings.

Improved Internet Sharing

Many of you are familiar with the Internet Sharing feature, which turns Windows Phone 8 into a mobile hotspot by sharing your cellular data connection over Wi-Fi.

In Update 3, we’ve made it easier to use your phone as a data-savvy hotspot for Windows 8.1 devices. Just pair your phone and Windows 8.1 PC or tablet over Bluetooth, tap your network name, and you’ll be connected and ready to go. No need to enter a password or dig out your phone and turn on Internet Sharing—it’s done for you.

But, wait, there’s more

That’s not all we’ve packed into Windows Phone 8 Update 3. Besides hundreds of under-the-hood performance tweaks and enhancements, we’ve also added a bunch of small but handy new features, including several that you’ve been asking for. They include:

  • More useful ringtones: With Update 3, you can use custom ringtones for more things—including instant messages, emails, voicemails, and reminders. You can also assign custom ringtones to contacts for text messages, so you’ll know who’s texting you without even looking.
  • No more twist and shout: Does your screen keep spinning when you’re trying to read emails in bed? Use the new rotation lock option to keep it fixed in place.
  • Better storage management: New storage settings make it easier to free up space on your phone and manage temporary files. A new category view shows what’s taking up space at a glance.
  • Easily close apps: Now you can use the App switcher to quickly close apps when you’re finished with them.
  • Wi-Fi access out of the box: You can now connect to Wi-Fi during phone set up, so you can start conserving cellular data right out of the box.
  • Better Bluetooth: The team made a bunch of improvements to improve connection quality for Bluetooth accessories.

Windows Phone 8 Update 3 adds the ability to assign custom ringtones to contacts for text messages, so you'll know who's texting you without even looking.Does your screen keep spinning when you’re trying to read emails in bed? Use the new rotation lock option to keep it fixed in place.

As you can see, there’s some fun and handy stuff in Windows Phone 8 Update 3. If you have suggestions for future updates, submit them to our Windows Phone Suggestion Box site. We always appreciate the feedback and take it into account as we prioritize new work.

So when will all this be coming to your phone? As I mentioned earlier, the rollout initially kicks off in the coming weeks and will continue over several months. Specific timing depends on a number of factors including your carrier and phone model.

Announcing the Developer Preview Program

Finally, today I’m also happy to announce the Windows Phone Preview for Developers. The program, which officially launches later today, gives app builders early access to our operating system updates so they can verify that their apps work as expected on the new code.

To participate and download Windows Phone 8 Update 3, you need to meet one of three conditions: your phone is “developer-unlocked,” you’re a registered Windows Phone Store developer, or you’re a registered Windows Phone App Studio developer.

You’ll find more details about the new program in a post today on our official Developer Blog. Try it out and let us know what you think, and thanks for your continued interest in Windows Phone!

Darren Laybourn, Corporate Vice President, Windows Phone

Announcing our third Windows Phone 8 update—plus a new developer preview program

Oct 082013

Please note that this post is only applicable for .net 4.5 and above.

Having trouble with .net array size limit, i.e. 2GB on a 64 bit target. Use above tag in your config file to work around this issue. A sample config file will look as follows…

    <gcallowverylargeobjects enabled="true" />

Please read the docs very carefully, there are some caveats that you should be aware off…

Read More

Oct 082013

This how the map network drive dialog look like. So how do we show this dialog programmatically?

Map Network Drive

The windows API’s for showing this dialog is: WNetConnectionDialog and WNetConnectionDialog1. I’ve demonstrated both WNetConnectionDialog and WNetConnectionDialog1 in this code snippet. WNetConnectionDialog is a simple API which takes a window handle and a DWORD. While WNetConnectionDialog1 is an API which provides few more parameters along with the flexibility to set up different options. Here’s the code…

#pragma comment(lib, "Mpr.lib")
void PrvMapNetworkDrive(LPTSTR lptszNetworkPath)
    CONNECTDLGSTRUCT condlg = { 0 };
    condlg.cbStructure = sizeof(condlg);
    condlg.hwndOwner = GetConsoleWindow();
    condlg.dwFlags =  CONNDLG_USE_MRU;

    NETRESOURCE nr = { 0 };
    nr.dwScope = RESOURCE_GLOBALNET;
    nr.dwType = RESOURCETYPE_DISK;
    nr.lpRemoteName = lptszNetworkPath;

    condlg.lpConnRes = &nr;

    const int RetVal = WNetConnectionDialog1(&condlg);
    //const int RetVal = WNetConnectionDialog(GetConsoleWindow(), RESOURCETYPE_DISK);

        cerr << "Error: invalid parameter";
        cerr << "Error: Bad device type";
    case ERROR_BUSY:
        cerr << "Error: Busy";
        cerr << "Error: No network";
        cerr << "Error: Not enough memory";
            DWORD Err = 0;
            TCHAR ErrBuf[MAX_PATH] = {0};
            TCHAR NameBuf[MAX_PATH] = {0};
            WNetGetLastError(&Err, ErrBuf, MAX_PATH, NameBuf, MAX_PATH);
            cerr << "Error: " << ErrBuf;
    case NO_ERROR:
        cout << "No error";
    };// End switch
}// End PrvMapNetworkDrive

I’ve added basic error checks, you’ll have to test this out properly before production usage.

Oct 072013

I had this post in my draft for a long time. This code snippet resizes a combo box’s drop down list. Please note an application sends the CB_SETDROPPEDWIDTH message to set the minimum allowable width, in pixels, of the list box of a combo box with the CBS_DROPDOWN or CBS_DROPDOWNLIST style.

Note: MFC function CComboBox::SetDroppedWidth is just a wrapper for CB_SETDROPPEDWIDTH.

// Fill out combo box with strings of random width, for demo purpose only
void FillCombo(CComboBox& Combo)
	LPCTSTR lpAVeryLongString = _T("This is a very long string, the purpose of which is to test out width calculation of a combo drop down");
	TCHAR Buf[200] = {0};
	const int Len = _tcslen(lpAVeryLongString);
	for(int Index = 0; Index < 100; ++Index)
		const int TrimLen = rand() % Len;
		_stprintf_s(Buf, _T("%.*s"), TrimLen, lpAVeryLongString);
// Resize combo box drop down width based on contents
void AutoAdjustComboWidth(CComboBox& Combo)
	if(!Combo.GetSafeHwnd() || !::IsWindow(Combo.GetSafeHwnd()))
	CDC& ComboDC = *Combo.GetDC();
	const int RestorePoint = ComboDC.SaveDC();
	CFont& ComboFont = *Combo.GetFont();
	int MaxX = -1;
	const UINT ItemCount = Combo.GetCount();
	for(UINT Index = 0; Index < ItemCount; ++Index)
		CString Text;
		Combo.GetLBText(Index, Text);
		// Get width of item string.
		const SIZE sz = ComboDC.GetTextExtent(Text);
		if( > MaxX)
			MaxX =;
	}// End for
	if(MaxX >  0)
		const int ScrollWidth = ::GetSystemMetrics(SM_CXVSCROLL);
		const int Border = ::GetSystemMetrics(SM_CXEDGE) * 2;
		Combo.SetDroppedWidth(MaxX + ScrollWidth * 2);

Some people might find this inconvenient as the list box width grows bigger. The way to workaround this issue is to use CComboBox::SetHorizontalExtent function as demonstrated here.

If you see bugs let me know, I’ll be glad to fix those.

Oct 042013

You’re not going to believe that you have a screen capture tool built into your operating system. LOL yes, its called PSR.exe. PSR stands for Problem Steps Recorder. The ideal usage of this tool is as follows…

  • Capture repro steps (screenshots) for a bug and to send it your customer
  • Capture screenshots for a particular scenario and send it your colleague
  • Capture screenshots on how to use a tool and send to your parents Smile

Its one easy tool to use. I guess its been there since XP. To run this tool go to the “Run” dialog via (Window Key + R). Type in PSR as shown below…


LOL, that’s it? Yep Open-mouthed smile.

Press enter, you’ll see the following dialog pop up…


Now all you need to do is to click “Start Record”. Once you do that this is how the dialog will look like…


Please note that every time you ‘click’, a screenshot is taken, otherwise no screenshots are taken. Once you are done just say “stop record”, you’ll see the following dialog popup, this dialog will have details of all the actions you did along with screenshots. Every screenshot is titled with a detailed description of what you did.


You can review your actions (Review the recorded steps as a slide show ) in slideshow, you can review your actions in “Text” format (click on “Review the additional details”). Note that every step is labeled with a number, for e.g. “Step 1”.

The other feature is that you can add comments to your screenshots via “Add Comment” button while recording.

PSR also provides a settings dialog where can you can turn off Screen capture. Once screen capture is off in your output you’ll just see text as shown below…

Recording Session: ‎10/‎4/‎2013 4:30:50 PM - 4:31:00 PM

Recorded Steps: 8, Missed Steps: 0, Other Errors: 0

Step 1: User left click on "File (menu item)" in "Untitled - Notepad"
UI Elements: File, Application, Untitled - Notepad, Notepad

The best part is yet to come. When you save, it saves all these details in a zip file. Send it to your customer, your team mates or your parents/family. Once you unzip the file, you’ll get just an “mht” file.


Just double click and run, should ideally open up in IE. This is how it looks for me…


Your customer or colleague can view screenshots as a slideshow or they can scroll down and view screenshots. I’m using PSR these days. Thought I’ll share this with you folks as well.