CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Sep 2007
    Location
    Bangalore,India
    Posts
    164

    Unhappy loading dll second time giving error "A required resource was unavailable"

    I am loading an extension dll from my mfc client application, when click on the menu first time the dll dialog is being loade and after i exit or close the dialog, and again clicking on the menu to load again it's giving error that "A required resource was unavailable". what could be the problem please help me to resolve this

    Code:
    void CTestRevApp ::On3DView()
    {
        typedef VOID (*MYPROC)(CString);
        
    	MYPROC ProcAdd;
        BOOL fRunTimeLinkSuccess = FALSE;
    
        
    	hinstLib = LoadLibrary(L"C:\\Documents and Settings\\sdh\\My Documents\\REVOLUTIONPROJ_DB\\DllDialog\\package\\DllTest\\Release\\dlltest.dll");
    	
    	if( hinstLib == NULL)
    	   FreeLibrary(hinstLib);
     
    
    	ProcAdd = (MYPROC)GetProcAddress(hinstLib, "runAppli");
    	ProcAdd(NULL);
    	if(ProcAdd == NULL)
    	{
    		AfxMessageBox(L"Unable to get pointer to function runAppi()");
    	    FreeLibrary(hinstLib);
    	    hinstLib = NULL;
    		return;
        }
        
    	return;
    }

  2. #2
    Join Date
    Sep 2007
    Location
    Bangalore,India
    Posts
    164

    Re: loading dll second time giving error "A required resource was unavailable"

    can anyone give your mail id so that I can send you the project ?? can u help me ?

  3. #3
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: loading dll second time giving error "A required resource was unavailable"

    Quote Originally Posted by sujan.dasmahapatra View Post
    I am loading an extension dll from my mfc client application, when click on the menu first time the dll dialog is being loade and after i exit or close the dialog, and again clicking on the menu to load again it's giving error that "A required resource was unavailable". what could be the problem please help me to resolve this
    Did you debug your code?
    What line (exactly!) in this code snippet causes this error?

    PS: You can attach your project (in zip archive excluding Debug and Release folders as well as .ncb, .aps, .clv files) to your post
    Victor Nijegorodov

  4. #4
    Join Date
    Sep 2007
    Location
    Bangalore,India
    Posts
    164

    Re: loading dll second time giving error "A required resource was unavailable"

    I have got the problem I have implemented the PrecreateWindow for my view class.
    just check this code.

    Code:
    BOOL CMyView::PreCreateWindow(CREATESTRUCT& cs)
    {
    	cs.lpszClass = ::AfxRegisterWndClass(CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS | CS_OWNDC,::LoadCursor(NULL, IDC_ARROW), NULL, NULL);
    
        cs.style |= WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
    
        cs.dwExStyle = WS_EX_CLIENTEDGE; 
    
    	return CView::PreCreateWindow(cs);
    }
    If I remove the first line, i.e
    cs.lpszClass = ::AfxRegisterWndClass(CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS | CS_OWNDC,::LoadCursor(NULL, IDC_ARROW), NULL, NULL);
    then my dll window is coming all the times from the client call. But it's flickering .
    So now please help me what can I do to resolve this. I think some of you must have understood the problem, please help me. Thanks a lot.

  5. #5
    Join Date
    Jan 2009
    Posts
    596

    Re: loading dll second time giving error "A required resource was unavailable"

    There are a few problems with your code - I have highlighted these with comments in red:
    Code:
    void CTestRevApp ::On3DView()
    {
        typedef VOID (*MYPROC)(CString);
        
    	MYPROC ProcAdd;
        BOOL fRunTimeLinkSuccess = FALSE;
    
        
    	hinstLib = LoadLibrary(L"C:\\Documents and Settings\\sdh\\My Documents\\REVOLUTIONPROJ_DB\\DllDialog\\package\\DllTest\\Release\\dlltest.dll");
    	
    	if( hinstLib == NULL)
    	   FreeLibrary(hinstLib); // No need to call FreeLibrary on a NULL value - you should just give an error message and return
     
    
    	ProcAdd = (MYPROC)GetProcAddress(hinstLib, "runAppli");
    	ProcAdd(NULL); // What is this line meant to do? You declared MYPROC to be a function which takes a CString, not a pointer. Also, you should not call it before checking for NULL
    	if(ProcAdd == NULL)
    	{
    		AfxMessageBox(L"Unable to get pointer to function runAppi()");
    	    FreeLibrary(hinstLib); // Shouldn't you Free the DLL always, whether or not you find the "runAppli" function?
    	    hinstLib = NULL;
    		return; // No need to return here, as execution would just fall through to the end of function anyway
        }
        
    	return;
    }

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured