Windows 在win32 console项目中生成日志文件时出错
我有一个生成日志文件的代码:-Windows 在win32 console项目中生成日志文件时出错,windows,visual-studio-2010,visual-c++,mfc,ini,Windows,Visual Studio 2010,Visual C++,Mfc,Ini,我有一个生成日志文件的代码:- // INI.cpp: implementation of the CINI class. //#include "stdafx.h" #include "INI.h" #include <iostream> #ifdef _DEBUG #undef THIS_FILE static char THIS_FILE[]=__FILE__; #define new DEBUG_NEW #endif CINI::CINI(char* szFile
// INI.cpp: implementation of the CINI class.
//#include "stdafx.h"
#include "INI.h"
#include <iostream>
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
CINI::CINI(char* szFileName)
{
memset(m_szFileName, 0x00, 255);
memcpy(m_szFileName, szFileName, strlen(szFileName));
}
CINI::~CINI()
{
}
float CINI::ReadFloat(char* szSection, char* szKey, float fltDefaultValue)
{
char szResult[255];
char szDefault[255];
float fltResult; sprintf(szDefault, "%f",fltDefaultValue);
GetPrivateProfileString(szSection, szKey, szDefault, szResult, 255, m_szFileName);
fltResult = atof(szResult); return fltResult;
}
bool CINI::ReadBoolean(char* szSection, char* szKey, bool bolDefaultValue)
{
char szResult[255];
char szDefault[255];
bool bolResult;
sprintf(szDefault, "%s", bolDefaultValue? "True" : "False");
GetPrivateProfileString(szSection, szKey, szDefault, szResult, 255, m_szFileName);
bolResult = (strcmp(szResult, "True") == 0 || strcmp(szResult, "true") == 0) ? true : false; return bolResult;
}
char* CINI::ReadString(char* szSection, char* szKey, const char* szDefaultValue)
{
memset(m_szResult, 0x00, 255);
GetPrivateProfileString(szSection, szKey, szDefaultValue, m_szResult, 255, m_szFileName);
return m_szResult;
}
void CINI::WriteInteger(char* szSection, char* szKey, int iValue)
{
char szValue[255]; sprintf(szValue, "%d", iValue);
WritePrivateProfileString(szSection, szKey, szValue, m_szFileName);
}
void CINI::WriteFloat(char* szSection, char* szKey, float fltValue)
{
char szValue[255];
sprintf(szValue, "%f", fltValue);
WritePrivateProfileString(szSection, szKey, szValue, m_szFileName);
}
void CINI::WriteBoolean(char* szSection, char* szKey, bool bolValue)
{
char szValue[255]; sprintf(szValue, "%s", bolValue ? "True" : "False");
WritePrivateProfileString(szSection, szKey, szValue, m_szFileName);
}
void CINI::WriteString(char* szSection, char* szKey, char* szValue)
{
WritePrivateProfileString(szSection, szKey, szValue, m_szFileName);
}
当我包含StdAfx.h和StdAfx.cpp时,我得到以下错误:-
c:\program files\microsoft visual studio 10.0\vc\atlmfc\include\afx.h(24): fatal error C1189: #error : Building MFC application with /MD[d] (CRT dll version) requires MFC shared dll version. Please #define _AFXDLL or do not use /MD[d]
StdAfx.cpp
1>c:\program files\microsoft visual studio 10.0\vc\atlmfc\include\afx.h(24): fatal error C1189: #error : Building MFC application with /MD[d] (CRT dll version) requires MFC shared dll version. Please #define _AFXDLL or do not use /MD[d]
1> INI.cpp
1>c:\program files\microsoft visual studio 10.0\vc\atlmfc\include\afx.h(24): fatal error C1189: #error : Building MFC application with /MD[d] (CRT dll version) requires MFC shared dll version. Please #define _AFXDLL or do not use /MD[d]
我正在使用VS2010,需要构建win32控制台项目。请提供帮助。您必须更改项目的属性: 转到项目->属性(最后一个菜单项)->配置属性->常规 在这里,您将看到带有“使用MFC”选项的“项目默认值”部分。选择“在静态库中使用MFC”
基本上,您会遇到冲突,因为在代码生成设置中,选择了多线程静态运行时库,而您尝试使用的MFC库是使用基于dll的C运行时构建的。Sir您提到的上述解决方案在这种情况下,是否在项目中包括StdAfx.h和StdAfx.cpp,如果案例不包括StdAfx.h和StdAfx.cpp,并在代码生成中选择运行库Libraray作为/MT,我将得到以下错误LIBCMT.lib(invarg.obj):错误LNK2005:u initp_misc_invarg已经在libcmtd.lib(invarg.obj)1>LIBCMT.lib(invarg.obj):错误LNK2005:u call_reportfault已经在libcmtd.lib中定义(g.obj)