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. AfxGetModuleState not returning DLL's ModuleState

AfxGetModuleState not returning DLL's ModuleState

Scheduled Pinned Locked Moved C / C++ / MFC
c++question
14 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.
  • O Offline
    O Offline
    ohadp
    wrote on last edited by
    #1

    I have an MFC executable and an ATL DLL which supports MFC as well. When the DLL calls AfxGetModuleState it gets the EXE's ModuleState class instead of it's own. Why does this happen ? What am I missing ?

    P H 2 Replies Last reply
    0
    • O ohadp

      I have an MFC executable and an ATL DLL which supports MFC as well. When the DLL calls AfxGetModuleState it gets the EXE's ModuleState class instead of it's own. Why does this happen ? What am I missing ?

      P Offline
      P Offline
      Prakash Nadar
      wrote on last edited by
      #2

      is it causing a problem ?


      I'll write a suicide note on a hundred dollar bill - Dire Straits

      O 1 Reply Last reply
      0
      • P Prakash Nadar

        is it causing a problem ?


        I'll write a suicide note on a hundred dollar bill - Dire Straits

        O Offline
        O Offline
        ohadp
        wrote on last edited by
        #3

        Yes because when loading resources (AfxFindStringResourceHandle for example), AfxGetModuleState is called. So, my DLL tries to load a String resource for example, and tries to run through all of the EXE's resource-handles (because AfxGetModuleState returns the EXE's module object) instead of it's own list of resource-handles (stored in it's own module-object). Am I missing something ? Does the DLL really have it's own moduleobject ? I'm pretty sure it does, but why isn't it returned then ? thanks

        P 1 Reply Last reply
        0
        • O ohadp

          Yes because when loading resources (AfxFindStringResourceHandle for example), AfxGetModuleState is called. So, my DLL tries to load a String resource for example, and tries to run through all of the EXE's resource-handles (because AfxGetModuleState returns the EXE's module object) instead of it's own list of resource-handles (stored in it's own module-object). Am I missing something ? Does the DLL really have it's own moduleobject ? I'm pretty sure it does, but why isn't it returned then ? thanks

          P Offline
          P Offline
          Prakash Nadar
          wrote on last edited by
          #4

          When you are loading the resource string, dont you think you need module instance handle of the dll???


          I'll write a suicide note on a hundred dollar bill - Dire Straits

          O 1 Reply Last reply
          0
          • P Prakash Nadar

            When you are loading the resource string, dont you think you need module instance handle of the dll???


            I'll write a suicide note on a hundred dollar bill - Dire Straits

            O Offline
            O Offline
            ohadp
            wrote on last edited by
            #5

            You can, but the better way is to use AfxFindStringResourceHandle which not only looks in your resource-hinstance but also traverses the CDynLinkLibrary list and any other relevant resource-handles, that's the way to use several resource-dlls at the same time. Only that it doesn't work in this specific scenario because the module returned is the EXE's one and not the DLLs one...

            1 Reply Last reply
            0
            • O ohadp

              I have an MFC executable and an ATL DLL which supports MFC as well. When the DLL calls AfxGetModuleState it gets the EXE's ModuleState class instead of it's own. Why does this happen ? What am I missing ?

              H Offline
              H Offline
              HENDRIK R
              wrote on last edited by
              #6

              Did you insert AFX_MANAGE_STATE(AfxGetStaticModuleState()); before any MFC call you do from within a DLL function?


              We are men. We are different. We have only one word for soap. We do not own candles. We have never seen anything of any value in a craft shop. We do not own magazines full of photographs of celebrities with their clothes on. - Steve

              O 2 Replies Last reply
              0
              • H HENDRIK R

                Did you insert AFX_MANAGE_STATE(AfxGetStaticModuleState()); before any MFC call you do from within a DLL function?


                We are men. We are different. We have only one word for soap. We do not own candles. We have never seen anything of any value in a craft shop. We do not own magazines full of photographs of celebrities with their clothes on. - Steve

                O Offline
                O Offline
                ohadp
                wrote on last edited by
                #7

                Nope :-) Can you tell me more about this ? What does it do exactly ? Is it possible to do it once per module and not before every call ? thanks

                J H 2 Replies Last reply
                0
                • O ohadp

                  Nope :-) Can you tell me more about this ? What does it do exactly ? Is it possible to do it once per module and not before every call ? thanks

                  J Offline
                  J Offline
                  jmkhael
                  wrote on last edited by
                  #8

                  MSDN: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wcemfc/htm/funct_36.asp[^] Papa while (TRUE) Papa.WillLove ( Bebe ) ;

                  1 Reply Last reply
                  0
                  • O ohadp

                    Nope :-) Can you tell me more about this ? What does it do exactly ? Is it possible to do it once per module and not before every call ? thanks

                    H Offline
                    H Offline
                    HENDRIK R
                    wrote on last edited by
                    #9

                    try MSDN: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_mfc_afx_manage_state.asp[^]


                    We are men. We are different. We have only one word for soap. We do not own candles. We have never seen anything of any value in a craft shop. We do not own magazines full of photographs of celebrities with their clothes on. - Steve

                    1 Reply Last reply
                    0
                    • H HENDRIK R

                      Did you insert AFX_MANAGE_STATE(AfxGetStaticModuleState()); before any MFC call you do from within a DLL function?


                      We are men. We are different. We have only one word for soap. We do not own candles. We have never seen anything of any value in a craft shop. We do not own magazines full of photographs of celebrities with their clothes on. - Steve

                      O Offline
                      O Offline
                      ohadp
                      wrote on last edited by
                      #10

                      Ok I'm starting to get it, There is no other solution except for placing this in all my methods that perform MFC calls ? Isn't this abit weird ?

                      H D 2 Replies Last reply
                      0
                      • O ohadp

                        Ok I'm starting to get it, There is no other solution except for placing this in all my methods that perform MFC calls ? Isn't this abit weird ?

                        H Offline
                        H Offline
                        HENDRIK R
                        wrote on last edited by
                        #11

                        AFAIK this is the only solution. I don't think it's weird cause you only want to change the module state during the function call, and then set it back to the main application. And adding one line of code isn't too bad, is it ? :)


                        We are men. We are different. We have only one word for soap. We do not own candles. We have never seen anything of any value in a craft shop. We do not own magazines full of photographs of celebrities with their clothes on. - Steve

                        O 1 Reply Last reply
                        0
                        • H HENDRIK R

                          AFAIK this is the only solution. I don't think it's weird cause you only want to change the module state during the function call, and then set it back to the main application. And adding one line of code isn't too bad, is it ? :)


                          We are men. We are different. We have only one word for soap. We do not own candles. We have never seen anything of any value in a craft shop. We do not own magazines full of photographs of celebrities with their clothes on. - Steve

                          O Offline
                          O Offline
                          ohadp
                          wrote on last edited by
                          #12

                          In the begining of every function that uses an MFC method which in turn uses this DLL's own resources ? I think it sounds terrible :-) Having to remember to do this, and having other people rememebr to do this. Not to mention having my code cluttered by this line all the time... I want my module to always use the same AFX_MODULE_THINGY, why can't the AFX methods do AfxGetStaticModuleState(), that is my question actually. Why did they leave it this way ?

                          H 1 Reply Last reply
                          0
                          • O ohadp

                            In the begining of every function that uses an MFC method which in turn uses this DLL's own resources ? I think it sounds terrible :-) Having to remember to do this, and having other people rememebr to do this. Not to mention having my code cluttered by this line all the time... I want my module to always use the same AFX_MODULE_THINGY, why can't the AFX methods do AfxGetStaticModuleState(), that is my question actually. Why did they leave it this way ?

                            H Offline
                            H Offline
                            HENDRIK R
                            wrote on last edited by
                            #13

                            ohadp wrote: I want my module to always use the same AFX_MODULE_THINGY, why can't the AFX methods do AfxGetStaticModuleState(), that is my question actually. Why did they leave it this way ? Unfortunately (?) I was never a part of the development teams that invented MFC and the related techniques. So I fear this is a question I can't answer you - I just take it as is, and every time my DLL does some weird things the 'AFX_MODULE_THINGY' is the first thing that comes to me. Hope you'll reach that state soon, too. ;)


                            We are men. We are different. We have only one word for soap. We do not own candles. We have never seen anything of any value in a craft shop. We do not own magazines full of photographs of celebrities with their clothes on. - Steve

                            1 Reply Last reply
                            0
                            • O ohadp

                              Ok I'm starting to get it, There is no other solution except for placing this in all my methods that perform MFC calls ? Isn't this abit weird ?

                              D Offline
                              D Offline
                              David Crow
                              wrote on last edited by
                              #14

                              ohadp wrote: There is no other solution except for placing this in all my methods that perform MFC calls ? No, it is only needed by those functions that load resources from the DLL. Your DLL can use MFC all day long, but if it ever needs to load one of its own resources, it must use the AFX_MANAGE_STATE() macro.


                              "The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)

                              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