Pages

Tuesday 9 January 2007

Porting unmanaged C++ code from VS2003 to VS2005

This should normally not cause too much trouble, after all, it's the same language and the same platform. Only the compiler changes a little. The VS2005 compiler does extra checks, especially in the 64bits and security area.

Warning C4244: 'initializing' : conversion from 'INT_PTR' to 'int', possible loss of data

  • Solution: disable Detect 64-bit portability issue in the project options Configuration Properties > C/C++ > General.

Warning C4996: 'sprintf' was declared deprecated

  • Solution: use the new and secure sprintf_s.

Reference: Deprecated CRT Functions

Note: don't use the new secure functions if you intend to keep compiling under VS2003. VS2003 projects will break if the new secure CRT functions are used. To disable the warnings, define _CRT_SECURE_NO_WARNINGS.

Warning C4996: 'itoa' was declared deprecated

  • Solution: replace itoa with _itoa or _itoa_s ...or use a CString (which is more elegant):

Warning C4996: '_fcvt' was declared deprecated

  • Solution: use _fcvt_s or CString.

Warning C4482: nonstandard extension used: enum 'CSecureRst::OperatorTypeEnum' used in qualified name

  • Solution: don't write the name of the enum type when specifying the enum.

No comments: