You're copying into the wrong address.
pMyStringAdresspMyStringAdress is a pointer that holds the heap address returned by VirtualAllocVirtualAlloc.
But you used &pMyStringAdress&pMyStringAdress (the address of the pointer variable on the stack) both when printing and in memcpy. That writes past the pointer variable itself and trashes the stack -> "Run-Time Check Failure #2 … stack … was corrupted."
- Fixes
Use pMyStringAdress, hence the message (no &) when printing and copying."Run-Time Check Failure #2 … stack … was corrupted."
Free with VirtualFree when done.Fixes
Minor: use the right printf specifiers.
- Use
pMyStringAdress(no&) when printing and copying. - Free with
VirtualFreewhen done. - Minor: use the right printf specifiers.