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 way I sometimes get a runtime error: "Stack around the variable String was corrupted"
When I use
TCHAR String[400] = {0};
SendMessageW(hwnd, WM_GETTEXT,10, (LPARAM)String);
it works without problems. But I 开发者_运维问答thought that the whole thing about using sizeof() is to make sure that there is no overflow problems.... Why is sizeof(String) not secure and what could I use instead??
Thanks! and have a nice day!
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);
精彩评论