Daily bytes
Posted by Nibu Thomas on April 7, 2009
Posted in General | Tagged: Article of the day, Famous birthday's, latest news, quote of the day, word of the day | Leave a Comment »
Ordering output of out of order builds in Visual Studio
Posted by Nibu Thomas on June 2, 2009
So what is an out of order build?
If you’ve got a multi-core processor then your compilation process will be distributed between these processors. One project will be built on one core while another one on a different core. Then all of these obj file will be gathered together during linking.
But one problem is that the output will look mangled, see this output…

Out of order builds
The numbers on the left 3>, 4> uniquely identify a particular project being compiled. I’ve got two cores so effectively two projects can be compiled in parallel. But this is a mess particularly if you’ve got too many project’s you’ll have a hard time find out related projects, you’ll get tired of scrolling up and down.
But there is a way to overcome this, at the top of the output window (see above shot) there is a combo “Show output from:”. Change this to “Build Order” from “Build”, now this is how the output will look…

Build output ordered
Just to be complete; you can enable out of order builds via…
Tools->Options->Projects and Solutions->Build and Run->Maximum number of parallel project builds.
Here is a screenshot of this dialog.

Enable Out Of Order Builds
So enjoy working in this great IDE (well)
.
Posted in Visual studio | Tagged: Build order, Ordered Build Output in Visual Studio | 1 Comment »
std::string caveat
Posted by Nibu Thomas on May 18, 2009
Never access an std::string’s buffer with an intent to increase/decrease it’s length nor pass such a buffer to functions which takes a char*. I did this mistake sometime back and got trapped in a strange bug with operator +=. This is how my code looked.
std::string str( ' ', MAX_PATH ); GetFolderName( pFullPath, &str[0] ); // Oop
Problem with above code is that you won’t get an immediate crash since it’s a properly allocated buffer with MAX_PATH chars. But if you do further operations on such string expect plenty of inconsistencies. This is how my code looked after above piece of code…
str += "\\"; // Append backslash
I was expecting a valid path with backslash appended towards it’s end, but this never happened and debugging with debugger too didn’t help.
So now let me tell you what the exact problem is! When you do &str[0] you pass the address to the first char in std::string’s buffer. So when function GetFolderName fills in this buffer with folder path the length of std::string is not updated since it’s a C style function and it’s neither expected to do so. So the function terminates given buffer with a ” with std::string’s length way high (MAX_PATH). So now when I do a += std::string internally fails some condition leading to unexpected results, note that this piece of code never caused a crash but I was quite lucky and watchful enough to fix this stupid bug. Sigh!
So watchout, there is no CString::GetBuffer or CString::GetBufferSetLength type of function for std::string, well at least for now.
Posted in C++, VC++, STL, Strange bugs | Tagged: std::string, Strange bugs, string caveat | Leave a Comment »
Project Conversion Bug in VS2008
Posted by Nibu Thomas on May 11, 2009
Are you having trouble with VS2008 after conversion from VS2005 to VS2008? Most common complaints are that the executable is way to slow when compared to it’s counterpart generated with VS2005. The reason for this is given in this MSDN forum thread have a look…
http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/fb32033b-7bad-439b-a94c-943a17f0cbb2
The essence of this thread is given below (quote from the thread, thanks to Jon Baggott)…
In Visual Studio 2008 SP1 (SP1 not RTM) there is a serious bug with /O2 optimization. One way this bug can be triggered is by upgrading a project from a previous version. Even though the project setting shows the release build is set to /O2, the build can be not optimized at all. To work around it you have to change the setting to no optimization, apply, and then change it back to /O2. The quick way to see if this is needed is to check whether the setting for optimization is in bold or regular – if’s it’s bold you’re OK; if it’s regular text you’re not. This bug has been reported to Microsoft by many people over the past few months via the Connect feedback site but every case has been closed by them without doing anything and for completely invalid reasons.Posted in C++, VC++, Strange bugs, Visual studio | Tagged: Project Conversion Bug in VS2008, VS2005, VS2008 | Leave a Comment »
Where can I find MFC feature pack samples?
Posted by Nibu Thomas on May 5, 2009
People are having trouble finding feature pack samples installed in the samples directory. I too had a similar problem. So what you need to do is to uninstall the previous sample exe that you’ve installed. Then install the samples from here. Good thing about this is that you’ll have an updated samples package.
If you’re still having problems, I’ve uploaded them for you to my blog, please rename this file to zip after downloading or save as zip.
Posted in MFC | Tagged: Feature pack, MFC Feature Pack, MFC Feature Pack Samples | 2 Comments »
Breakpoints in Visual Studio
Posted by Nibu Thomas on May 2, 2009
What’s a breakpoint?
A breakpoint is defined as the location where a debugger breaks execution to allow the user to have a look or to modify the execution context.
What’s new with breakpoints?
With visual studio 2005 and 2008 behavior of breakpoint has changed. Some features that were added are as follows…
- Know hit count of a break point, no more need to keep a temp debugger variable for counting hits. For e.g. you can set a conditional breakpoint and then enable hit count. You’ll see how many times the condition was satisfied, you can also disable breaking of execution so that the program keeps running.
- Trace local variables/function name and more to the visual studio immediate/output window.
- Run a macro when a breakpoint is hit.
- We can disable breaking of execution which means there will only be tracing going on and no breaking of execution.
So to access these features, after adding a breakpoint, open the breakpoint window and right click on this breakpoint. Lower half of the dropdown contains these features, here is a screenshot of the context menu…

Breakpoint Context Menu
There are different types of break points available in visual studio. There are four in my knowledge…
- File breakpoint – Breaks at a location in a file
- Address breakpoint – Breaks at an address
- Function breakpoint – Breaks at a function
- Data breakpoint – Breaks at specific byte locations
Hit count
Let me show you how to count the number of even numbers from 1 to 100, I know it’s quite easy, it’s fifty, but via debugger? Here is a small function with a loop from 1 to 100.
void CountEven( const int From, const int To )
{
for( int Index = From; Index < To; ++Index )
{
// Set a conditional breakpoint to get the count of odd numbers,
// Dummy code to allow set a breakpoint
::SendMessage( AfxGetMainWnd()->GetSafeHwnd(), WM_NULL, 0, 0 );
}
}
Now set a break point inside the for loop (Press F9) and right click and select “Breakpoint->Condition” item. You’ll get the following dialog…

Setting a Conditional breakpoint
So here I’ve set the condition that whenever Index%2 is zero then we have an even number. So when this happens I’m asking the debugger to break execution. So this works as expected but our aim is to count the number of even numbers using debugger, so for that again right click on the breakpoint line and select “Breakpoint->Hit Count” item, following dialog pops up…

Enable hit count in the debugger
You can see that I’ve selected an option called “break when the hit count is a multiple of”. I’ve given 10 as the option, so that frequency of breaking of execution is less. When I run the code this is what I get in the breakpoints window…

Hit count result
See the “Hit Count” item? Execution broke 5 times this means for every 10 hits, hence count is 50. Isn’t this fun?
Tracing
Remember the times when we had to trace statements just for debugging purpose, for e.g. we wanted to trace a certain variable’s value when it satisfies a condition. Let’s take the above example, we’ve already enabled a conditional breakpoint such that it’s breaks execution whenever “Index” is an even number. Right click on the breakpoint line and select “Breakpoint” and then “When Hit” option. Following dialog pops up…

When Hit Dialog
Check the first option Print a message”, this is the option that prints a message either to your “immediate window” or to your “Output window” based on the options that you’ve set. Now run the program to have some fun, this is the output in my computer…

Output of "when hit"
All even index values are traced to the output window, isn’t this cool?
Filter
This one is even more cool. It allows us to set breakpoint filters. This is kind of a conditional but with a larger scope. For e.g. if you want to break execution only for a certain thread or only for a certain process. So for this right click on the breakpoint line and select “Breakpionts->Filter”. Following dialog pops up…

Breakpoint filter
Pretty easy to use. So this means for a function that is called from multiple threads you can explicitly tell the debugger for which threads to break execution.
Tid bits
- Did you know that you can set a breakpoint in the call stack window by press F9?
- Did you know that you can delete all breakpoints by press Ctrl + Shift + F9?
- Did you know that you can run to cursor by pressing Ctrl + F10?
- Did you know that you display breakpoints window by pressing Alt + F9?
- Did you know that you can use “Set Next Statement” by pressing Ctrl + Shift + F10?
Yeap that’s it from me for now, all the best.
Posted in C++, VC++, Debugging, Visual studio | Tagged: breakpoints, debugging tips and tricks, tracing, tutorial, Visual studio | 2 Comments »
MFC Feature Pack – CMFCEditBrowseCtrl
Posted by Nibu Thomas on April 15, 2009
CMFCEditBrowseCtrl?
It’s a specialized edit control (MFC Feature Pack VS2008) with a browse button attached to it’s right side, when we click on this button we get an open file dialog or an open folder dialog. See this sample screenshot.

Browse edit control sample
Also this control allows us to implement our own event handling by overriding OnBrowse function of this class. This a cool control which I like a bit too much since I know how painful it is to get one going.
Some tips on how to make such a control…
- Handle nc calcsize event, so that you can specify size of the area that the browse button will take which in turn results in edit control resizing it’s client area to adjust the button.
- Handle nc paint to draw the button, also you have to force generate an nc calcsize message for once in the beginning.
- Handle mouse up and mouse down event.
Usage
- You should be working in VS2008 SP1 or with Feature pack installation
- Add an edit control to a dialog
- Open .h file of this dialog’s class and add a member variable - CMFCEditBrowseCtrl m_EditBrowse;
- Open .cpp file and add a call to sub class this item in DoDataExchange
DDX_Control( pDX, IDC_EDIT_FILEBROWSE, m_EditBrowse);
- Then in OnInitDialog…
// Note: Only one of these calls will work at a time! m_EditBrowse.EnableFileBrowseButton(); // To show file open dialog m_EditBrowse.EnableFolderBrowseButton(); // To show folder browse dialog m_EditBrowse.EnableBrowseButton(); // To do custom event handling
- That’s it, now you’ve got the browse edit working.
- Note that above calls take some parameters (which has default values) look up in MSDN.
Custom event handling for browse button
Here is a small sample on how to handle custom browse button event handling, taken from MSDN samples…
class CMyBrowseEdit : public CMFCEditBrowseCtrl
{
virtual void OnBrowse()
{
MessageBox(_T("Browse item..."));
SetWindowText(_T("New value!"));
}
};
More…
Use SetBrowseButtonImage to change browse button image, also has an option to maintain such a bitmap or an icon. There are some more virtual functions which could be useful…
- OnDrawBrowseButton – Override to for some additional painting from your side
- OnChangeLayout – Called when browse button mode changes, i.e. from folder to file mode etc (I guess so).
Posted in CodeProject, MFC | Tagged: CEdit, CMFCEditBrowseCtrl, Extending edit controls, MFC Feature Pack | 3 Comments »
Kerala MVPs in the News
Posted by Nibu Thomas on April 8, 2009
Few days back (28th March 209) we MVP’s from kerala were in the news. A local newspaper (Mathrubhumi Calicut edition) published a news item about us. Here is the screenshot, the news item is in Malayalam but I’ve encircled the area with my photograph and news item.
Posted in General, MVP Stuff | Tagged: Mathrubhumi, Microsoft MVP, MVP, MVP news items | 4 Comments »
Script error in VC++ wizards after installing IE8
Posted by Nibu Thomas on April 1, 2009
You might have script errors in VC++ wizards after installing IE8, for e.g. when you double click inside a dialog normally we should taken to corresponding file but instead we get a script error…

Script error
Pretty strange isn’t it. Well as per VC++ team blogs this bug due to IE8 installation. Reason for this behavior is as explained below (quoted from VC++ team blogs…)
The VC++ Wizards Engine implements the IInternetSecurityManager interface. In this implementation it allows or disallows specific actions under certain policies that Internet Explorer queries it about. In IE8 a custom Security Manager now also gets queried about the URLACTION_ACTIVEX_OVERRIDE_REPURPOSEDETECTION policy which IE previously did not delegate to custom security managers when the engine wasn’t running in the iexplore.exe process. The IE engine then fails this action because we don’t have a policy entry for it in the custom zone for VC++ Wizards. We are still investigating whether this change in IE8 is by design and will possibly be addressing it by a fix in either the Wizard or IE components depending on the outcome.And according to this blog, following fix should work….
Please follow the following steps:- Open regedit (on a 64-bit OS, open the 32-bit regedit)
-
Under “HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet
Settings\Zones”, create a new key called 1000 (if it isn’t already there) -
Under 1000, create a DWORD entry with:
- o Name = 1207
- o Type = REG_DWORD
- o Data = 0×000000
Just now I had this problem hence I had to use this fix and it works.
Posted in Strange bugs, Visual studio | Tagged: IE8 bug in VC++ wizards, Script error in visual studio, Visual studio | 3 Comments »














. So a workaround is to open .rc file in a text editor and add WS_HSCROLL style manually for this combo.
