网站首页  词典首页

请输入您要查询的函数:

 

术语 copymemory
释义 CopyMemory
语法:
C++
void CopyMemory(
__in PVOID Destination,
__in const VOID *Source,
__in SIZE_T Length
);
CopyMemory函数
副本1块从一个位置到另一个内存。
参数
Destination [in]
阿以复制的块的目的起始地址的指针。
来源 [in]
是对的内存块的起始地址指针的副本。
Length [in]
该内存块大小的复制,以字节为单位。
返回值
这个函数没有返回值。
备注
这个函数被定义为RtlCopyMemory功能。在实施过程中提供的内联。有关更多信息,请参阅Winbase.h和WINNT.H中。
如果源和目标块重叠,结果是不确定的。对于重叠块,使用MoveMemory功能。
安全备注
第一个参数,目标,必须大到足以容纳源长度字节,否则,可能会出现缓冲区溢出。这可能导致对服务的应用程序如果发生访问冲突或攻击予以否认,但最坏的情况下,允许攻击者注入到可执行代码的过程。尤其如此,如果目的地是一个基于堆栈的缓冲区。请注意,最后一个参数,长度,是字节数复制到目的地,而不是大小的目标。
实例
下面的代码示例显示了一个更安全的方式使用CopyMemory。或者,您可以使用memcpy_s或wmemcpy_s功能。

#include
#include
#include
#define BUFFER_SIZE 1024
#define COPY_SIZE 512
/*
MyCopyMemory - A wrapper for CopyMemory
buf - destination buffer
pbData - source buffer
cbData - size of block to copy, in bytes
bufsize - size of the destination buffer
*/
void MyCopyMemory(TCHAR *buf, TCHAR *pbData, SIZE_T cbData, SIZE_T bufsize)
{
CopyMemory(buf, pbData, min(cbData,bufsize));
}
void main()
{
TCHAR buf[BUFFER_SIZE] = TEXT("This is the destination");
TCHAR pbData[BUFFER_SIZE] = TEXT("This is the source");
MyCopyMemory(buf, pbData, COPY_SIZE*sizeof(TCHAR), BUFFER_SIZE*sizeof(TCHAR));
_tprintf(TEXT("Destination buffer contents: %s\\n"), buf);
}

要求:
最低支持:client-Windows 2000专业版
最低支持server-Windows 2000服务器
HeaderWinbase.h(头文件:winuser.h)
参见
FillMemory
内存管理功能
MoveMemory
SecureZeroMemory
ZeroMemory
如果有任何问题和意见,请发送给微软(wsddocfb@microsoft.com)
生成日期:2009年8月27日
==英文原文==CopyMemory Function
Copies a block of memory from one location to another.
Syntax
C++
void 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.
Remarks
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 Remarks
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.
Examples
The following code example shows a safer way to use CopyMemory. Alternatively, you could use the memcpy_s or wmemcpy_s function.
#include
#include
#include
#define BUFFER_SIZE 1024
#define COPY_SIZE 512
/*
MyCopyMemory - A wrapper for CopyMemory
buf - destination buffer
pbData - source buffer
cbData - size of block to copy, in bytes
bufsize - size of the destination buffer
*/
void MyCopyMemory(TCHAR *buf, TCHAR *pbData, SIZE_T cbData, SIZE_T bufsize)
{
CopyMemory(buf, pbData, min(cbData,bufsize));
}
void main()
{
TCHAR buf[BUFFER_SIZE] = TEXT("This is the destination");
TCHAR pbData[BUFFER_SIZE] = TEXT("This is the source");
MyCopyMemory(buf, pbData, COPY_SIZE*sizeof(TCHAR), BUFFER_SIZE*sizeof(TCHAR));
_tprintf(TEXT("Destination buffer contents: %s\\n"), buf);
}
Requirements
Minimum supported clientWindows 2000 Professional
Minimum supported serverWindows 2000 Server
HeaderWinbase.h (include Windows.h)
See Also
FillMemory
Memory Management Functions
MoveMemory
SecureZeroMemory
ZeroMemory
Send comments about this topic to Microsoft
Build date: 8/27/2009
==原始网址==http://msdn.microsoft.com/en-us/library/aa366535(VS.85).aspx\n
随便看

 

windows api函数参考手册包含2258条windows api函数文档,详细介绍nodejs、java、rust调用windows api的方法技巧,是学习windows api编程的入门中文文档。

 

Copyright © 2004-2023 Winrtm.com All Rights Reserved
京ICP备2021023879号-40 更新时间:2024/10/6 13:18:40