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. Resource conflict on ON_UPDATE_COMMAND_UI

Resource conflict on ON_UPDATE_COMMAND_UI

Scheduled Pinned Locked Moved C / C++ / MFC
questionsharepointlearning
6 Posts 3 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.
  • Y Offline
    Y Offline
    yccheok
    wrote on last edited by
    #1

    I have an EXE class which contains a button resource with ID EXE_BUTTON_RESOURCE

    ON_UPDATE_COMMAND_UI(EXE_BUTTON_RESOURCE, OnUpdateExeButtonResource)

    void EXE::OnUpdateExeButtonResource(CCmdUI* pCmdUI)
    {
    pCmdUI->Enable(exe_flag);
    }

    This EXE application will load another DLL class. DLL class is having a menu item resource with ID DLL_MENU_RESOURCE. Unfortunately, EXE_BUTTON_RESOURCE and DLL_MENU_RESOURCE is having the same resource ID. To avoid them have conflict ID is pretty difficult, as they are two separate projects. Whenever exe_flag, which is the member for EXE turn to false, this will affect menu in DLL too. Clicking on DLL_MENU_RESOURCE menu will have no effect at all. How can I avoid this trap? Having manual inspection on their resource.h files is not an option for me, as they are 2 separate projects, managed by 2 separate teams.

    _ 1 Reply Last reply
    0
    • Y yccheok

      I have an EXE class which contains a button resource with ID EXE_BUTTON_RESOURCE

      ON_UPDATE_COMMAND_UI(EXE_BUTTON_RESOURCE, OnUpdateExeButtonResource)

      void EXE::OnUpdateExeButtonResource(CCmdUI* pCmdUI)
      {
      pCmdUI->Enable(exe_flag);
      }

      This EXE application will load another DLL class. DLL class is having a menu item resource with ID DLL_MENU_RESOURCE. Unfortunately, EXE_BUTTON_RESOURCE and DLL_MENU_RESOURCE is having the same resource ID. To avoid them have conflict ID is pretty difficult, as they are two separate projects. Whenever exe_flag, which is the member for EXE turn to false, this will affect menu in DLL too. Clicking on DLL_MENU_RESOURCE menu will have no effect at all. How can I avoid this trap? Having manual inspection on their resource.h files is not an option for me, as they are 2 separate projects, managed by 2 separate teams.

      _ Offline
      _ Offline
      _Superman_
      wrote on last edited by
      #2

      Try adding the following statement as the first line in every exported function of the DLL. AFX_MANAGE_STATE(AfxGetStaticModuleState());

      «_Superman_»
      I love work. It gives me something to do between weekends.

      Microsoft MVP (Visual C++)

      Polymorphism in C

      Y 1 Reply Last reply
      0
      • _ _Superman_

        Try adding the following statement as the first line in every exported function of the DLL. AFX_MANAGE_STATE(AfxGetStaticModuleState());

        «_Superman_»
        I love work. It gives me something to do between weekends.

        Microsoft MVP (Visual C++)

        Polymorphism in C

        Y Offline
        Y Offline
        yccheok
        wrote on last edited by
        #3

        Do you mean code like this ?

        void EXE::OnUpdateExeButtonResource(CCmdUI* pCmdUI)
        {
        AFX_MANAGE_STATE(AfxGetStaticModuleState());
        pCmdUI->Enable(exe_flag);
        }

        No. It doesn't work. Clicking on DLL's menu item will still have no effect. Is changing

        #define DLL_RESOURCE_ID 1234

        to

        const int DLL_RESOURCE_ID = ::RegisterWindowMessage(_T("DLL_RESOURCE_ID"));

        a elegant solution (To avoid resource ID conflict)? I don't know.

        _ S 2 Replies Last reply
        0
        • Y yccheok

          Do you mean code like this ?

          void EXE::OnUpdateExeButtonResource(CCmdUI* pCmdUI)
          {
          AFX_MANAGE_STATE(AfxGetStaticModuleState());
          pCmdUI->Enable(exe_flag);
          }

          No. It doesn't work. Clicking on DLL's menu item will still have no effect. Is changing

          #define DLL_RESOURCE_ID 1234

          to

          const int DLL_RESOURCE_ID = ::RegisterWindowMessage(_T("DLL_RESOURCE_ID"));

          a elegant solution (To avoid resource ID conflict)? I don't know.

          _ Offline
          _ Offline
          _Superman_
          wrote on last edited by
          #4

          I meant adding in the DLL's code, not the EXE's.

          «_Superman_»
          I love work. It gives me something to do between weekends.

          Microsoft MVP (Visual C++)

          Polymorphism in C

          Y 1 Reply Last reply
          0
          • _ _Superman_

            I meant adding in the DLL's code, not the EXE's.

            «_Superman_»
            I love work. It gives me something to do between weekends.

            Microsoft MVP (Visual C++)

            Polymorphism in C

            Y Offline
            Y Offline
            yccheok
            wrote on last edited by
            #5

            I cannot use your suggestion as I am using extension DLL. http://support.microsoft.com/kb/161589 However, I already did a similar thing even before your suggestion.

            void DLL::OnContextMenu(CWnd* pWnd, CPoint point)
            {
            RestoreDLLState ext;
            ...
            }

            RestoreDLLState will load global DLL resource, and load back its original resource once done.

            RestoreDLLState::RestoreDLLState()
            {
            m_hInstOld = AfxGetResourceHandle();
            AfxSetResourceHandle(g_hResource);
            }

            RestoreDLLState::~RestoreDLLState()
            {
            AfxSetResourceHandle(m_hInstOld);
            }

            It doesn't work. :(

            1 Reply Last reply
            0
            • Y yccheok

              Do you mean code like this ?

              void EXE::OnUpdateExeButtonResource(CCmdUI* pCmdUI)
              {
              AFX_MANAGE_STATE(AfxGetStaticModuleState());
              pCmdUI->Enable(exe_flag);
              }

              No. It doesn't work. Clicking on DLL's menu item will still have no effect. Is changing

              #define DLL_RESOURCE_ID 1234

              to

              const int DLL_RESOURCE_ID = ::RegisterWindowMessage(_T("DLL_RESOURCE_ID"));

              a elegant solution (To avoid resource ID conflict)? I don't know.

              S Offline
              S Offline
              Sauro Viti
              wrote on last edited by
              #6

              The RegisterWindowMessage Function (Windows)[^] defines a new window message that is guaranteed to be unique throughout the system, and is designed to generate at runtime message IDs that could be used for inter-process communications: using it solve your problem, but it could not be a good idea if you use it extensively, because it waste system resources. Anyway, the changement you are evaluating, requires that you manually modify the resource.h file on your project to remove the correspondant #define and produce a situation where the resource editor is not able to load and handle your resource script file (i.e. project_name.rc), then you should modify it manually.

              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