我试图得到一些简单的代码我在网站上发现,在VC++ 2010运行在Windows Vista上64:堆栈被损坏
#include "stdafx.h"
#include <windows.h>
int _tmain(int argc, _TCHAR* argv[])
{
DWORD dResult;
BOOL result;
char oldWallPaper[MAX_PATH];
result = SystemParametersInfo(SPI_GETDESKWALLPAPER, sizeof(oldWallPaper)-1, oldWallPaper, 0);
fprintf(stderr, "Current desktop background is %s\n", oldWallPaper);
return 0;
}
它编译,但当我运行它,我总是得到这样的错误:
Run-Time Check Failure #2 - Stack around the variable 'oldWallPaper' was corrupted.
我不知道是怎么回事错的,但我注意到,那oldWallPaper的价值看起来像“C:\ 0:\ 0 \ 0 U \ 0s \ 0e \ 0r \ 0s [...]“ - 我想知道所有的\ 0s来自哪里。
- 我的一个朋友编译它的Windows XP 32(也VC++ 2010),并能没有问题
任何线索/提示/意见运行呢?
谢谢
你不应该在数组上使用'sizeof',它将不会在你已经有'malloc''d的数组上工作。 – bobobobo 2010-12-03 12:23:17