Just about had enough, stupid debug error
-
Hello! I am working on a custom control derived from CWnd, which I was hoping to put on CodeProject until I tried the control with the Create function (two step creation) in debug mode and it errored out. I then tried the control in Release mode and everything worked fine. Here is what my create function looks like: //Function: Create //Job: creates the NavBarCtrl BOOL CNavBarCtrl::Create(const RECT& rect, CWnd* parent, UINT nID, DWORD dwStyle /* = WS_CHILD | WS_BORDER | WS_TABSTOP | WS_VISIBLE*/) { //Make sure variables are valid: ASSERT(parent && IsWindow(parent->GetSafeHwnd())); //parent must be a valid window ASSERT(parent->GetDlgItem(nID) == NULL); //must be a unique dialog item //Create the window: if(!CWnd::Create(NAVBARCTRL_CLASSNAME, NULL, dwStyle, rect, parent, nID)) return false; //Done: return true; } The program crashes in debug mode sometime within the call to CWnd::Create. I have properly initialized the class name contained in NAVBARCTRL_CLASSNAME, since I used the same code Chris Maunder does in his grid control. Just a side note, I tried this code in debug mode first on a Windows XP machine, and was unable to get into the heart of the CWnd call to see what was wrong. Then I tried the code on a Windows 2000 machine and was able to debug enough to see that apparently the code was ASSERTing in the call to CWnd::Attach, on this line: ASSERT(m_hWnd == NULL) I examined the values for m_hWnd and found that, while it did not point to any place in memory (pointer had not been initialized), the value was not NULL. So I tried setting m_hWnd to NULL right before the call to CWnd::Create, but that didn't help. I am hoping someone can shed some light on this situation because it is really annoying to have to run all the programs that use this control in Release mode, and frankly, I hate miscellaneous errors. I would rather not send the code, but if it will help to solve this problem then I will do whatever. Thanks in advance! :eek: Sincerely, Alexander Wiseman Est melior esse quam videri It is better to be than to seem
-
Hello! I am working on a custom control derived from CWnd, which I was hoping to put on CodeProject until I tried the control with the Create function (two step creation) in debug mode and it errored out. I then tried the control in Release mode and everything worked fine. Here is what my create function looks like: //Function: Create //Job: creates the NavBarCtrl BOOL CNavBarCtrl::Create(const RECT& rect, CWnd* parent, UINT nID, DWORD dwStyle /* = WS_CHILD | WS_BORDER | WS_TABSTOP | WS_VISIBLE*/) { //Make sure variables are valid: ASSERT(parent && IsWindow(parent->GetSafeHwnd())); //parent must be a valid window ASSERT(parent->GetDlgItem(nID) == NULL); //must be a unique dialog item //Create the window: if(!CWnd::Create(NAVBARCTRL_CLASSNAME, NULL, dwStyle, rect, parent, nID)) return false; //Done: return true; } The program crashes in debug mode sometime within the call to CWnd::Create. I have properly initialized the class name contained in NAVBARCTRL_CLASSNAME, since I used the same code Chris Maunder does in his grid control. Just a side note, I tried this code in debug mode first on a Windows XP machine, and was unable to get into the heart of the CWnd call to see what was wrong. Then I tried the code on a Windows 2000 machine and was able to debug enough to see that apparently the code was ASSERTing in the call to CWnd::Attach, on this line: ASSERT(m_hWnd == NULL) I examined the values for m_hWnd and found that, while it did not point to any place in memory (pointer had not been initialized), the value was not NULL. So I tried setting m_hWnd to NULL right before the call to CWnd::Create, but that didn't help. I am hoping someone can shed some light on this situation because it is really annoying to have to run all the programs that use this control in Release mode, and frankly, I hate miscellaneous errors. I would rather not send the code, but if it will help to solve this problem then I will do whatever. Thanks in advance! :eek: Sincerely, Alexander Wiseman Est melior esse quam videri It is better to be than to seem
Alexander, how are you instantiating CNavBarCtrl? If m_hWnd is erroneous then it sounds like the instance of CNavBarCtrl might not be valid. I don't understand why you couldn't step into the code CWnd::Create on XP. Neville Franks, Author of ED for Windows. www.getsoft.com
-
Alexander, how are you instantiating CNavBarCtrl? If m_hWnd is erroneous then it sounds like the instance of CNavBarCtrl might not be valid. I don't understand why you couldn't step into the code CWnd::Create on XP. Neville Franks, Author of ED for Windows. www.getsoft.com
Hi Neville, Thanks for your response. I am creating a pointer to a CNavBarCtrl and then using the 'new' operator to create a new object of the class. Then in the create call, the program crashes in debug mode (it runs fine in release mode). Here is the code I use to create it: //somewhere in .h file of a view class: CNavBarCtrl *m_nav; //in .cpp file: m_nav = new CNavBarCtrl(); if(!m_nav->Create( /* variables */ )) //crashes in debug mode I couldn't step into the code of CWnd::Create on XP because every time I was in debug mode and reached that line and then pressed the button to step into the next function, the program crashes as soon as I did (in other words, it threw an exception as soon as I tried to step into the function). If you could shed some light on this I would be very appreciative! Thanks in advance! Sincerely, Alexander Wiseman Est melior esse quam videri It is better to be than to seem
-
Alexander, how are you instantiating CNavBarCtrl? If m_hWnd is erroneous then it sounds like the instance of CNavBarCtrl might not be valid. I don't understand why you couldn't step into the code CWnd::Create on XP. Neville Franks, Author of ED for Windows. www.getsoft.com
Hello! Just in case anyone was wondering, I found the solution to the problem. Stepping through the code didn't work on my machine for some reason, but the actual problem was a line fo code in PreSubclassWindow. Just goes to show how you should really know your window creation process; I din't remember when it was called and so when I manually stepped through the code I found the error in that function. Thanks for your time! Sincerely, Alexander Wiseman Est melior esse quam videri It is better to be than to seem