使用WndClass访问违规读取位置

时间:2014-04-21 17:26:10

标签: c++ windows winapi

我有一个问题,使用此代码:

BOOL RegisterApp(HINSTANCE hInst)
{
    WNDCLASS wc;

    wc.style         = CS_HREDRAW | CS_VREDRAW;
    wc.lpfnWndProc   = WndProc;
    wc.cbClsExtra    = 0;
    wc.cbWndExtra    = 0;
    wc.hInstance     = hInst;
    wc.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
    wc.hCursor        = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH)GetStockObject(GRAY_BRUSH);
    wc.lpszClassName = szClassName;
    //

    //
    return RegisterClass(&wc);
}

当我尝试使用&wc时,我有这个错误:

Unhandled exception at 0x763adf81 in lab3.exe: 0xC0000005: Access violation reading location 0xcccccccc.

请帮助我,我需要做些什么?

1 个答案:

答案 0 :(得分:4)

您尚未初始化wc的所有数据成员。

参考http://msdn.microsoft.com/en-us/library/windows/desktop/ms633576(v=vs.85).aspx

相关问题