Copy and Store LPTSTR in class causes crash

Posted by Jake M on Stack Overflow See other posts from Stack Overflow or by Jake M
Published on 2012-06-11T10:04:44Z Indexed on 2012/06/11 10:40 UTC
Read the original article Hit count: 266

Filed under:
|

I am attempting to copy a LPTSTR and store that string as a member variable in an object. But my attempts to copy the LPTSTR seem to fail and when I go to access/print the value of the copied LPTSTR I get a program crash.

Is it possible to copy a LPTSTR and store it in my class below or is it better to just use a TCHAR*?

class Checkbox
{
   private:
      LPTSTR text;
      HWND hwnd;

   public:
      Checkbox(HWND nHwnd, LPTSTR nText)
      {
        lstrcpy(checkText, text); 
      }

      void print()
      {
        // Causes a crash
        MessageBox(hwnd, text, text, MB_OK);
      }
};

© Stack Overflow or respective owner

Related posts about c++

Related posts about winapi