Gold mine of Visual C++ tricks!
Glorious Bugs
_chdir() pitfall – error while opening file.
Oct 4th
![]()
I still remember that bug! Because it grabbed my two days and delayed the delivery. Well, the story goes like this – It was during late summer of 2004. I was working in a DVD writer project. Internally we were using a third party DVD writer library named BHA Gold. Well, my project was a wrapper library for the BHA Gold library.
Well, the bug was this – There is a config file in my project, which exist in the same folder, together with exe. Before writing DVD, I’ve to read some settings from the config file. But the bug is this. During startup, I could open the file. But if I write one DVD using BHA gold, then when i tried to open the same file once again, it shows error!

![]()
At last its been found that the culprit is the api – _chdir(). The DVD writing library was calling this api internally to prepare the directory tree, and once this api is called, the default directory will be changed to the specified directory and during next time, while opening the setting file, it shows an error that “file not found”! Since the setting file does not exist in the new default directory.
![]()
Well, in such cases you could use the api – SetCurrentDirectory(). See the code snippet to set the current directory as exe’s folder path.
#include "Shlwapi.h"
...
// Get the full path of current exe file.
TCHAR FilePath[MAX_PATH] = { 0 };
GetModuleFileName( 0, FilePath, MAX_PATH );
// Strip the exe filename from path and get folder name.
PathRemoveFileSpec( FilePath );
// Set the current working directory.
SetCurrentDirectory( FilePath );
![]()
Don’t forget to add Shlwapi.lib to project settings.
![]()
Targeted Audience – Advanced.
Interesting bug in VisualStudio!
Jul 15th
![]()
Once in technical forum, a guy asked how to add ampersand( & ) symbol to control captions? Because the ampersand( & ) symbol is used to specify the keyboard accelerator for the control. Have a look at my previous post -
http://weseetips.com/2008/06/15/how-to-add-ampersand-symbol-to-dialog-control-captions/
Visual Studio, the ultimate creator – recommends to add && to make ampersand visible in control captions. But, does the creator himself suffer due to ampersand problem?
Read on…
![]()
Have a look at the properties of Auto variable item in Visual Studio window. It suffers the same bug. The variable name is “&lResult”. But in the properties window, its displayed as “lResult”. See the screenshot.

![]()
Pretty funny, nah? BTW, Was that guy from Microsoft?
(Just kidding)
But I always bow my head in front this legendary compiler suite. Its a classic. I tried a lot, but my heart won’t allow me to switch to the new generation Visual Studio IDEs. Still 6.0 is my favorite. What about you guys? Comment on!
![]()
Targeted Audience – Beginners.
Copy-Paste of source files; Compilation Guard Band's worst enemy.
May 10th
![]()
In big projects, sometimes you want to write almost similar classes, which is more or less similar. For instance, assume you have a request base class, and the derived classes should implement some common virtual functions.
Usually one easy method is to copy-paste one of the existing derived class so that by making minor change, we can start the next derived class. While doing so, just remember – you are making one of the dangerous, hard to detect bug. When you try to compile your source, the second derived class you created, will show the error