how can I copy an allocated buffer of type BYTE* (e.g. BYTE* buffer = new
BYTE[200];) into a variable of type CByteArray? I could not find a solution
in the samples provided...
Best wishes,
Peter
CByteArray barray;
barray.SetSize(200 );
CopyMemory(barray.GetData(), buffer, 200);
--
Scott McPhillips [VC++ MVP]
> how can I copy an allocated buffer of type BYTE* (e.g. BYTE* buffer = new
> BYTE[200];) into a variable of type CByteArray? I could not find a solution
> in the samples provided...
I don't find the method, eiher.
But why do you want to use the ancient CByteArray class? Use a modern
std::vector<> instead:
#include <vector>
std::vector<BYTE> v(buffer, buffer+200);
Or if you define v somewhere else and need to copy the bytes:
#include <vector>
std::vector<BYTE> v;
v.assign(buffer, buffer+200);
Norbert
CByteArray b;
b.SetSize(200);
now put your values in b[i].
If you have the data coming from some outside source (which again, it is very unlikely you
would need to use new to get it!) you might have
void CopyToByteArray(CByteArray & b, LPBYTE data, UINT len)
{
b.SetSize(len);
memcpy(b.GetData(), len, data);
}
but the fact that you said new BYTE[200] is very suspect. There is virtually no need to
use new at all. Please show the code and why you thinhk you need to use new to allocate a
fixed size array, or why you even think you need an array at all.
joe
On Sun, 7 Oct 2007 08:06:02 -0700, Peter Schmitz <PeterS...@discussions.microsoft.com>
wrote:
Joseph M. Newcomer [MVP]
email: newc...@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm