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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to use MFC CDialog in a DLL ?

How to use MFC CDialog in a DLL ?

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++tutorialquestion
6 Posts 4 Posters 2 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.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    Hello, folks, I got some trouble using MFC CDialog class in my DLL (MFC static linked DLL). Though my DLL is made MFC static linked, when I use MFC classes to create a dialog (pop-up or child), I always got a window creation error. I know I can create dialog using win32 SDK (i.e, using CreateDialog(..) or DialogBoxParam(..), I did them before !), but I still want to use MFC to create my dialog. Because I also have something like CListCtrl or CListView on that dialog. Could anybody help me ? Or I should use win32 SDK instead ? And, are "list control" and "list view" same ? Any response would be appreciated.

    R 1 Reply Last reply
    0
    • L Lost User

      Hello, folks, I got some trouble using MFC CDialog class in my DLL (MFC static linked DLL). Though my DLL is made MFC static linked, when I use MFC classes to create a dialog (pop-up or child), I always got a window creation error. I know I can create dialog using win32 SDK (i.e, using CreateDialog(..) or DialogBoxParam(..), I did them before !), but I still want to use MFC to create my dialog. Because I also have something like CListCtrl or CListView on that dialog. Could anybody help me ? Or I should use win32 SDK instead ? And, are "list control" and "list view" same ? Any response would be appreciated.

      R Offline
      R Offline
      Rage
      wrote on last edited by
      #2

      Yo Yo~~ wrote: Though my DLL is made MFC static linked, when I use MFC classes to create a dialog (pop-up or child), I always got a window creation error. Post your code, pls ... The code is more likely to be wrong than the MFC dll :) ~RaGE();

      L 1 Reply Last reply
      0
      • R Rage

        Yo Yo~~ wrote: Though my DLL is made MFC static linked, when I use MFC classes to create a dialog (pop-up or child), I always got a window creation error. Post your code, pls ... The code is more likely to be wrong than the MFC dll :) ~RaGE();

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

        /// on MyGUIDlg.cpp; a dialog based application void CGUIDlg::OnViewLog() { DWORD r = 0; r = ViewLogFile( this->m_hWnd ); } /// on MyDLL.cpp; a MFC static linked DLL DLLExport DWORD WINAPI ViewLogFile( HWND hParendWnd ) { CWnd* pParentWnd = new CWnd(); pParentWnd->Attach( hParendWnd ); CEventLogDlg* pLogDlg = new CEventLogDlg( pParentWnd ); if ( pLogDlg != NULL ) { pLogDlg->Create( IDD_EVENT_LOG, pParentWnd ); ///IDD_EVENT_LOG is resource ID pLogDlg->ShowWindow( SW_SHOW ); } } /// class CEventLogDlg class CEventLogDlg : public CDialog { ........ }

        K 1 Reply Last reply
        0
        • L Lost User

          /// on MyGUIDlg.cpp; a dialog based application void CGUIDlg::OnViewLog() { DWORD r = 0; r = ViewLogFile( this->m_hWnd ); } /// on MyDLL.cpp; a MFC static linked DLL DLLExport DWORD WINAPI ViewLogFile( HWND hParendWnd ) { CWnd* pParentWnd = new CWnd(); pParentWnd->Attach( hParendWnd ); CEventLogDlg* pLogDlg = new CEventLogDlg( pParentWnd ); if ( pLogDlg != NULL ) { pLogDlg->Create( IDD_EVENT_LOG, pParentWnd ); ///IDD_EVENT_LOG is resource ID pLogDlg->ShowWindow( SW_SHOW ); } } /// class CEventLogDlg class CEventLogDlg : public CDialog { ........ }

          K Offline
          K Offline
          KaRl
          wrote on last edited by
          #4

          There may be a confusion about the resource you try to load. Called from an application, your DLL will try to load application's resource. To be sure what you are loading, try this: In the dialog constructor: CMyDlg::CMyDlg(CWnd* pParent /*=NULL*/) : CDialog(/*CMyDlg::IDD*/) { HINSTANCE hInstance = GetModuleHandle(_T("MyDLL")); VERIFY(hInstance); HRSRC hResource = ::FindResource(hInstance, MAKEINTRESOURCE(IDD_MYRESOURCE), RT_DIALOG); VERIFY(hResource); HGLOBAL hTemplate = LoadResource(hInstance, hResource); VERIFY(hTemplate); InitModalIndirect((HGLOBAL)hTemplate, pParent); FreeResource(hTemplate); } We do not inherit the Earth from our ancestors. We borrow it from our children. Antoine de Saint Exupéry (1900-1944)

          M L 2 Replies Last reply
          0
          • K KaRl

            There may be a confusion about the resource you try to load. Called from an application, your DLL will try to load application's resource. To be sure what you are loading, try this: In the dialog constructor: CMyDlg::CMyDlg(CWnd* pParent /*=NULL*/) : CDialog(/*CMyDlg::IDD*/) { HINSTANCE hInstance = GetModuleHandle(_T("MyDLL")); VERIFY(hInstance); HRSRC hResource = ::FindResource(hInstance, MAKEINTRESOURCE(IDD_MYRESOURCE), RT_DIALOG); VERIFY(hResource); HGLOBAL hTemplate = LoadResource(hInstance, hResource); VERIFY(hTemplate); InitModalIndirect((HGLOBAL)hTemplate, pParent); FreeResource(hTemplate); } We do not inherit the Earth from our ancestors. We borrow it from our children. Antoine de Saint Exupéry (1900-1944)

            M Offline
            M Offline
            Mel Stober
            wrote on last edited by
            #5

            I tried your suggestion, put that code in my dialog's constructor and compiled the dll. Then in my app, I added the dialog's *.h file, but when I tried to compile my app, I got and error about an undefined symbol in the dialog box's header file: #ifdef _USRDLL #define DllExport __declspec( dllexport ) #else #define DllExport __declspec( dllimport ) #endif class DllExport CMyDlg : public CDialog { // Construction public: enum { IDD = IDD_MYDIALOG_DIALOG }; I know that IDD_MYDIALOG_DIALOG is defined in the dll's resource.h file. Do I also have to include it in my app's *.cpp ?

            1 Reply Last reply
            0
            • K KaRl

              There may be a confusion about the resource you try to load. Called from an application, your DLL will try to load application's resource. To be sure what you are loading, try this: In the dialog constructor: CMyDlg::CMyDlg(CWnd* pParent /*=NULL*/) : CDialog(/*CMyDlg::IDD*/) { HINSTANCE hInstance = GetModuleHandle(_T("MyDLL")); VERIFY(hInstance); HRSRC hResource = ::FindResource(hInstance, MAKEINTRESOURCE(IDD_MYRESOURCE), RT_DIALOG); VERIFY(hResource); HGLOBAL hTemplate = LoadResource(hInstance, hResource); VERIFY(hTemplate); InitModalIndirect((HGLOBAL)hTemplate, pParent); FreeResource(hTemplate); } We do not inherit the Earth from our ancestors. We borrow it from our children. Antoine de Saint Exupéry (1900-1944)

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

              Thanks ! It really helps. I tried your codes and added something in my DLL as follows. Then it worked ! /// in MyDLL.cpp CMyDlg* InitMyDialog( HWND hParent ) { CMyDlg* pMyDlg = NULL; AFX_MANAGE_STATE( AfxGetStaticModuleState() ); pMyDlg = new CMyDlg( CWnd::FromHandle( hParent ) ); if ( pMyDlg != NULL ) pMyDlg->ShowWindow( SW_HIDE ); return pMyDlg; }

              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