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. AFX_MANAGE_STATE(AfxGetStaticModuleState());

AFX_MANAGE_STATE(AfxGetStaticModuleState());

Scheduled Pinned Locked Moved C / C++ / MFC
comquestion
7 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.
  • N Offline
    N Offline
    Niklas L
    wrote on last edited by
    #1

    Hi I have a dll with exported functions, which I protect with AFX_MANAGE_STATE(AfxGetStaticModuleState()). Fine. Now, to those functions I send a callback function as a param. This callback function is in the exe. Is there a corresponding way to restore the module state when I get back into the exe, or do I need to roll up my sleves for this one? It's a requirement that the writer of the dll shouldn't be bothered with restoring the state before calling the callbacks, but just setting his own state correctly using the AFX_MANAGE_STATE macro. tia Niklas

    home

    M 1 Reply Last reply
    0
    • N Niklas L

      Hi I have a dll with exported functions, which I protect with AFX_MANAGE_STATE(AfxGetStaticModuleState()). Fine. Now, to those functions I send a callback function as a param. This callback function is in the exe. Is there a corresponding way to restore the module state when I get back into the exe, or do I need to roll up my sleves for this one? It's a requirement that the writer of the dll shouldn't be bothered with restoring the state before calling the callbacks, but just setting his own state correctly using the AFX_MANAGE_STATE macro. tia Niklas

      home

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      Do you really need to do this? Are you accessing resources in the dll and the callback? Mark

      N 1 Reply Last reply
      0
      • M Mark Salsbery

        Do you really need to do this? Are you accessing resources in the dll and the callback? Mark

        N Offline
        N Offline
        Niklas L
        wrote on last edited by
        #3

        Yes. :( The dlls may supply dialogs, as well as calling one of the callbacks to invoke the exes dialogs (along with other things)

        home

        M 1 Reply Last reply
        0
        • N Niklas L

          Yes. :( The dlls may supply dialogs, as well as calling one of the callbacks to invoke the exes dialogs (along with other things)

          home

          M Offline
          M Offline
          Mark Salsbery
          wrote on last edited by
          #4

          I would think you'd just need AFX_MANAGE_STATE(AfxGetStaticModuleState()) at the top of the callback function. As long as the module handle is set properly so MFC can find and load resources when it needs to. This can also be overriden by loading the resources yourself if you need to. Mark

          N 2 Replies Last reply
          0
          • M Mark Salsbery

            I would think you'd just need AFX_MANAGE_STATE(AfxGetStaticModuleState()) at the top of the callback function. As long as the module handle is set properly so MFC can find and load resources when it needs to. This can also be overriden by loading the resources yourself if you need to. Mark

            N Offline
            N Offline
            Niklas L
            wrote on last edited by
            #5

            I already tried that. AfxGetStaticModuleState() only seems to work in dlls. It returns null for resource and instance handles.

            home

            1 Reply Last reply
            0
            • M Mark Salsbery

              I would think you'd just need AFX_MANAGE_STATE(AfxGetStaticModuleState()) at the top of the callback function. As long as the module handle is set properly so MFC can find and load resources when it needs to. This can also be overriden by loading the resources yourself if you need to. Mark

              N Offline
              N Offline
              Niklas L
              wrote on last edited by
              #6

              After some investigation I found that AFX_MODULE_STATE* pPrevModuleState = AfxSetModuleState(NULL); on entry, and AfxSetModuleState(pPrevModuleState); on exit seems to work. This will allow me to load the correct resources and also use AfxGetApp() and its compadres. (though I'm not entirely convinced yet) thanks for your time. Niklas

              home

              M 1 Reply Last reply
              0
              • N Niklas L

                After some investigation I found that AFX_MODULE_STATE* pPrevModuleState = AfxSetModuleState(NULL); on entry, and AfxSetModuleState(pPrevModuleState); on exit seems to work. This will allow me to load the correct resources and also use AfxGetApp() and its compadres. (though I'm not entirely convinced yet) thanks for your time. Niklas

                home

                M Offline
                M Offline
                Mark Salsbery
                wrote on last edited by
                #7

                That sounds good :) Just in case you haven't seen this: How to properly export functions by using the MFC Shared Library[^] Outlines the few things that can fail if it's not right. Mark

                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