开发者

Visual studio i think heap error

开发者 https://www.devze.com 2023-02-08 15:05 出处:网络
I am on a project with C++ and WinApi32 . There Are 3 classes , each of them is about 150 lines code .

I am on a project with C++ and WinApi32 . There Are 3 classes , each of them is about 150 lines code .

In my main window , below code will be ran frequently :

wc.cbClsExtra=0;
wc.cbWndExtra=0;
wc.hbrBackground = CreateSolidBrush(BkColor);
wc.hCursor = LoadCursor(NULL,IDC_HAND);
wc.hIcon = NULL;
wc.hInstance = hInstance;
vertex_hInstance = hInstance;
wc.lpfnWndProc = VertexProc;
wc.lpszClassName = Vertex_Class;
wc.lpszMenuName=NULL;
wc.style = CS_HREDRAW|CS_VREDRAW;
RegisterClass(&wc);
hWnd = CreateWi开发者_如何学编程ndow(Vertex_Class,L"",WS_CHILD|WS_BORDER,getx(),gety(),getw(),geth(),parent_HWND,NULL,hInstance,0);

It's in a function of a class which I have defined early. Running Program : There is no error , everything is good. Closing Program : gives me error :Windows Has Triggered a Breakpoint, to see picture : Visit Error


The code you have shown is not sufficient to say what causes the problem that you describe.

However, you should not register the same window class more than once.

I don't know the effect of "frequently" registering the same window class, because it's just not something that one does (so I have no experience with that), but conceivably it might be gobbling up resources, which in turn might have a very detrimental effect…

The usual solution is register a window class only the first time, or before you create any windows of that class.

E.g. you can use a singleton to achieve this.

Cheers & hth.,

0

精彩评论

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

关注公众号