::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是我自己定义的一个结构体
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是我自己定义的一个结构体
解决方案 »
- opencv2.3.2使用_cvUpdateMotionHistory函数//不知道是在那个lib与头文件呢???
- htm 脚本运行 出错 js代码
- 结构包含类的问题
- 关于CreateFile
- 调用HtmlHelp始终不能成功
- 有关hook api的问题
- 我用WININET库函数,写一个支持upload/download的ftp客户端,目前已经可以支持下载续传,但上传时,总是不正确,怎么解决?
- 相关文件的读写问题,请指教,谢谢!
- 关于进程钩子(HOOK)和API重定向的一个问题!
- 用ATL做的控件怎样放在网上
- 如何将数据库(Access2000)与串行接口连接
- win7下使用原始套接字截包的问题?
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.
你又没有给你的目标缓冲区分配空间,直接往里拷内容,当然会报错。
可使用如下代码:
User *u1 = new User;