简体   繁体   中英

Memory error with type L“” in Win32

Here's the code for my paint method in my Win32 project:

case WM_PAINT:
    _tcscat_s(greeting, sizeof(greeting), LoadedFile);
    hdc = BeginPaint(hWnd, &ps);

    TextOut(hdc,  
        5, 5,  
        greeting, _tcslen(greeting));

    EndPaint(hWnd, &ps);
    break;

I am consistently getting the error that either the stack around greeting or around ps is corrupted. To be clear, greeting is initialized like:

TCHAR greeting[100] = _T("Welcome! Your file is ");

And LoadedFile is initialized like this:

TCHAR LoadedFile[100];
LoadedFile[0] = 0;

LoadedFile is not yet changed by anything, so it shouldn't be adding anything to greeting . I've tried things like

sizeof(greeting) + 1

Which just shifts the error. Not sure what's wrong here.

Edit: Without the _tcscat_s() , call the window loads normally

Well, I found the problem, even though I don't really understand why the solution works. I just changed

 _tcscat_s(greeting, sizeof(greeting), LoadedFile);

to

_tcscat_s(greeting, 100, LoadedFile);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM