0

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

gureedo
  • 315
  • 1
  • 11
Nabeel
  • 123
  • 2
  • 3
  • 11

1 Answers1

2

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:

LPBYTE lp = byBuffer;
return lp;

If that's the case, then the local variable byBuffer is 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.

Mark Ransom
  • 299,747
  • 42
  • 398
  • 622