I am working on Visual studio C++.
I have these codes:
CString str;
BYTE byBuffer[10000] = { 0 };
str ="Invalid Command. Spaces are not allowed too!!";
strcpy_s(reinterpret_cast<LPSTR>(byBuffer), 10000, T2CA(str ));
The problem is byBuffer = “Invalid Command. Spaces are not allowed too!!”; but after the following line, the string changes.
LPBYTE lp=byBuffer ; Although it works fine for small strings like OK, GOOD JOB. etc..
i am debugging the whole code by setting the breakpoints. moreover this function has been called to another function in which ( LPBYTE lpBuffer) recieved this value.
Plz help
The code you’re showing us looks OK, so I’m going out on a limb and making a guess.
I’m guessing that you’re trying to return this buffer from a function:
If that’s the case, then the local variable
byBufferis getting destroyed at the end of the function and the pointer no longer points to valid memory. You’re lucky if you can see anything recognizable in the output at all.