Defining buffer size correct “Stack around the variable String was corrupted”

后端 未结 1 1849
甜味超标
甜味超标 2021-01-24 15:18

I have these two lines in my code:

TCHAR String[400] = {0};
SendMessageW(hwnd, WM_GETTEXT,sizeof(String), (LPARAM)String);

When I use it that w

1条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-24 15:42

    You are using wchar_t, sizeof(String) will be 800, not 400. Fix:

    wchar_t String[400] = 0;
    SendMessageW(hwnd, WM_GETTEXT, sizeof(String) / sizeof(wchar_t), (LPARAM)String);
    

    0 讨论(0)
提交回复
热议问题