Creating char array from address

C++ and its handling of variables and pointers is still very strange to me. Right now i have ProgramA written in vb.net and ProgramB written in c++, ProgramA allocates and writes (potentially) 199 bytes+200th as number of bytes written to to an address inside ProgramB. ProgramA then passes the memory address to ProgramB and now i want to turn these 199 bytes into a char*

The code that i have is:

char* GetLen = new char[0];
std::memcpy(GetLen, (char*)(lpParameter+199), 1);
char* GetStuff = new char[GetLen[0]];
std::memcpy(GetStuff, (char*)lpParameter, GetLen[0]);

but i get an error saying that lpParameter (a PVOID) has to be a pointer to a complete object type. Please help
In C++, when you add to a pointer, really the size of pointed object is added. For example prt++ will add 1 to prt if ptr is a char* and 4 if ptr is a int*. This is useful when dealing with arrays. *(my_array+1) is the same as my_array[1].
void does not have a size, so apparently C++ doesn't know how much to add. Change that line to ((char*)lpParameter)+199.
Also, I don;t think you can allocate an array of 0 elements, and you definitely don't need to. If you want to allocate 1 char, write = new char;. Though, I don't think you need to use dynamic memory here at all. 2 first lines could simply be char GetLen = ((char*)lpParameter)[199];
Topic archived. No new replies allowed.