开发者

0xC0000005: Access violation reading location 0x4fa2b3f1 when doing CStatic.Create

开发者 https://www.devze.com 2023-03-18 23:44 出处:网络
I have problem with CStatic. So I have this: CStatic * lblPresent; SetWindowPos(NULL,GetSystemMetrics(SM_CXSCREEN)/2-234,0,0,0,SWP_NOSIZE | SWP_NOZORDER);

I have problem with CStatic. So I have this:

    CStatic * lblPresent;
    SetWindowPos(NULL,GetSystemMetrics(SM_CXSCREEN)/2-234,0,0,0,SWP_NOSIZE | SWP_NOZORDER);
    lblPresent=new CStatic();
    wstring wtemp=L"Welcome";
    tempChar = new WCHAR[wtemp.length()+1];
    wcscpy_s(tempChar, wtemp.size()+1, (LPWSTR)wtemp.c_str());
    lblPresent->Create(tempChar, WS_CHILD | WS_VISIBLE,CRect(20, 90, 448, 130), this);

When it reach that last line, it says:

Unhandled exception at 0x6e54ba20 in CPTest.exe: 0xC0000005: Access violation reading location 0x4fa2b3f1.

When I step over using debugger, it 开发者_StackOverflow中文版brings me to this:

AfxWndProcDllStatic(HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam)
{
    AFX_MANAGE_STATE(&afxModuleState);
    return AfxWndProc(hWnd, nMsg, wParam, lParam);
}

The exception seems to happen in that line that returns, with the values (written in the watch):

        hWnd    0x001a01d0 {unused=0 }  HWND__ *
        lParam  0                       long
        nMsg    272                     unsigned int
        wParam  2425038                 unsigned int

Does anyone know what happens and what to do?

Thanks, Reinardus


Why can't you make it this simple:

lblPresent->Create(L"Welcome", WS_CHILD | WS_VISIBLE,CRect(20, 90, 448, 130), this);

Is this pointer valid and actually pointing to some valid CWnd ?

0

精彩评论

暂无评论...
验证码 换一张
取 消