Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. loading dll second time giving error "A required resource was unavailable"

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

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++announcementlearning
27 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    appollosputnik
    wrote on last edited by
    #1

    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; } [/code]

    J 1 Reply Last reply
    0
    • A appollosputnik

      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; } [/code]

      J Offline
      J Offline
      Jochen Arndt
      wrote on last edited by
      #2

      Your code looks a little bit mixed up. Try it this way. It should solve your problem:

      CTestRevApp::CTestRevApp()
      {
      hinstLib = NULL;
      }

      CTestRevApp::~CTestRevApp()
      {
      if (hinstLib != NULL)
      FreeLibrary(hinstLib);
      }

      void CTestRevApp::On3DView()
      {
      typedef VOID (*MYPROC)(CString);

      MYPROC ProcAdd;
      if (hinstLib == NULL)
      {
          hinstLib = LoadLibrary(L"C:\\\\Documents and Settings\\\\sdh\\\\My Documents\\\\REVOLUTIONPROJ\_DB\\\\DllDialog\\\\package\\\\DllTest\\\\Release\\\\dlltest.dll");
      
          if (hinstLib == NULL)
              AfxMessageBox(L"Unable to load library");
      }
      if (hinstLib != NULL)
      {
          ProcAdd = (MYPROC)GetProcAddress(hinstLib, "runAppli");
          if (ProcAdd == NULL)
              AfxMessageBox(L"Unable to get pointer to function runAppi()");
          else
              ProcAdd(NULL);
      }
      

      }

      A 1 Reply Last reply
      0
      • J Jochen Arndt

        Your code looks a little bit mixed up. Try it this way. It should solve your problem:

        CTestRevApp::CTestRevApp()
        {
        hinstLib = NULL;
        }

        CTestRevApp::~CTestRevApp()
        {
        if (hinstLib != NULL)
        FreeLibrary(hinstLib);
        }

        void CTestRevApp::On3DView()
        {
        typedef VOID (*MYPROC)(CString);

        MYPROC ProcAdd;
        if (hinstLib == NULL)
        {
            hinstLib = LoadLibrary(L"C:\\\\Documents and Settings\\\\sdh\\\\My Documents\\\\REVOLUTIONPROJ\_DB\\\\DllDialog\\\\package\\\\DllTest\\\\Release\\\\dlltest.dll");
        
            if (hinstLib == NULL)
                AfxMessageBox(L"Unable to load library");
        }
        if (hinstLib != NULL)
        {
            ProcAdd = (MYPROC)GetProcAddress(hinstLib, "runAppli");
            if (ProcAdd == NULL)
                AfxMessageBox(L"Unable to get pointer to function runAppi()");
            else
                ProcAdd(NULL);
        }
        

        }

        A Offline
        A Offline
        appollosputnik
        wrote on last edited by
        #3

        It's not solving the problem. My Client application is still active when i am calling On3DView 2nd time, it's giving still error "A required resource was unavailable" and not laoding the dlg of the dll. I have exactly copied your code it's still giving error.

        J 1 Reply Last reply
        0
        • A appollosputnik

          It's not solving the problem. My Client application is still active when i am calling On3DView 2nd time, it's giving still error "A required resource was unavailable" and not laoding the dlg of the dll. I have exactly copied your code it's still giving error.

          J Offline
          J Offline
          Jochen Arndt
          wrote on last edited by
          #4

          The error is very probably in your DLL showing a dialog. Common sources are forgetting to release DCs and GDI objects.

          A 3 Replies Last reply
          0
          • J Jochen Arndt

            The error is very probably in your DLL showing a dialog. Common sources are forgetting to release DCs and GDI objects.

            A Offline
            A Offline
            appollosputnik
            wrote on last edited by
            #5

            how can i release them manually. Please help me

            J 1 Reply Last reply
            0
            • A appollosputnik

              how can i release them manually. Please help me

              J Offline
              J Offline
              Jochen Arndt
              wrote on last edited by
              #6

              Do you have the source code? If not, you must contact the supplier of the DLL. If yes, you must check the code. If the code uses GetDC() somewhere, ensure that ReleaseDC() is called when the CDC is no longer used.

              A 1 Reply Last reply
              0
              • J Jochen Arndt

                Do you have the source code? If not, you must contact the supplier of the DLL. If yes, you must check the code. If the code uses GetDC() somewhere, ensure that ReleaseDC() is called when the CDC is no longer used.

                A Offline
                A Offline
                appollosputnik
                wrote on last edited by
                #7

                I am releasing it in the ::OnDestroy() fucntion of the view

                J 1 Reply Last reply
                0
                • A appollosputnik

                  I am releasing it in the ::OnDestroy() fucntion of the view

                  J Offline
                  J Offline
                  Jochen Arndt
                  wrote on last edited by
                  #8

                  That's one place where you release a DC (in your app or the DLL?). If not in the DLL, you should concentrate on the DLL code. There may be multiple places in your code using DCs and GDI objects. If you miss any release call or forget to de-select GDI objcets out of context, the error may occcur. I can't really help you without seeing the code. I can only guess. Check this example code:

                  CDC *pDC = GetDC();
                  CPen NewPen(PS_SOLID, 0, m_Color);
                  CPen *pOldPen = pDC->SelectObject(&NewPen);
                  CFont *pOldFont = pDC->SelectObject(m_pMyFont);
                  // do something with the DC
                  ...
                  // Don't forget to select the old objects
                  pDC->SelectObject(pOldFont);
                  pDC->SelectObject(pOldPen);
                  // Don't forget to release the DC
                  ReleaseDC(pDC);

                  A 1 Reply Last reply
                  0
                  • J Jochen Arndt

                    That's one place where you release a DC (in your app or the DLL?). If not in the DLL, you should concentrate on the DLL code. There may be multiple places in your code using DCs and GDI objects. If you miss any release call or forget to de-select GDI objcets out of context, the error may occcur. I can't really help you without seeing the code. I can only guess. Check this example code:

                    CDC *pDC = GetDC();
                    CPen NewPen(PS_SOLID, 0, m_Color);
                    CPen *pOldPen = pDC->SelectObject(&NewPen);
                    CFont *pOldFont = pDC->SelectObject(m_pMyFont);
                    // do something with the DC
                    ...
                    // Don't forget to select the old objects
                    pDC->SelectObject(pOldFont);
                    pDC->SelectObject(pOldPen);
                    // Don't forget to release the DC
                    ReleaseDC(pDC);

                    A Offline
                    A Offline
                    appollosputnik
                    wrote on last edited by
                    #9

                    I am not able to delete the view it's crashing delete m_pNewView; It's crashing. how can I delete the view.????

                    J 2 Replies Last reply
                    0
                    • A appollosputnik

                      I am not able to delete the view it's crashing delete m_pNewView; It's crashing. how can I delete the view.????

                      J Offline
                      J Offline
                      Jochen Arndt
                      wrote on last edited by
                      #10

                      I'm sorry, but without knowing your code, I can't really help. Also, is there a relation to the original question, or is it a new one? If it is a new one, you should open a new question. Views are usually handled by the document class and the frame work. To close a view manually, the parent frame of the view must be closed.

                      A 2 Replies Last reply
                      0
                      • J Jochen Arndt

                        I'm sorry, but without knowing your code, I can't really help. Also, is there a relation to the original question, or is it a new one? If it is a new one, you should open a new question. Views are usually handled by the document class and the frame work. To close a view manually, the parent frame of the view must be closed.

                        A Offline
                        A Offline
                        appollosputnik
                        wrote on last edited by
                        #11

                        this is my view class of the dll [code] // MyView.cpp : implementation file // #include "stdafx.h" #include "DlgsViewDlg.h" #include "MyView.h" ////////////////////////////////////////////////////////////////////////// #include // Header File For Windows #include // Header File For Windows Math Library #include // Header File For Standard Input/Output #include // Header File For Variable Argument Routines #include // Header File For The OpenGL32 Library #include // Header File For The GLu32 Library #include // Header File For The Glaux Library //#include ///////////////////////////////////////////////////////////////////////// #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif #pragma comment (lib, "OpenGL32.lib") #pragma comment (lib, "glu32.lib") #define NOFPOINTSINARC 5 #define NSWEEP 60 #define DIB_HEADER_MARKER ((WORD) ('M' << 8) | 'B') #define WIDTHBYTES(bits) (((bits) + 31) / 32 * 4) ///////////////////////////////////////////////////////////////////////////// // CMyView typedef enum state { NOMOVE = 0, PAN , ZOOM, ROTATE } statemovement; struct vec3{ float x, y, z; }; GLfloat trans[3]; /* current translation */ GLfloat trans_axes[3]; GLfloat rot[3]; statemovement STATE; GLfloat PI = 4 * atan(1.0); //////////////////////// GLuint base; // Base Display List For The Font Set GLfloat cnt1; // 1st Counter Used To Move Text & For Coloring GLfloat cnt2; // 2nd Counter Used To Move Text & For Coloring bool keys[256]; // Array Used For The Keyboard Routine bool active=TRUE; // Window Active Flag Set To TRUE By Default bool fullscreen=TRUE; // Fullscreen Flag Set To Fullscreen Mode By Default //////////////////////// double CMyView::left = -10.0f; double CMyView::right = 10.0f; double CMyView::top = -10.0f; double CMyView::bottom = 10.0f; double CMyView::znear = -100.0f; double CMyView::zfar = 100.0f; static float zoomFactor = 1.0f; static bool colorChange=false; static double iRed=1.0f; static double iGreen=0.0f; static double iBlue=0.0f; IMPLEMENT_DYNCREATE(CMyView, CView) CMyView::CMyView() :object(0) ,startPoints(NULL) ,endPoints(NULL) ,arcs(NULL) ,pan(false) ,zoom(false) ,rotate(false) ,x(NULL) ,y(NULL) ,allX(NULL) ,allY(NULL) ,allZ(NULL) ,cx(0.0) ,cy(0.0) ,cz(0.0) ,isModel(false) { trans[0] = 0.0f; trans[1] =

                        1 Reply Last reply
                        0
                        • J Jochen Arndt

                          I'm sorry, but without knowing your code, I can't really help. Also, is there a relation to the original question, or is it a new one? If it is a new one, you should open a new question. Views are usually handled by the document class and the frame work. To close a view manually, the parent frame of the view must be closed.

                          A Offline
                          A Offline
                          appollosputnik
                          wrote on last edited by
                          #12

                          this is my dialog class of the dll.......In the view class you can see I have done ReleaseDC everywhere. Check if could help resolve this error. Thanks a lot for your help. [code] // DlgsViewDlg.cpp : implementation file // #include "stdafx.h" #include "DlgsView.h" #include "DlgsViewDlg.h" #include "MyView.h" #ifdef _DEBUG #define new DEBUG_NEW #endif static UINT BASED_CODE indicators[] = { ID_INDICATOR_NISH, ID_INDICATOR_TIME }; // CAboutDlg dialog used for App About class CAboutDlg : public CDialog { public: CAboutDlg(); // Dialog Data enum { IDD = IDD_ABOUTBOX }; protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support // Implementation protected: DECLARE_MESSAGE_MAP() }; CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD) { } void CAboutDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); } BEGIN_MESSAGE_MAP(CAboutDlg, CDialog) END_MESSAGE_MAP() // CDlgsViewDlg dialog CString CDlgsViewDlg::fileName = L""; CDlgsViewDlg::CDlgsViewDlg(CString filename, CWnd* pParent /*=NULL*/) : CDialog(CDlgsViewDlg::IDD, pParent) { m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); fileName = filename; } CDlgsViewDlg::~CDlgsViewDlg() { delete m_pNewView; } void CDlgsViewDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); } BEGIN_MESSAGE_MAP(CDlgsViewDlg, CDialog) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_COMMAND(ID_FILE_NEW,OnFileNew) //}}AFX_MSG_MAP ON_COMMAND(ID_UTILITY_EXIT, &CDlgsViewDlg::OnUtilityExit) ON_COMMAND(ID_EXIT, &CDlgsViewDlg::OnExit) ON_COMMAND(ID_UTILITY_LOADPROFILE, &CDlgsViewDlg::OnUtilityLoadprofile) ON_COMMAND(ID_UTILITY_GENERATESURFACE, &CDlgsViewDlg::OnUtilityGeneratesurface) ON_COMMAND(ID_UTILITY_DRAW1, &CDlgsViewDlg::OnUtilityDraw1) ON_COMMAND(ID_UTILITY_DRAW3, &CDlgsViewDlg::OnUtilityDraw3) ON_COMMAND(ID_UTILITY_SAVEASIMAGE, &CDlgsViewDlg::OnUtilitySaveasimage) ON_COMMAND(ID_VIEW_WIREFRAME, &CDlgsViewDlg::OnViewWireframe) ON_COMMAND(ID_VIEW_SHADE, &CDlgsViewDlg::OnViewShade) ON_COMMAND(ID_VIEW_NORMAL, &CDlgsViewDlg::OnViewNormal) ON_COMMAND(ID_VIEW_PAN, &CDlgsViewDlg::OnViewPan) ON_COMMAND(ID_VIEW_ZOOM, &CDlgsViewDlg::OnViewZoom) ON_COMMAND(ID_VIEW_ROTATE, &CDlgsViewDlg::OnViewRotate) ON_COMMAND(ID_VIEW_TOPVIEW, &CDlgsViewDlg::OnViewTopview) ON_COMMAND(ID_VIEW_FRONTVIEW, &CDlgsViewDlg::OnViewFrontview) ON_COMMAND(ID_VIEW_SIDEVIEW, &CDlgsViewDlg::OnViewSideview) ON_COMMAND(ID

                          1 Reply Last reply
                          0
                          • A appollosputnik

                            I am not able to delete the view it's crashing delete m_pNewView; It's crashing. how can I delete the view.????

                            J Offline
                            J Offline
                            Jochen Arndt
                            wrote on last edited by
                            #13

                            I'll reply again to this message. You have added too much unformatted code to your other posts (therefore somebody has donevoted them).

                            1. You should use the 'code' button on top of the CP message input window to format the selection as C++ code.
                            2. You should limit the amount of code. Nobody here will step through too many lines.

                            Regarding the CView deletion: Why do you use a CView derived class within a CDialog? Using a CWnd derived class as user control should solve your problem. CView classes are used with the document view model and expect to have a frame window as parent.

                            A 1 Reply Last reply
                            0
                            • J Jochen Arndt

                              I'll reply again to this message. You have added too much unformatted code to your other posts (therefore somebody has donevoted them).

                              1. You should use the 'code' button on top of the CP message input window to format the selection as C++ code.
                              2. You should limit the amount of code. Nobody here will step through too many lines.

                              Regarding the CView deletion: Why do you use a CView derived class within a CDialog? Using a CWnd derived class as user control should solve your problem. CView classes are used with the document view model and expect to have a frame window as parent.

                              A Offline
                              A Offline
                              appollosputnik
                              wrote on last edited by
                              #14

                              your answer is not a solution. try to solve the problem.

                              L J 2 Replies Last reply
                              0
                              • A appollosputnik

                                your answer is not a solution. try to solve the problem.

                                L Offline
                                L Offline
                                Lost User
                                wrote on last edited by
                                #15

                                sujandasmahapatra wrote:

                                your answer is not a solution

                                Being rude is not a solution either.

                                Why is common sense not common? Never argue with an idiot. They will drag you down to their level where they are an expert. Sometimes it takes a lot of work to be lazy Individuality is fine, as long as we do it together - F. Burns

                                1 Reply Last reply
                                0
                                • A appollosputnik

                                  your answer is not a solution. try to solve the problem.

                                  J Offline
                                  J Offline
                                  Jochen Arndt
                                  wrote on last edited by
                                  #16

                                  sujandasmahapatra wrote:

                                  your answer is not a solution

                                  The solution is to not use a CView derived class as a client window of a dialog.

                                  sujandasmahapatra wrote:

                                  try to solve the problem

                                  No. You must solve the problem. It's not my job. The only thing I can do, is to help you.

                                  L A C 3 Replies Last reply
                                  0
                                  • J Jochen Arndt

                                    sujandasmahapatra wrote:

                                    your answer is not a solution

                                    The solution is to not use a CView derived class as a client window of a dialog.

                                    sujandasmahapatra wrote:

                                    try to solve the problem

                                    No. You must solve the problem. It's not my job. The only thing I can do, is to help you.

                                    L Offline
                                    L Offline
                                    Lost User
                                    wrote on last edited by
                                    #17

                                    5 for your patience.

                                    Why is common sense not common? Never argue with an idiot. They will drag you down to their level where they are an expert. Sometimes it takes a lot of work to be lazy Individuality is fine, as long as we do it together - F. Burns

                                    1 Reply Last reply
                                    0
                                    • J Jochen Arndt

                                      sujandasmahapatra wrote:

                                      your answer is not a solution

                                      The solution is to not use a CView derived class as a client window of a dialog.

                                      sujandasmahapatra wrote:

                                      try to solve the problem

                                      No. You must solve the problem. It's not my job. The only thing I can do, is to help you.

                                      A Offline
                                      A Offline
                                      appollosputnik
                                      wrote on last edited by
                                      #18

                                      i wanted a view on the dialog. so i derived from cview and created the view in the dialog. 1st time everything is coming fine. but without closing the client application if i try to launch again the dialog then it's giving error. Please give me some suggestion how can i get rid of it. Thanks

                                      J 1 Reply Last reply
                                      0
                                      • A appollosputnik

                                        i wanted a view on the dialog. so i derived from cview and created the view in the dialog. 1st time everything is coming fine. but without closing the client application if i try to launch again the dialog then it's giving error. Please give me some suggestion how can i get rid of it. Thanks

                                        J Offline
                                        J Offline
                                        Jochen Arndt
                                        wrote on last edited by
                                        #19

                                        The problem is that the view is not properly closed. But even if you would close it properly, there will be other problems. A CView is not designed to be a child view of a dialog. It must be a child of a CFrameWnd derived class. Change your CView class to be based on a CWnd.

                                        1 Reply Last reply
                                        0
                                        • J Jochen Arndt

                                          sujandasmahapatra wrote:

                                          your answer is not a solution

                                          The solution is to not use a CView derived class as a client window of a dialog.

                                          sujandasmahapatra wrote:

                                          try to solve the problem

                                          No. You must solve the problem. It's not my job. The only thing I can do, is to help you.

                                          C Offline
                                          C Offline
                                          Chris Meech
                                          wrote on last edited by
                                          #20

                                          And demonstrating a great deal of restraint as well. Good for you. :)

                                          Chris Meech I am Canadian. [heard in a local bar] In theory there is no difference between theory and practice. In practice there is. [Yogi Berra] posting about Crystal Reports here is like discussing gay marriage on a catholic church’s website.[Nishant Sivakumar]

                                          A 1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups