dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 17

Thread: problem in LoadFrame..

  1. #1
    Join Date
    May 2006
    Location
    Mumbai, India
    Posts
    292

    Unhappy problem in LoadFrame..

    Hi!

    While running a code ported from VC6 to VC8, I an getting unhandled exception. When I debugged my code I found that LoadFrame() is causing a probelm saying::
    First-chance exception at 0x104817fd (msvcp80d.dll) in KPVault.exe: 0xC0000005: Access violation writing location 0x0000424b.
    Unhandled exception at 0x104817fd (msvcp80d.dll) in KPVault.exe: 0xC0000005: Access violation writing location 0x0000424b.
    I am calling LoadFrame as
    Code:
    CMainFrame* pFrame = new CMainFrame;
    pFrame->LoadFrame(IDR_MAINFRAME,
    		WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE, NULL,
    		NULL);
    I checked all my resources named as IDR_MAINFRAME. Those are a String, Menu, Acceralator, Icon and a Toolbar.

    VC6 build for the same code runs just fine. Then What is causing this problem??

    Thx

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,543

    Re: problem in LoadFrame..

    Try to debug your application, step in to the LoadFrame(..) method and go step-by-step until the problem...

  3. #3
    Join Date
    May 2006
    Location
    Mumbai, India
    Posts
    292

    Re: problem in LoadFrame..

    Thanks victor!

    I did the same thing!
    But its showing me problem in create() function of windows which is being called implicitly called by LoadFrame.

    Thx

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,543

    Re: problem in LoadFrame..

    What "create() function "?
    Are the parameters passed in this function correct?

  5. #5
    Join Date
    May 2006
    Location
    Mumbai, India
    Posts
    292

    Re: problem in LoadFrame..

    Thx...

    I checked the parameters for the the calling function n I found that LoadFrame internally calls function 'Create' and in my case its calling it with some wrong parameters

    Here is the implementation for LoadFrame from winfrm.cpp::

    Code:
    BOOL CFrameWnd::LoadFrame(UINT nIDResource, DWORD dwDefaultStyle,
    	CWnd* pParentWnd, CCreateContext* pContext)
    {
    	// only do this once
    	ASSERT_VALID_IDR(nIDResource);
    	ASSERT(m_nIDHelp == 0 || m_nIDHelp == nIDResource);
    
    	m_nIDHelp = nIDResource;    // ID for help context (+HID_BASE_RESOURCE)
    
    	CString strFullString;
    	if (strFullString.LoadString(nIDResource))
    		AfxExtractSubString(m_strTitle, strFullString, 0);    // first sub-string
    
    	VERIFY(AfxDeferRegisterClass(AFX_WNDFRAMEORVIEW_REG));
    
    	// attempt to create the window
    	LPCTSTR lpszClass = GetIconWndClass(dwDefaultStyle, nIDResource);
    	CString strTitle = m_strTitle;
    	if (!Create(lpszClass, strTitle, dwDefaultStyle, rectDefault,
    	  pParentWnd, ATL_MAKEINTRESOURCE(nIDResource), 0L, pContext))
    	{
    		return FALSE;   // will self destruct on failure normally
    	}
    
    	// save the default menu handle
    	ASSERT(m_hWnd != NULL);
    	m_hMenuDefault = ::GetMenu(m_hWnd);
    
    	// load accelerator resource
    	LoadAccelTable(ATL_MAKEINTRESOURCE(nIDResource));
    
    	if (pContext == NULL)   // send initial update
    		SendMessageToDescendants(WM_INITIALUPDATE, 0, 0, TRUE, TRUE);
    
    	return TRUE;
    }
    In my case it gets failed at step
    //attempt to create window
    and lpszClass reamains NULL.

    I think thats the cause of the proble,...

    plz help!!

  6. #6
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,543

    Re: problem in LoadFrame..

    Quote Originally Posted by sachin871
    Thx...

    I checked the parameters for the the calling function n I found that LoadFrame internally calls function 'Create' and in my case its calling it with some wrong parameters
    Which parameters seem "wrong"?
    Is the nIDResource value correct (something like 128)?

  7. #7
    Join Date
    May 2006
    Location
    Mumbai, India
    Posts
    292

    Re: problem in LoadFrame..

    Which parameters seem "wrong"?
    Is the nIDResource value correct (something like 128)?
    Today 09:41 AM
    No!
    I am sending IDR_MAINFRAME(128) correctly.
    I checked resources with same ID IDR_MAINFRAME and they do exist!!

    I am saying that in LoadFrame() inplementation by windows, variable 'lpszClass' remains NULL. I am not sure but I think that may be the problem.

  8. #8
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,543

    Re: problem in LoadFrame..

    Quote Originally Posted by sachin871
    I checked resources with same ID IDR_MAINFRAME and they do exist!!
    Well, now it would be usefull to prove your .exe module whether it really contains the frame menu with id=128.
    To do it open your exe in VC as a resource and try to find this menu.
    I am saying that in LoadFrame() inplementation by windows, variable 'lpszClass' remains NULL. I am not sure but I think that may be the problem.
    Sure, it is the problem!

    BTW, have you tried to Rebuild All (if this feature exists in VC8)?

  9. #9
    Join Date
    May 2006
    Location
    Mumbai, India
    Posts
    292

    Re: problem in LoadFrame..

    Thx victor for the quick reply!!

    I had already checkd my resources avlable in .exe. and all of them do exists!! I did rebuild and again checked now and found the same results.

    That means the its the variable 'lpszClass' creating the problem. But I cant modify as that is through the windows function.

    Is ther any other solution. Can I use Create() function replacing LoadFrame()?

    Thx!

  10. #10
    Join Date
    May 1999
    Location
    DELAWARE, USA
    Posts
    9,917

    Re: problem in LoadFrame..

    To intelligently answer your question it is desirable (if not necessary) to see your code.

    Window class string being NULL is something out of ordinary and to find a reason for that we would have to actively debug your project.
    Could you attach it (or sample that reproduce behavior) to your post?
    There are only 10 types of people in the world:
    Those who understand binary and those who do not.

  11. #11
    Join Date
    May 1999
    Location
    DELAWARE, USA
    Posts
    9,917

    Re: problem in LoadFrame..

    I forgot to add:
    Class name is set to NULL if the icon with given resource ID does not exist.
    Even though window creation does not fail since default implementation of the frame window registers own window class in PreCreateWindow.

    Hence, your problem is not a window class.
    There are only 10 types of people in the world:
    Those who understand binary and those who do not.

  12. #12
    Join Date
    May 2006
    Location
    Mumbai, India
    Posts
    292

    Re: problem in LoadFrame..

    Thx for the reply!!

    Unfortunately I cant attach my code here. I am not allowd to do so. I'll try my best to explain whats goin on in the code.

    I am callign LoadFrame as specified in my first post. I debugged my code actively and found that I am getting 'lpszClass' variable as NULL. This is because "GetIconWndClass( )" was getting failed and returning NULL. I checked my .exe for Icon resource and everything is fine. Icon with name IDR_MAINFRAME and value 128 do exist.

    I am attaching code fro GetIconWndClass function to indicate line where Its getting failed and returning NULL.

    Code:
    LPCTSTR CFrameWnd::GetIconWndClass(DWORD dwDefaultStyle, UINT nIDResource)
    {
    	ASSERT_VALID_IDR(nIDResource);
    	HINSTANCE hInst = AfxFindResourceHandle(
    		ATL_MAKEINTRESOURCE(nIDResource), ATL_RT_GROUP_ICON);
    	HICON hIcon = ::LoadIcon(hInst, ATL_MAKEINTRESOURCE(nIDResource));
    	if (hIcon != NULL)
    	{
    		CREATESTRUCT cs;
    		memset(&cs, 0, sizeof(CREATESTRUCT));
    		cs.style = dwDefaultStyle;
    		PreCreateWindow(cs);
    			// will fill lpszClassName with default WNDCLASS name
    			// ignore instance handle from PreCreateWindow.
    
    		WNDCLASS wndcls;
    	------------>if (cs.lpszClass != NULL &&
    			AfxCtxGetClassInfo(AfxGetInstanceHandle(), cs.lpszClass, &wndcls) &&
    			wndcls.hIcon != hIcon)
    		{
    			// register a very similar WNDCLASS
    			return AfxRegisterWndClass(wndcls.style,
    				wndcls.hCursor, wndcls.hbrBackground, hIcon);
    		}
    	}
    	return NULL;        // just use the default
    }

    Thx !!

  13. #13
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,543

    Re: problem in LoadFrame..

    Sounds, you are doing something wrong in your CMainFrame::PreCreateWindow method (either you are corrupting the cs.lpszClass member or you are NOT calling base class PreCreateWindow method).

  14. #14
    Join Date
    May 1999
    Location
    DELAWARE, USA
    Posts
    9,917

    Re: problem in LoadFrame..

    Quote Originally Posted by sachin871
    Unfortunately I cant attach my code here. I am not allowd to do so. I'll try my best to explain whats goin on in the code.
    Quote Originally Posted by me earlier
    Could you attach it (or sample that reproduce behavior) to your post?
    Posting MFC code is not really helping to find your problem.
    Quote Originally Posted by me earlier
    Class name is set to NULL . . . window creation does not fail since default implementation of the frame window registers own window class in PreCreateWindow.
    Therefore, most likely VictorN is right.
    There are only 10 types of people in the world:
    Those who understand binary and those who do not.

  15. #15
    Join Date
    Sep 2019
    Posts
    3

    Re: problem in LoadFrame..

    Hello Sachin, I am facing the same Problem that you have posted. did you find the solution?

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)