Monday, March 15, 2010

Debugging Visual Studio in Release Mode

There will be times when you want to debug in Release mode. To achieve the same, just do the following steps.

  • In Project Settings (Alt-F7) under the "C++/C tab" set the category to "General" and change the Debug Info setting to "Program Database".
  • Under the "Linker tab", in General check the "Generate Debug Info" tab.
  • "Rebuild All"

Wednesday, October 28, 2009

error C2440: ’static_cast’ : cannot convert from ‘UINT (__thiscall CStaticLink::* )(CPoint)’ to ‘LRESULT (__thiscall CWnd::* )(CPoint)’

When we convert a module done in lower versions(ie: VC6 to VS2003) to VS2005 or above in C++, there's a possibility of an error like this. This occurs because of the difference in return types used in older versions of Visual Studio. To make it run, you need to change the return-type UINT to an LRESULT and things should be fine.


UINT CStaticLink::OnNcHitTest(CPoint point)
{
return HTCLIENT;
}

Replace UINT with LRESULT :)

Tuesday, March 17, 2009

CCommandLineInfo

CCommandLineInfo is a MFC class that can be used to parse the command line of the executable. This is a very useful one and is easy to impliment.

If you create a MFC application with the application wizard you will get the lines CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
in the app class´s InitInstance method.

ParseCommandLine will call ParseParam in CCommandLineInfo. To parse your own command line params, derive a class from CCommandLineInfo and override ParseParam method:

void CTestCommandLineInfo::ParseParam( LPCTSTR lpszParam, BOOL bFlag, BOOL bLast ){
if(bFlag)
{
if(lpszParam .strCompareNoCase('sumtext')
{
//some code to deal with the string value associated with lpszParam )
}
state = _0;
}
}
CCommandLineInfo::ParseParam( lpszParam, bFlag, bLast );
}
If you need to parse flags only, you do not need to invent a state system. Then it is enough to ask for bFlag and set some static variable for the parameter given in lpszParam. But if you want to handle parameters with values, you need to set a private state variable if the parameter name is parsed and set the appropriate static variable if the actual value is parsed .