以前,VC 6 プロジェクトを移行する時の,設定などについて書いた.
VC6 から 2005 , 2008
VC6 から 2010 – 2019
VC6 から 2022 –

今回は C++ コードの変更などのまとめ.
アプリケーションクラス InitInstance の次の呼出しを削除.
#ifdef _AFXDLL
Enable3dControls();
#else
Enable3dControlsStatic();
#endif
文字や文字列を _T() で括る.
‘A’ –> _T(‘A’)
"abc" –> _T("abc")
_MBCS では問題ないコードが _UNICODE で,CString 変数のポインタが値として解釈されることがある.
その場合は LPCTSTR() で括れば良い.
str –> LPCTSTR(str)
C スタイルの文字列に関連する CString の操作方法
CString⇒LPTSTR変換
文字列操作関数の _UNICODE 対応と _s 対応.
_t で始まる関数に置き換え.また gcc などでも通る様に _tdefine.hxx を用意.
_MSC_VER により,_s 版と以前のものを切替える関数群を用意.
int を INT_PTR などに(x64 対応).
CArray::GetSize など,MFC の色々な所で int が INT_PTR に変更された.
int size = array.GetSize() ; –> INT_PTR size = array.GetSize() ;
ダイアログベースの時も同様に.
OnTimer も UINT を UINT_PTR に.
afx_msg void OnTimer (UINT_PTR nIDEvent);
sprintf など,可変長引数を使用している部分の修正.
古いコードで使用しているだけなので,#if defined (__cplusplus_cli) で切り分けることにした.
ビジュアルスタイルを有効にするため,stdafx.h の最後の方に追加.
#if _MSC_VER >= 1400
#ifdef _UNICODE
#if defined _M_IX86
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"")
#elif defined _M_IA64
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='ia64' publicKeyToken='6595b64144ccf1df' language='*'\"")
#elif defined _M_X64
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"")
#else
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
#endif
#endif
#endif
* まだ作成途中です.
Microsoft C/C++ 2003 – 2015 の変更履歴
Visual C++ 移植およびアップグレード ガイド
[…] VC6 プロジェクトのコードの移行 […]