AfxRegisterWndClass crashes when called again
-
Hi, In my MFC project, I get crash as follows: 1. i call MyCreate() then MyUnCreate() 2. calling MyCreate() the second time, causes crash at AfxRegisterWndClass below. sudo code provided: CMyCwndSub is derived from CWnd. in another file: CMyCwndSub *p;
void MyCreate()
{
//in here code looks for Window with title "MyWndWin".p->new CMyCwndSub; CString m = **AfxRegisterWndClass**(0); //crashes in this line the 2nd time called. p->CreateEx(0, m, -T"MyWndWin",0,0,0,0,0,NULL,0); . . .
}
void MyUnCreate()
{
delete p;
p = NULL;
} -
Hi, In my MFC project, I get crash as follows: 1. i call MyCreate() then MyUnCreate() 2. calling MyCreate() the second time, causes crash at AfxRegisterWndClass below. sudo code provided: CMyCwndSub is derived from CWnd. in another file: CMyCwndSub *p;
void MyCreate()
{
//in here code looks for Window with title "MyWndWin".p->new CMyCwndSub; CString m = **AfxRegisterWndClass**(0); //crashes in this line the 2nd time called. p->CreateEx(0, m, -T"MyWndWin",0,0,0,0,0,NULL,0); . . .
}
void MyUnCreate()
{
delete p;
p = NULL;
}Try to [UnregisterClassA function (winuser.h) - Win32 apps | Microsoft Learn](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-unregisterclassa) in the MyUnCreate()
-
Try to [UnregisterClassA function (winuser.h) - Win32 apps | Microsoft Learn](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-unregisterclassa) in the MyUnCreate()
-
would this work?.
//inside mfc library
void MyUnCreate()
{
::UnregisterClass(_T("MyWndWin"), AfxGetInstanceHndle());
delete p;
p = NULL;
}Didn't you test it? :confused: Also you must pass to UnregisterClass the className returned by AfxRegisterWndClass(...), not the caption of your window!
-
Didn't you test it? :confused: Also you must pass to UnregisterClass the className returned by AfxRegisterWndClass(...), not the caption of your window!
I did the following and still crashed. Maybe the AfxRegisterWndClass is set to release class automatically at the end when library exits. ?
//inside mfc library
void MyUnCreate()
{
::UnregisterClass(ClassName, AfxGetInstanceHandle());
delete p;
p = NULL;
} -
I did the following and still crashed. Maybe the AfxRegisterWndClass is set to release class automatically at the end when library exits. ?
//inside mfc library
void MyUnCreate()
{
::UnregisterClass(ClassName, AfxGetInstanceHandle());
delete p;
p = NULL;
}etechX2 wrote:
Maybe the AfxRegisterWndClass is set to release class automatically at the end when library exits. ?
1. Please read the Microsoft documentation about AfxRegisterWndClass; 2. Why are you trying to unregister and then reregister already registered Class? just save its name and then use it again!