0xC0000005:执行 CStatic.Create 时访问冲突读取位置 0x4fa2b3f1
我在使用 CStatic 时遇到问题。所以我有这个:
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);
当它到达最后一行时,它说:
Unhandled exception at 0x6e54ba20 in CPTest.exe: 0xC0000005: Access violation reading location 0x4fa2b3f1.
使用调试器跳过时,它让我看到这个:
AfxWndProcDllStatic(HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam)
{
AFX_MANAGE_STATE(&afxModuleState);
return AfxWndProc(hWnd, nMsg, wParam, lParam);
}
异常似乎发生在返回的那一行,其值(写在手表中):
hWnd 0x001a01d0 {unused=0 } HWND__ *
lParam 0 long
nMsg 272 unsigned int
wParam 2425038 unsigned int
当我 有人知道会发生什么以及该怎么做吗?
谢谢, 雷纳德斯
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 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为什么不能让它变得这么简单:
this
指针是否有效并且实际上指向某个有效的 CWnd ?Why can't you make it this simple:
Is
this
pointer valid and actually pointing to some valid CWnd ?