Sep 132014
 
Please Share...

Issue

Today had a customer who was facing warning: RC4005/C4005 after installing VS2013 Update 3. They also had installed the Windows 8.1 SDK. Any new project created in the IDE showed these symptoms so this was not caused by existing code.

Cause

It turned out that his include file settings in project properties was causing this. It was missing a critical include…

$(WindowsSDK_IncludePath)

We added above include as illustrated below and the warnings (RC4005/C4005) went away…

image

Hope this helps save your time. Smile

Please Share...
Aug 052014
 
Please Share...

Had a customer who a opened a ticket for help on this error. The project built fine on Windows 8 but after upgrading to Windows 8.1 he started seeing above error on compilation using a 64 bit toolset.

After much troubleshooting we found the issue to be caused by a pre-release version of WDK installed on his machine. RCToolPath pointed to an older version of WDK8.1.

Customer uninstalled pre-release of WDK (to be precise: Windows Driver Kit for Windows 8.1 Preview) and installed WDK RTM. This resolved the tracker error in this case.

Blogging on this just in case you’re pulling your hair out trying to figure.

Please Share...
Feb 272014
 
Please Share...

What does Side by Side Mean?

Side by Side implementation allows binaries co-exist side by side even with identical names. Well internally the binaries are placed into different folders based on type, name, version, processorArchitecture and publickeytoken. All these elements make up a unique folder/file name. For developers all they need is to embed a manifest into their application which I guess most of you would know. Mostly side by side dependencies are specified via #pragma comment statements or Visual Studio creates a manifest file which is then embedded into the binary using mt.exe. Visual Studio creates a manifest file in the intermediate output folder which follows the following naming convention.

AppOutputFileName.exe.embed.manifest

How is a manifest embedded into an application?

If you build your application then you should see following line in the build output window…

1>Copyright (C) Microsoft Corporation. All rights reserved.
1>Linking...
1>Embedding manifest...

This file will be embedded into the binary as a resource of type RT_MANIFEST which is just an XML file. The OS application loader will pick up this file from the application’s resource section and will figure out application dependencies from the manifest entries.

Viewing Manifest file embedded into an executable file

Viewing Manifest file embedded into an executable file

What does Side by Side Solve?

The intention was to solve dll hell but this itself went on to become a bigger hell making bloggers like me to blog on this issue. Side by Side errors are hard to figure out hence there is a dedicated tool to help figure the errors out. Side by Side concept is cool but got screwed by the numerous ifs and buts that got into this technology.

How does a Side by Side error look like?

Side by side errors are troublesome to troubleshoot. You run an MFC/CRT application on customer machine and you run into error dialogs similar to the one shown below…

image

Don’t get overawed by the error. Its quite easy to troubleshoot, hmm well.

How to troubleshoot Side by Side errors using sxstrace?

As the error message suggests let use sxstrace.exe. The usage of sxstrace is pretty easy to understand…

C:\windows\system32>sxstrace
WinSxs Tracing Utility.
Usage: SxsTrace [Options]
Options:
   Trace -logfile:FileName [-nostop]
       Enabling tracing for sxs.
       Tracing log is saved to FileName.
       If -nostop is specified, will not prompt to stop tracing.
   Parse -logfile:FileName -outfile:ParsedFile  [-filter:AppName]
       Translate the raw trace file into a human readable format and save the re
sult to ParsedFile.
       Use -filter option to filter the output.
   Stoptrace
       Stop the trace if it is not stopped before.
Example:  SxsTrace Trace -logfile:SxsTrace.etl
          SxsTrace Parse -logfile:SxsTrace.etl -outfile:SxsTrace.txt
Collecting sxstrace logs

The command usage message shows us two sample commands and that’s exactly what we’re going to try. Please make sure you’re running an elevated command prompt…

Run the following command…

C:\>SxsTrace Trace -logfile:SxsTrace.etl
Tracing started. Trace will be saved to file SxsTrace.etl.
Press Enter to stop tracing...

So now you’re in tracing mode. Go ahead and run your application which threw the side by side error. Press enter on the command prompt window once you’re done repro’ing the error, this will stop the side by side tracing that’s going on. Once you press enter the ETL trace file will be dumped into the current folder. The dumped trace file is not in human readable format…

Binary output from SxsTrace tool

Binary output from SxsTrace tool

Parsing sxstrace logs

To make it readable, we’ll need to parse this file using sxstrace tool. Run following command to do that…

C:\>SxsTrace Parse -logfile:SxsTrace.etl -outfile:SxsTrace.txt
Parsing log file SxsTrace.etl...
Parsing finished! Output saved to file SxsTrace.txt.

So now we have a text file as output. Lets open the file and find out what went wrong… Contents are as follows…

Parsed output from sxstrace

Parsed output from sxstrace

I’ve annotated the above screenshot for your convenience.

Sample location of a side by side assembly

So basically side by side works based on version of a dll. All side by side binaries go in the winsxs folder located in C:\Windows. For e.g. on my machine msvcr90d.dll is located in the following folder…

Viewing a side by side assembly

Viewing a side by side assembly

If you noticed, the folder name is made up of version number as well. So dll’s belonging to different versions are put in unique folders hence they exists “side by side” hence the name “side by side”.

So the above error means the application couldn’t find msvcr90d.dll in the above location. The way I would solve this is to create a setup project in VC9 and install the merge modules onto the target machine. Please note the dll’s are debug binaries else you could have just installed the redist’s.

Hope this will help you.

Please Share...
Feb 032014
 
Please Share...

DataRepeater is great control to display data from a table/view, as the name says repeats bunch of fields from a dataset on every row. Follow these simple steps to get started working with this control…

Step 1:

Add a reference to the PowerPack library as shown here: http://ntcoder.com/bab/2013/12/20/visualbasic-powerpack-missing-from-visual-studio-2013/

Step 2:

Make sure you’ve got the datasets in place: Press Shift + Alt + D or View –> Other Windows –> Data Sources. See below screenshots of my Northwind dataset…

image

Step 3:

Drag and drop an instance of data repeater onto your win forms or a container control. Resultant form will look as follows…

image

Please note you’ve got to have the right version of DataRepeater in order for it to get displayed on the form designer surface.

Step 4:

Drag and drop fields from your data set onto this data repeater’s surface. Note that every field dropped on to data repeater will be a pair of control (Label followed by text field or any other control if the option is provided, in my case picture control). I’ve got the following fields dropped on to the control…

image

The size of the control at runtime will be the same as the one you’ve given on the designer, unless you’ve docked the control. Scrollbar’s will be provided by the control to scroll through the rows of data.

Step 5:

Now if I run the form this is what I see. You can scroll through as well. Quick way to display data on a form.

image

Step 6:

DataRepeater supports some other features as well, please go through the documentation to know more. Enjoy!

Please Share...
Jan 222014
 
Please Share...

Visual Studio 2013 comes with a new feature called “Debug Managed Memory” this feature also allows to compare managed memory usage across two dumps.  Read on…

This is how you would open a .net 4.5 memory dump in Visual Studio…

imageimage

So for the purpose of this blog I’ve created memory dumps of a managed application that consumes high memory: memtest.exe. I’ve collected three memory dumps…

  1. MemTest.dmp
  2. MemTest (2).dmp
  3. MemTest (3).dmp

For demo purpose I’m opening MemTest (3).dmp ‘first’ as shown in the above screenshot. So once you open the dump in Visual studio this is how Visual Studio will look like…

image

Check out mouse cursor location in the above screenshot. Click on this option. You’ll following dialog pop up….

image

Following which you’ll see the following screen…

image

This report will show the most number of objects on heap. If you notice the largest objects in my case are ArrayLists and second one is MemTest.Form1, too many forms. The also shows you the roots to an object.

Further in the above screenshot, I’ve highlighted an item in red. That option allows us to compare multiple dumps. The resultant report will show you the diff view between the two dumps. For demo I’m comparing MemTest (3).dmp with MemTest.dmp. MemTest (3).dmp was collected after  memtest.dmp was collected so you should ideally see a positive diff between the two dumps as the memory is increasing. See screenshot…

image

You’ll see that, new columns has been added to this report, for e.g. “Cound Diff.”, ‘Size Diff (Bytes)” etc. The bottom table shows you the “Reference Count Diff.” as well.

Really cool feature! Comparing managed memory has been never easier. Please note this feature is only enabled for.net memory dumps that use .net 4.5.

Please Share...
Jan 202014
 
Please Share...

A video presentation on what’s new and cool in Visual Studio 2013 Solution Explorer…

I’ll follow up this presentation with some more presentation on what’s some of the cool things in Visual Studio 2013 just to speed up anyone who’s hopping onto the Visual Studio 2013 wagon.

Please Share...
Dec 202013
 
Please Share...

Where’s the Visual Studio 2013 Visual Basic PowerPack?

Note the VisualBasic PowerPack is not part of Visual Studio 2013 install, it comes as separate MSI. The download link for Visual Basic Powerpack for Visual Studio 2013 is hard to find online as well. I found the link from our internal support article.

Download VB Powerpack (direct link to bits): http://go.microsoft.com/fwlink/?LinkId=321343

Steps to Install Visual Studio 2013 Visual Basic PowerPack

Installing Visual Basic Powerpacks

Installing Visual Basic Powerpacks

Please close any open instances of Visual Studio 2013. Once the installation completes and if you still don’t see the Powerpack controls in the toolbox. Do the following.

  1. Open Visual Studio 2013
  2. Open the toolbox. Add a new tab, right click on the toolbox, select “Add Tab”. Name the tab to “Visual Basic PowerPack”
  3. Expand the new “Tab”. Right click in the empty space under the new tab and select “Choose Item”. You’ll see the following dialog popup…

    Adding reference to Visual Basic powerpack

    Adding reference to Visual Basic powerpack

  4. Please give it few minutes to load all items. Please select “.Net Framework Components” tab if its not already selected.
  5. In the filter text box control please type in “Power”. You should see something like this in the above dialog…

    Choose toolbox items

    Choose toolbox items

  6. Check the relevant ones and add them to your toolbox as shown below…

    Adding Filter for powerpack in the Choose toolbox items dialog

    Adding filter for powerpack in the Choose toolbox items dialog

  7. Once you click ok, you should see the following controls added to your toolbox…

    PowerPack controls listed in VS toolbox

    PowerPack controls listed in VS toolbox

  8. In my case I’ve added all powerpack controls to my toolbox.
  9. You might also have to add a reference to this new powerpack library if you still see compilation errors. Be aware that the assembly name has changed as well…

    Adding reference to new powerpack library

    Adding reference to new powerpack library

Conclusion

We’ve had couple of customer’s who report that Visual Basic powerpack is missing from Visual Studio 2013.
http://connect.microsoft.com/VisualStudio/feedback/details/801421/microsoft-visualbasic-powerpacks-vs-dll

Enjoy the powerpack.

Please Share...
Nov 052013
 
Please Share...

High Memory Usage Scenario

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 accidentally left some GFlags setting configured.

Reminded me of a customer who had an issue wherein all applications 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.

Memory Dump Analysis for High Memory Usage

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.

image

 

Cause of High Memory Usage

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…

image

So if you have application verifier installed on your box you’ll see your application listed 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

Please Share...
Oct 172013
 
Please Share...

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

Please Share...
Oct 072013
 
Please Share...

Code Snippet to Resize CComboBox Drop Down List

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);
 
	Combo.Clear();
 
	for(int Index = 0; Index < 100; ++Index)
	{
		const int TrimLen = rand() % Len;
		_stprintf_s(Buf, _T("%.*s"), TrimLen, lpAVeryLongString);
		Combo.AddString(Buf);
	}
}
 
// Resize combo box drop down width based on contents
void AutoAdjustComboWidth(CComboBox& Combo)
{
	if(!Combo.GetSafeHwnd() || !::IsWindow(Combo.GetSafeHwnd()))
	{
		ASSERT(FALSE);
		return;
	}
 
	CDC& ComboDC = *Combo.GetDC();
	const int RestorePoint = ComboDC.SaveDC();
	CFont& ComboFont = *Combo.GetFont();
 
	ComboDC.SelectObject(&ComboFont);
 
	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(sz.cx > MaxX)
		{
			MaxX = sz.cx;
		}
	}// End for
 
	if(MaxX >  0)
	{
		const int ScrollWidth = ::GetSystemMetrics(SM_CXVSCROLL);
		const int Border = ::GetSystemMetrics(SM_CXEDGE) * 2;
		Combo.SetDroppedWidth(MaxX + ScrollWidth * 2);
	}
 
	ComboDC.RestoreDC(RestorePoint);
}

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,will fix those.

Please Share...