How to debug a function in release mode

29 07 2015

The Visual Studio IDE provides different optimization options that help us to create code for maximum speed or minimum size. Mostly we select /O1 optimizes code for minimum size when we build our project in release configuration. But you might be observed that the variable values may not be displayed correctly in the watch window if we try to debug our source code in release configuration. Of-course, we have options to enable debugging support in release mode. But just think in case if you want to debug just one function in release mode!!!

Pragma directives specify machine- or operating-specific compiler features. The compiler optimization can be performed on a function-by-function basis using #prgma optimize statement.

#pragma optimize( "[optimization-list]", {on | off} )

We can disable the optimization using the optimize pragma with the empty string (“”).

#pragma optimize( "", off )
void FunctionToDebug()
#pragma optimize( "", on ) 

Some pragmas provide the same functionality as compiler options. When a pragma is encountered in source code, it overrides the behavior specified by the compiler option.

How to convert a ANSI/MB project into a UNICODE

14 05 2013

Most of the time we may need to give multiple language support for our applications. Incase if we need to support Russian or Chinese language means, definitely we have to give Unicode support for our application. So here I would like to share some tips for converting existing ANSI/MultiByte project into Unicode.

If we build our project in Multi-byte character set it will allocate 1 byte for one character. This is enough for representing all English letters. But if we build our project in Unicode character set it will allocate 2 bytes for each letters. It is required for representing Russian and Chinese letters.

Below are some suggestions for converting MBCS to Unicode project

Step 1: Create new configuration from Project Configuration Manager. Give name something like ReleaseUnicode/DebugUnicode.

Step 2: Change Character Set to Unicode from Project Settings.


Step 3: Replace all char datatype with TCHAR. This will automatically switch to normal char or wchar_t based on it is compiled as MBCS or Unicode respectively.

Step 4: Add _T as prefix to each string text. eg: _T(“Hello World”)

Step 5: Replace LPSTR and LPCSTR with LPTSTR and LPCTSTR respectively.

Step 6: Replace following win32 APIs with corresponding Generic equivalent for same.

strstr _tcsstr
strcmp _tcscmp
sprintf_s _stprintf_s
strlen _tcslen
_stricmp _tcscmp
strcpy_s _tcscpy_s
atol _tstol
atoi _tstoi
atof _tstof
strcspn _tcscspn
fopen_s tfopen_s
strtok_s _tcstok_s
strtol _tcstol
strtoul _tcstoul

How to put a vertical line after a certain amount of chars in VS2008 IDE

15 01 2009




We are following different coding standards while programming in different languages. That is very effective to improve the readability of the code. Sometimes we need to fix 80th column as the bounday in the Visual Studio text editor. That means it’s better to draw a vertical line after a certain amount of characters in the Text Editor.





First of all open the RegEdit and locate the following. 

HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\9.0\Text Editor and create a string called Guides with the value RGB(255,0,0) 80 to have a red vertical line at the column 80 in the VS text editor. You can add multiple lines in your text editor by adding the string value RGB(255, 0, 0) 80, RGB(0,255, 0) 49

Restart Visual Studio after you add these values for the changes to take effect. 





I think it is working fine in VS2003 and VS2005 also. If you are using that version please try with the following registry path.

VS2005 : HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\8.0\Text Editor

VS2003:  HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\7.1\Text Editor