![](/img/trans.png)
[英]Run-Time Check Failure #2 - Stack around the variable 'application' was corrupted
[英]Run-Time Check Failure #2 - stack around the variable 'osvi' was corrupted on mfc application
我一直在互聯網上搜索,我不知道為什么會這樣,這並不是一個明顯的陣列問題。
功能如下:
BOOL IsOsCompatible()
{
BOOL retVal = 0;
OSVERSIONINFO osvi;
ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
GetVersionEx(&osvi);
if(osvi.dwMajorVersion == 6)
{
if(osvi.dwMinorVersion == 0)
{
if(SendErrorM("This program has not been tested on Windows Vista(TM).\nAre you sure you want to use it?",MB_YESNO) == IDYES)
retVal = 1;
}
else if(osvi.dwMinorVersion == 1)
{
retVal = 1;
}
else if(osvi.dwMinorVersion == 2)
{
if(SendErrorM("This program has not been tested on Windows 8(TM).\nAre you sure you want to use it?",MB_YESNO) == IDYES)
retVal = 1;
}
}
else
SendErrorM("Your windows verison is incompatible with the minimum requirements of this application.",NULL);
return retVal;
}
有任何想法嗎?
OSVERSIONINFOEX
大於OSVERSIONINFO
,因此
ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
將在osvi
“外部”(周圍)寫入零。
你要
OSVERSIONINFOEX osvi;
ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
或(通常更安全)
OSVERSIONINFOEX osvi;
ZeroMemory(&osvi, sizeof(osvi));
多余的X是您的問題:
OSVERSIONINFO osvi;
ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
Windows A,W和X很爛。
避免宏 :
template <typename T>
inline void zero_memory(T& m) {
std::memset(&T, 0, sizeof(T));
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.