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. Ask for help ___the errors in my projects to show modless dialog in dll [modified]

Ask for help ___the errors in my projects to show modless dialog in dll [modified]

Scheduled Pinned Locked Moved C / C++ / MFC
help
5 Posts 2 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.
  • H Offline
    H Offline
    hailuolan
    wrote on last edited by
    #1

    my function in dll: extern "C" _declspec(dllexport) CDialog * ShowDllDlg(HWND hWnd) { AFX_MANAGE_STATE(AfxGetStaticModuleState()); CDllDlg * m_pDlg =new CDllDlg(); m_pDlg->Create(IDD_DLG_DllDLG, CWnd::FromHandle(hWnd)); m_pDlg->ShowWindow(SW_SHOW); return m_pDlg; } Another function to call dll function in my test project: void CTestDlg::OnBnClickedButtonDlltest() { HWND myhWnd = this->m_hWnd; typedef CDialog * (_stdcall *Connect)(HWND hWnd); HINSTANCE hinstDLL=NULL; hinstDLL = ::LoadLibrary("AntiSubmarine.dll"); if (hinstDLL) { Connect Proc; Proc = (Connect)GetProcAddress(hinstDLL,"ShowDllDlg"); if (Proc!=(Connect)NULL) { m_pdlg = (CDialog *)Proc(myhWnd);//in *.h file defines CDialog * m_pdlg; //if only "Proc(myhWnd)", also the same error; } FreeLibrary(hinstDLL); } else { AfxMessageBox("Not found dll !"); } return; } when run the dll, error comes out.

    modified on Wednesday, August 19, 2009 8:47 AM

    Z 2 Replies Last reply
    0
    • H hailuolan

      my function in dll: extern "C" _declspec(dllexport) CDialog * ShowDllDlg(HWND hWnd) { AFX_MANAGE_STATE(AfxGetStaticModuleState()); CDllDlg * m_pDlg =new CDllDlg(); m_pDlg->Create(IDD_DLG_DllDLG, CWnd::FromHandle(hWnd)); m_pDlg->ShowWindow(SW_SHOW); return m_pDlg; } Another function to call dll function in my test project: void CTestDlg::OnBnClickedButtonDlltest() { HWND myhWnd = this->m_hWnd; typedef CDialog * (_stdcall *Connect)(HWND hWnd); HINSTANCE hinstDLL=NULL; hinstDLL = ::LoadLibrary("AntiSubmarine.dll"); if (hinstDLL) { Connect Proc; Proc = (Connect)GetProcAddress(hinstDLL,"ShowDllDlg"); if (Proc!=(Connect)NULL) { m_pdlg = (CDialog *)Proc(myhWnd);//in *.h file defines CDialog * m_pdlg; //if only "Proc(myhWnd)", also the same error; } FreeLibrary(hinstDLL); } else { AfxMessageBox("Not found dll !"); } return; } when run the dll, error comes out.

      modified on Wednesday, August 19, 2009 8:47 AM

      Z Offline
      Z Offline
      zhu_lin
      wrote on last edited by
      #2

      because you free the library after creating a modless dialog, so the error happened.

      it's my pleasure to make friend with you.

      H 1 Reply Last reply
      0
      • Z zhu_lin

        because you free the library after creating a modless dialog, so the error happened.

        it's my pleasure to make friend with you.

        H Offline
        H Offline
        hailuolan
        wrote on last edited by
        #3

        First, thank you very much for your help. You said "free the library after creating a modless dialog". Beacuse I do not understand the dll, and for some resons, i have to use it with modless dialog. So, could you help me to edit the codes, and make the program run freely. Finally, thanks. it's my pleasure to make friend with you.

        1 Reply Last reply
        0
        • H hailuolan

          my function in dll: extern "C" _declspec(dllexport) CDialog * ShowDllDlg(HWND hWnd) { AFX_MANAGE_STATE(AfxGetStaticModuleState()); CDllDlg * m_pDlg =new CDllDlg(); m_pDlg->Create(IDD_DLG_DllDLG, CWnd::FromHandle(hWnd)); m_pDlg->ShowWindow(SW_SHOW); return m_pDlg; } Another function to call dll function in my test project: void CTestDlg::OnBnClickedButtonDlltest() { HWND myhWnd = this->m_hWnd; typedef CDialog * (_stdcall *Connect)(HWND hWnd); HINSTANCE hinstDLL=NULL; hinstDLL = ::LoadLibrary("AntiSubmarine.dll"); if (hinstDLL) { Connect Proc; Proc = (Connect)GetProcAddress(hinstDLL,"ShowDllDlg"); if (Proc!=(Connect)NULL) { m_pdlg = (CDialog *)Proc(myhWnd);//in *.h file defines CDialog * m_pdlg; //if only "Proc(myhWnd)", also the same error; } FreeLibrary(hinstDLL); } else { AfxMessageBox("Not found dll !"); } return; } when run the dll, error comes out.

          modified on Wednesday, August 19, 2009 8:47 AM

          Z Offline
          Z Offline
          zhu_lin
          wrote on last edited by
          #4

          void CTestDlg::OnBnClickedButtonDlltest()
          {
          HWND myhWnd = this->m_hWnd;

          typedef CDialog * (_stdcall *Connect)(HWND hWnd);
          HINSTANCE hinstDLL=NULL;
          hinstDLL = ::LoadLibrary("AntiSubmarine.dll");
          if (hinstDLL) {
          Connect Proc;
          Proc = (Connect)GetProcAddress(hinstDLL,"ShowDllDlg");
          if (Proc!=(Connect)NULL) {
          m_pdlg = (CDialog *)Proc(myhWnd);//in *.h file defines CDialog * m_pdlg;
          //if only "Proc(myhWnd)", also the same error;
          }
          //FreeLibrary(hinstDLL);
          }
          else {
          AfxMessageBox("Not found dll !");
          }
          return;
          }

          if you create a modless dialog, don't free the library which include the dialog resource until you destroy the dialog, because that modless dialog is not block like mod dialog. :)

          it's my pleasure to make friend with you.

          H 1 Reply Last reply
          0
          • Z zhu_lin

            void CTestDlg::OnBnClickedButtonDlltest()
            {
            HWND myhWnd = this->m_hWnd;

            typedef CDialog * (_stdcall *Connect)(HWND hWnd);
            HINSTANCE hinstDLL=NULL;
            hinstDLL = ::LoadLibrary("AntiSubmarine.dll");
            if (hinstDLL) {
            Connect Proc;
            Proc = (Connect)GetProcAddress(hinstDLL,"ShowDllDlg");
            if (Proc!=(Connect)NULL) {
            m_pdlg = (CDialog *)Proc(myhWnd);//in *.h file defines CDialog * m_pdlg;
            //if only "Proc(myhWnd)", also the same error;
            }
            //FreeLibrary(hinstDLL);
            }
            else {
            AfxMessageBox("Not found dll !");
            }
            return;
            }

            if you create a modless dialog, don't free the library which include the dialog resource until you destroy the dialog, because that modless dialog is not block like mod dialog. :)

            it's my pleasure to make friend with you.

            H Offline
            H Offline
            hailuolan
            wrote on last edited by
            #5

            Thank you very much for your answers. I'll try it again. if there is any error, could you help me again? May I have your Emaill for contact in the future? my Emaill: hailuolan@yahoo.com.cn :) it's my pleasure to make friend with you.

            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