Valhalla Legends Archive

Programming => General Programming => C/C++ Programming => Topic started by: Eli_1 on May 20, 2004, 07:06 PM

Title: Quick CopyMemory Question
Post by: Eli_1 on May 20, 2004, 07:06 PM
Just wondering how to use CopyMemory like the PacketBuffer class uses it.

VB:

'MakeWORD
Dim Result As String * 2    
CopyMemory ByVal Result, Value, 2


How do I do the String * 2 in C++, or is that not needed?

C++??

// If this is wrong please tell me why
char Result[1]; // 0-1 (2)?
CopyMemory( Result, Value, 2 );

Title: Re:Quick CopyMemory Question
Post by: K on May 20, 2004, 07:25 PM

WORD wValue = 0xabcd; // or unsigned int
BYTE bResult[2]; // or unsigned char / char.

memcpy(bResult, wValue, 2); // or CopyMemory.


edit: for arrays, the number inside the brackets indicates how many elements are in the array.  the indeces of the array are from 0 to that number minus one.

int myarray[15]; has indeces of 0-14 for a total of 15 items.
Title: Re:Quick CopyMemory Question
Post by: Eli_1 on May 20, 2004, 07:29 PM
Ok, thanks.

Blah and I knew about arrays too. That was just a stupid mistake.  :(