首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

VC6会运行的代码VS2010不能运行

2012-08-25 
VC6能运行的代码VS2010不能运行#include windows.h#include stdio.h#pragma comment(linker, /INCREM

VC6能运行的代码VS2010不能运行


#include "windows.h"
#include "stdio.h"

#pragma comment(linker, "/INCREMENTAL:NO") 

void Fun()
{
  MessageBox(0,0,0,0);
}

void main()
{
  LPVOID p = malloc(0x100);
  memcpy(p,Fun,0x100);
  _asm call p;
}


这段代码在Visual C++ 6.0里能运行,但是到了Visual Studio 2010里就不行了。
只有把malloc改成VirtualAlloc才行,为什么会这样啊,malloc会失败。







[解决办法]
刚才测试了一下,应该是malloc分配的内存的页属性的问题。
[解决办法]
Routine, Required Header
malloc, <stdlib.h> and <malloc.h> 
memcpy, <memory.h> or <string.h> 

热点排行