::ZeroMemory(buffer,BUFFERSIZE);
User *u=(User*)buffer;
u->age=20;
u->isShow=false;

int dest=200;
::CopyMemory(u+1,&dest,sizeof(int)); //我在这个结构体大小后面分配一个INT空间用于存放重叠数据现在这个结构体U的大小就是一个结构体加一个整型变量了吧 User *u1=NULL;
::CopyMemory(u1,u,sizeof(User)); //这里系统直接异常 我想这句话有错误吗 ,  但我直接取u+1这个地址都能正确的吧INT 类型的值取出来 但第一次取这个结构体就不行了 为什么啊! 
int dest;
我这样去的 CopyMemory(&dest,u+1,sizeof(int));//这样能正确 
但我如果把 dest定义成指针就异常了 不知道为什么User是我自己定义的一个结构体 

解决方案 »

  1.   

    CopyMemory Function
    Copies a block of memory from one location to another.Syntax
    Copyvoid CopyMemory(
      __in  PVOID Destination,
      __in  const VOID *Source,
      __in  SIZE_T Length
    );
    Parameters
    Destination [in] 
    A pointer to the starting address of the copied block's destination.Source [in] 
    A pointer to the starting address of the block of memory to copy.Length [in] 
    The size of the block of memory to copy, in bytes.Return Value
    This function has no return value.Res
    This function is defined as the RtlCopyMemory function. Its implementation is provided inline. For more information, see Winbase.h and Winnt.h.If the source and destination blocks overlap, the results are undefined. For overlapped blocks, use the MoveMemory function.Security Res
    The first parameter, Destination, must be large enough to hold Length bytes of Source; otherwise, a buffer overrun may occur. This may lead to a denial of service attack against the application if an access violation occurs or, in the worst case, allow an attacker to inject executable code into your process. This is especially true if Destination is a stack-based buffer. Be aware that the last parameter, Length, is the number of bytes to copy into Destination, not the size of the Destination. 
      

  2.   

    这极限的玩bug吧... - -!
      

  3.   

    User *u1=NULL;
    你又没有给你的目标缓冲区分配空间,直接往里拷内容,当然会报错。
    可使用如下代码:
    User *u1 = new User;