使用不同的Platform Toolset时ASSERT()宏的不同行为 [英] Different behavior of ASSERT() macro when using different Platform Toolset
问题描述
Hi,
我使用Visual Studio 2015 Pro(更新3)创建一个简单的Windows控制台应用程序,如下所示
I use Visual Studio 2015 Pro (Update 3) to create a simple windows console app as below
int main()
{
int nRetCode = 0;
HMODULE hModule = ::GetModuleHandle(nullptr);
if (hModule != nullptr)
{
// initialize MFC and print and error on failure
if (!AfxWinInit(hModule, nullptr, ::GetCommandLine(), 0))
{
// TODO: change error code to suit your needs
wprintf(L"Fatal Error: MFC initialization failed\n");
nRetCode = 1;
}
else
{
// TODO: code your application's behavior here.
wprintf(L"Debug Assertion Failed....\n");
ASSERT(FALSE);
wprintf(L"I'm still alive!\n");
}
}
else
{
// TODO: change error code to suit your needs
wprintf(L"Fatal Error: GetModuleHandle failed\n");
nRetCode = 1;
}
return nRetCode;
}
对于Windows 7 x64 Ent
如果我针对Platform Toolset 100或120构建应用程序 - > "Debug Assertion Failed"对话框按预期显示。
If I build the app against Platform Toolset 100 or 120 --> "Debug Assertion Failed" dialog appears as expected.
如果我针对Platform Toolset 140构建应用程序 - >应用程序在此行终止"ASSERT(FALSE)"。没有"Debug Assertion Failed"对话框。
If I build the app against Platform Toolset 140 --> The app is terminated at this line "ASSERT(FALSE)" without "Debug Assertion Failed" dialog.
对于Windows 10 Pro x64(版本1607)
如果我针对Platform Toolset 140构建应用程序 - > "Debug Assertion Failed"对话框按预期显示。
If I build the app against Platform Toolset 140 --> "Debug Assertion Failed" dialog appears as expected.
我的应用程序出了什么问题?
What's wrong with my app ?
请注意:该应用程序内置于DEBUG模式并从命令行运行而没有附加调试器。
Please note that: The app is built in DEBUG mode and run from command line without attached debugger.
推荐答案
Hi,
我用Visual Studio 2015 Pro(更新3)创建一个简单的Windows控制台应用程序,如下所示
I use Visual Studio 2015 Pro (Update 3) to create a simple windows console app as below
int main()
{
int nRetCode = 0;
HMODULE hModule = :: GetModuleHandle(nullptr);
if(hModule!= nullptr)
{
//初始化MFC并在失败时打印和错误
if(!AfxWinInit(hModule,nullptr,:: GetCommandLine) (),0))
{
// TODO:更改错误代码以满足您的需要
wprintf(L"致命错误:MFC初始化失败\ nn");
nRetCode = 1;
}
else
{
// TODO:在此编码应用程序的行为。
wprintf(L" Debug Assertion Failed .... \ n");
ASSERT(FALSE);
wprintf(L"我还活着!\ n");
}
}
其他
{
// TODO:更改错误代码以满足您的需求
wprintf(L"致命错误:GetModuleHandle失败\ N'QUOT);
nRetCode = 1;
}
返回nRetCode;
}
int main() { int nRetCode = 0; HMODULE hModule = ::GetModuleHandle(nullptr); if (hModule != nullptr) { // initialize MFC and print and error on failure if (!AfxWinInit(hModule, nullptr, ::GetCommandLine(), 0)) { // TODO: change error code to suit your needs wprintf(L"Fatal Error: MFC initialization failed\n"); nRetCode = 1; } else { // TODO: code your application's behavior here. wprintf(L"Debug Assertion Failed....\n"); ASSERT(FALSE); wprintf(L"I'm still alive!\n"); } } else { // TODO: change error code to suit your needs wprintf(L"Fatal Error: GetModuleHandle failed\n"); nRetCode = 1; } return nRetCode; }
对于Windows 7 x64 Ent
如果我针对Platform Toolset 100或120构建应用程序 - > "Debug Assertion Failed"对话框按预期显示。
If I build the app against Platform Toolset 100 or 120 --> "Debug Assertion Failed" dialog appears as expected.
如果我针对Platform Toolset 140构建应用程序 - >应用程序在此行终止"ASSERT(FALSE)"。没有"Debug Assertion Failed"对话框。
If I build the app against Platform Toolset 140 --> The app is terminated at this line "ASSERT(FALSE)" without "Debug Assertion Failed" dialog.
对于Windows 10 Pro x64(版本1607)
如果我针对Platform Toolset 140构建应用程序 - > "Debug Assertion Failed"对话框按预期显示。
If I build the app against Platform Toolset 140 --> "Debug Assertion Failed" dialog appears as expected.
我的应用程序出了什么问题?
What's wrong with my app ?
请注意:该应用程序内置于DEBUG模式并从命令行运行而没有附加调试器。
Please note that: The app is built in DEBUG mode and run from command line without attached debugger.
这篇关于使用不同的Platform Toolset时ASSERT()宏的不同行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!