VC++2013出現bug: 無法打開源文件“stdafx.h”
1、首先需要把#include "stdafx.h"置於最頭
2、在解決方案資源管理器中添加以下幾個文件(附圖下)
3、文件的內容分別為
①、targetver.h
#pragma once
// 包括 SDKDDKVer.h 將定義可用的最高版本的 Windows 平台。
// 如果要為以前的 Windows 平台生成應用程序,請包括 WinSDKVer.h,並將
// WIN32_WINNT 宏設置為要支持的平台,然后再包括 SDKDDKVer.h。
#include <SDKDDKVer.h>
②、stdafx.cpp
// stdafx.cpp : 只包括標准包含文件的源文件
// TestCPPDLL.pch 將作為預編譯頭
// stdafx.obj 將包含預編譯類型信息
#include "stdafx.h"
// TODO: 在 STDAFX.H 中
// 引用任何所需的附加頭文件,而不是在此文件中引用
③、stdafx.h
// stdafx.h : 標准系統包含文件的包含文件,
// 或是經常使用但不常更改的
// 特定於項目的包含文件
//
#pragma once
#include "targetver.h"
#define WIN32_LEAN_AND_MEAN // 從 Windows 頭文件中排除極少使用的信息
// Windows 頭文件:
#include <windows.h>
④、dllmain.cpp
// dllmain.cpp : 定義 DLL 應用程序的入口點。
#include "stdafx.h"
BOOL APIENTRY DllMain(HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
編譯即可運行成功