0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

VC6 MFC プロジェクトを .dsp を使わずに VC2005 〜 2026 へ移行・ビルドする手順

0
Last updated at Posted at 2026-09-25

はじめに

古い Visual C++ 6.0(VC6)の .dsp ファイルを使用したプロジェクトを Modern Visual Studio(VC2005 〜 VC2026)環境へ移行する際、プロジェクトファイルの自動変換に頼らず「空の Win32 プロジェクト」から手動で再構築する手順と、必要となるコード修正ポイントをまとめました。


1. 新規プロジェクトの作成とファイル追加

  1. 新しい Visual Studio で「空の Win32 プロジェクト」(または「空のプロジェクト」)を作成します。
  2. 既存のソースファイル(*.cpp、*.h、*.rc など)をプロジェクトに追加します。
  3. プロジェクトのプロパティを開き、[構成プロパティ] -> [全般] -> [MFC の使用] を 「共有 DLL で MFC を使う」(または「スタティック ライブラリで MFC を使う」)に設定します。

VC_2010_iWho_empty.png


2. コードの修正ポイント

DoModal() の戻り値の型変更

64ビット環境や Modern VC では DoModal() の戻り値が INT_PTR に変更されています。int で受けている場合は INT_PTR へ変更します。

// 変更前
// int nResponse = dlg.DoModal();

// 変更後
INT_PTR nResponse = dlg.DoModal();

セキュア関数(_stscanf_s)への対応

VC2005(_MSC_VER >= 1400)以降では、従来の C ランタイム関数に対して警告やエラーが発生する場合があります。コンパイラバージョンで分岐して対応します。

int f_count = 0;
#if (_MSC_VER >= 1400)
    f_count = ::_stscanf_s(strIP.c_str(), _T("172.%d."), &nSecond);
#else
    f_count = ::_stscanf  (strIP.c_str(), _T("172.%d."), &nSecond);
#endif


3. プリコンパイル済みヘッダーの設定

  1. ソースファイル一覧から StdAfx.cpp(または pch.cpp)を右クリックし、[プロパティ] を開きます。
  2. [構成プロパティ] -> [C/C++] -> [プリコンパイル 済みヘッダー] に移動します。
  3. [プリコンパイル済みヘッダー] を 「作成 (/Yc)」 に設定します。
    (※プロジェクト全体のデフォルト設定は「使用 (/Yu)」にしておきます)

4. Winsock 関連の非推奨警告(C4996)への対処(VC2022 / VC2026)

Modern Visual Studio で Winsock の旧 API(::gethostbyname、::inet_ntoa、::inet_addr、::gethostbyaddr など)を使用している場合、C4996 エラー(Use getaddrinfo() or GetAddrInfoW() instead...)が発生してビルドが停止することがあります。

旧 API をそのまま使用する場合は、StdAfx.h の先頭(afxwin.h などのインクルード前)に以下のマクロ定義を追加します。

#ifndef _WINSOCK_DEPRECATED_NO_WARNINGS
#define _WINSOCK_DEPRECATED_NO_WARNINGS
#endif

#include <afxwin.h>

ソースコードおよび詳細情報


※ 本記事の構成および文章の作成には、生成 AI を利用しています。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?