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. Load Dialog From a Resource DLL

Load Dialog From a Resource DLL

Scheduled Pinned Locked Moved C / C++ / MFC
comgraphicshelptutoriallearning
16 Posts 5 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.
  • L Lost User

    Is the resource ID ID_DIALOG in the calling program equal to what was used in the DLL? If you're not sure and you don't have the DLL's code to look it up, you could analyse the DLL with the resource hacker[^].

    G Offline
    G Offline
    goldenrose9
    wrote on last edited by
    #7

    i have the correct id, i need a small code to show the dialog from reource dll in win32 way

    Some Day I Will Prove MySelf :: GOLD

    1 Reply Last reply
    0
    • G goldenrose9

      I need a sample of how to load dialog resource from a dll I found a sample here but it is not working. http://www.codeproject.com/Messages/1212280/Re-how-to-load-dialog-resource-from-a-dll.aspx

      // Load the resource dll
      HMODULE hModule = LoadLibrary("C:\\another_resource.dll");

      if(hModule != NULL)
      {
      // Loading your dialog
      HWND hDialog = CreateDialog(hModule, MAKEINTRESOURCE(ID_DIALOG), /* Handle to parent window */, /* Pointer to dialog procedure function */);

      // Loading your bitmap
      HBITMAP hBitmap = LoadBitmap(hModule, MAKEINTRESOURCE(IDB_BITMAP);

      FreeLibrary(hModule);
      }

      thanx in advance please help

      Some Day I Will Prove MySelf :: GOLD

      A Offline
      A Offline
      Andrew Brock
      wrote on last edited by
      #8

      Firstly you need a message handler, essentialy the same as your main message handler, usually WndProc

      BOOL CALLBACK DlgProc(HWND hDlg, UINT nMessage, WPARAM wParam, LPARAM lParam) {
      switch (nMessage) {
      case WM_INITDIALOG:
      //This is where you do all your initialisation. This is the first place after all the controls have been created, so you can use GetDlgItem()
      return TRUE;

      	case WM\_COMMAND:
      		//This is the same as it is in the WndProc, handle button clicks, etc...
      		switch (LOWORD(wParam)) {
      			case IDOK: //This is usually the OK or Done button
      				return TRUE; 
      
      			case IDCANCEL: //This is usually the Close or Cancel button
      				DestroyWindow(hDlg); //close the dialog
      				return TRUE;
      		}
      		break;
              } 
      } 
      return FALSE; 
      

      }

      Then you just need to use that as the "procedure function"

      void DisplayDynamicDialog(HWND hParent) {
      HMODULE hModule = LoadLibrary("Resources.dll");
      if(hModule != NULL) {
      hDialog = CreateDialog(hModule, MAKEINTRESOURCE(ID_DIALOG), hParent, (DLGPROC)DlgProc);
      ShowWindow(hDialog, SW_SHOW);
      FreeLibrary(hModule); //This might need to be called later, after the dialog has been closed since it is modeless
      }
      }

      Finally, just to reiterate what Thaddeus Jones said, the ID you supply needs to be the ID defined in the DLL, not the ID defined in the exe, hence the resource.h that you include needs to be from the dll. To avoid confusion, I recommend using quoted string names instead.

      G 1 Reply Last reply
      0
      • G goldenrose9

        I need a sample of how to load dialog resource from a dll I found a sample here but it is not working. http://www.codeproject.com/Messages/1212280/Re-how-to-load-dialog-resource-from-a-dll.aspx

        // Load the resource dll
        HMODULE hModule = LoadLibrary("C:\\another_resource.dll");

        if(hModule != NULL)
        {
        // Loading your dialog
        HWND hDialog = CreateDialog(hModule, MAKEINTRESOURCE(ID_DIALOG), /* Handle to parent window */, /* Pointer to dialog procedure function */);

        // Loading your bitmap
        HBITMAP hBitmap = LoadBitmap(hModule, MAKEINTRESOURCE(IDB_BITMAP);

        FreeLibrary(hModule);
        }

        thanx in advance please help

        Some Day I Will Prove MySelf :: GOLD

        A Offline
        A Offline
        Abhi Lahare
        wrote on last edited by
        #9

        you can also use combination of LoadResource[^] and FindResouce[^]

        1 Reply Last reply
        0
        • G goldenrose9

          I need a sample of how to load dialog resource from a dll I found a sample here but it is not working. http://www.codeproject.com/Messages/1212280/Re-how-to-load-dialog-resource-from-a-dll.aspx

          // Load the resource dll
          HMODULE hModule = LoadLibrary("C:\\another_resource.dll");

          if(hModule != NULL)
          {
          // Loading your dialog
          HWND hDialog = CreateDialog(hModule, MAKEINTRESOURCE(ID_DIALOG), /* Handle to parent window */, /* Pointer to dialog procedure function */);

          // Loading your bitmap
          HBITMAP hBitmap = LoadBitmap(hModule, MAKEINTRESOURCE(IDB_BITMAP);

          FreeLibrary(hModule);
          }

          thanx in advance please help

          Some Day I Will Prove MySelf :: GOLD

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

          Firstly your call to CreateDialog() is incomplete, so this code will not even compile. Secondly are you sure you are making the right call (i.e. is this a Modal or Modeless dialog)? Take a look here[^] for some more information.

          I must get a clever new signature for 2011.

          G 1 Reply Last reply
          0
          • G goldenrose9

            create dialog.. Is required, I have the correct dialog id and i m able to load the dll using loadlibrary(). After this i m confused what to do next, so i need a small example that demonstrate how to show the dialog from resource dll. Thanx in advance.

            Some Day I Will Prove MySelf :: GOLD

            C Offline
            C Offline
            Cool_Dev
            wrote on last edited by
            #11

            see from msdn documentation http://msdn.microsoft.com/en-us/library/ms644996%28v=vs.85%29.aspx#modeless_box[^]

            G 1 Reply Last reply
            0
            • L Lost User

              Firstly your call to CreateDialog() is incomplete, so this code will not even compile. Secondly are you sure you are making the right call (i.e. is this a Modal or Modeless dialog)? Take a look here[^] for some more information.

              I must get a clever new signature for 2011.

              G Offline
              G Offline
              goldenrose9
              wrote on last edited by
              #12

              i know it is incomplete, therefore i m in need of a sample in win32 way.

              Some Day I Will Prove MySelf :: GOLD

              L 1 Reply Last reply
              0
              • C Cool_Dev

                see from msdn documentation http://msdn.microsoft.com/en-us/library/ms644996%28v=vs.85%29.aspx#modeless_box[^]

                G Offline
                G Offline
                goldenrose9
                wrote on last edited by
                #13

                thanx, but i need help in displaying a dialog from a resouce dll.

                Some Day I Will Prove MySelf :: GOLD

                1 Reply Last reply
                0
                • A Andrew Brock

                  Firstly you need a message handler, essentialy the same as your main message handler, usually WndProc

                  BOOL CALLBACK DlgProc(HWND hDlg, UINT nMessage, WPARAM wParam, LPARAM lParam) {
                  switch (nMessage) {
                  case WM_INITDIALOG:
                  //This is where you do all your initialisation. This is the first place after all the controls have been created, so you can use GetDlgItem()
                  return TRUE;

                  	case WM\_COMMAND:
                  		//This is the same as it is in the WndProc, handle button clicks, etc...
                  		switch (LOWORD(wParam)) {
                  			case IDOK: //This is usually the OK or Done button
                  				return TRUE; 
                  
                  			case IDCANCEL: //This is usually the Close or Cancel button
                  				DestroyWindow(hDlg); //close the dialog
                  				return TRUE;
                  		}
                  		break;
                          } 
                  } 
                  return FALSE; 
                  

                  }

                  Then you just need to use that as the "procedure function"

                  void DisplayDynamicDialog(HWND hParent) {
                  HMODULE hModule = LoadLibrary("Resources.dll");
                  if(hModule != NULL) {
                  hDialog = CreateDialog(hModule, MAKEINTRESOURCE(ID_DIALOG), hParent, (DLGPROC)DlgProc);
                  ShowWindow(hDialog, SW_SHOW);
                  FreeLibrary(hModule); //This might need to be called later, after the dialog has been closed since it is modeless
                  }
                  }

                  Finally, just to reiterate what Thaddeus Jones said, the ID you supply needs to be the ID defined in the DLL, not the ID defined in the exe, hence the resource.h that you include needs to be from the dll. To avoid confusion, I recommend using quoted string names instead.

                  G Offline
                  G Offline
                  goldenrose9
                  wrote on last edited by
                  #14

                  :thumbsup: thanks a lot, worked like a charm, once again thanx.

                  Some Day I Will Prove MySelf :: GOLD

                  1 Reply Last reply
                  0
                  • G goldenrose9

                    i know it is incomplete, therefore i m in need of a sample in win32 way.

                    Some Day I Will Prove MySelf :: GOLD

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

                    OK so what part of this[^] are you having trouble with?

                    I must get a clever new signature for 2011.

                    G 1 Reply Last reply
                    0
                    • L Lost User

                      OK so what part of this[^] are you having trouble with?

                      I must get a clever new signature for 2011.

                      G Offline
                      G Offline
                      goldenrose9
                      wrote on last edited by
                      #16

                      sir i had received the answer, thanx for giving ur valuable time sir.

                      Some Day I Will Prove MySelf :: GOLD

                      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