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. Binary resource in Windows service?

Binary resource in Windows service?

Scheduled Pinned Locked Moved C / C++ / MFC
questionhardwarejsonlearning
14 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.
  • J James R Twine

    Have you tried calling FindResourceEx with a NULL instance parameter directly?  Also, try using FindResource if language is not an concern (and it sounds like it is not).    Also, how are the resources identified, by number or by string?  Are you using the correct Resource Type value?    Peace! -=- James


    If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
    Tip for new SUV drivers: Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
    DeleteFXPFiles & CheckFavorites (Please rate this post!)

    R Offline
    R Offline
    RoyceF
    wrote on last edited by
    #5

    Yes, I tried FindResourceEx() with the NULL instance parameter. The resources are identified by number, their type is "TEXT".

    J 1 Reply Last reply
    0
    • R RoyceF

      Yes, I tried FindResourceEx() with the NULL instance parameter. The resources are identified by number, their type is "TEXT".

      J Offline
      J Offline
      James R Twine
      wrote on last edited by
      #6

      Are you using MAKEINTRESOURCE to specify the identifying number?    This might go faster if we had a code snippet of the code you are using...    Peace! -=- James


      If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
      Tip for new SUV drivers: Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
      DeleteFXPFiles & CheckFavorites (Please rate this post!)

      R 1 Reply Last reply
      0
      • J James R Twine

        Are you using MAKEINTRESOURCE to specify the identifying number?    This might go faster if we had a code snippet of the code you are using...    Peace! -=- James


        If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
        Tip for new SUV drivers: Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
        DeleteFXPFiles & CheckFavorites (Please rate this post!)

        R Offline
        R Offline
        RoyceF
        wrote on last edited by
        #7

        This code fails - the m_hInstance member is null: CWinApp* lpApp = AfxGetApp(); HINSTANCE hInstance = lpApp->m_hInstance; This code fails - fires an assert in debug, throws an exception in release version: HINSTANCE hInstance = AfxGetInstanceHandle(); This code never executes because of the above failures: HANDLE hHandle1 = LoadResource( hInstance, FindResource( hInstance, MAKEINTRESOURCE( IDR_RES1 ), "TEXT" ) ); HANDLE hHandle2 = LoadResource( hInstance, FindResource( hInstance, MAKEINTRESOURCE( IDR_RES2 ), "TEXT" ) ); This code works in 3 other Windows desktop applications. It just doesn't work here because of the runtime environment, the service. I am trying to find a way around the fact that the embedded resources aren't accessible when the service is loading, or even after it is loaded. Thanks for your help, Royce

        B J 2 Replies Last reply
        0
        • R RoyceF

          This code fails - the m_hInstance member is null: CWinApp* lpApp = AfxGetApp(); HINSTANCE hInstance = lpApp->m_hInstance; This code fails - fires an assert in debug, throws an exception in release version: HINSTANCE hInstance = AfxGetInstanceHandle(); This code never executes because of the above failures: HANDLE hHandle1 = LoadResource( hInstance, FindResource( hInstance, MAKEINTRESOURCE( IDR_RES1 ), "TEXT" ) ); HANDLE hHandle2 = LoadResource( hInstance, FindResource( hInstance, MAKEINTRESOURCE( IDR_RES2 ), "TEXT" ) ); This code works in 3 other Windows desktop applications. It just doesn't work here because of the runtime environment, the service. I am trying to find a way around the fact that the embedded resources aren't accessible when the service is loading, or even after it is loaded. Thanks for your help, Royce

          B Offline
          B Offline
          Blake Miller
          wrote on last edited by
          #8

          If your resources are contained directly within your EXE file, then use GetModuleHandle(NULL) to retrieve the 'instance' handle used for loading the resources :cool:

          1 Reply Last reply
          0
          • R RoyceF

            This code fails - the m_hInstance member is null: CWinApp* lpApp = AfxGetApp(); HINSTANCE hInstance = lpApp->m_hInstance; This code fails - fires an assert in debug, throws an exception in release version: HINSTANCE hInstance = AfxGetInstanceHandle(); This code never executes because of the above failures: HANDLE hHandle1 = LoadResource( hInstance, FindResource( hInstance, MAKEINTRESOURCE( IDR_RES1 ), "TEXT" ) ); HANDLE hHandle2 = LoadResource( hInstance, FindResource( hInstance, MAKEINTRESOURCE( IDR_RES2 ), "TEXT" ) ); This code works in 3 other Windows desktop applications. It just doesn't work here because of the runtime environment, the service. I am trying to find a way around the fact that the embedded resources aren't accessible when the service is loading, or even after it is loaded. Thanks for your help, Royce

            J Offline
            J Offline
            James R Twine
            wrote on last edited by
            #9

            When you said an "MFC based service" before, do you really mean a MFC service, or an ATL service with "support MFC" checked.  If you have the latter, you need to "fool" MFC by doing the following:

            	CWinApp	waWA;
            
            	waWA.m_hInstance = _Module.GetModuleInstance();
            	afxCurrentInstanceHandle = _Module.GetModuleInstance();    // Or ::GetModuleHandle( NULL )
            	afxCurrentResourceHandle = _Module.GetResourceInstance();  // Or ::GetModuleHandle( NULL )
            

            Then things that refrence the global CWinApp instance will work correctly.  Kludgy, but that is what you get for mixing MFC and ATL with VC++ 6.0! :)    Peace! -=- James


            If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
            Tip for new SUV drivers: Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
            DeleteFXPFiles & CheckFavorites (Please rate this post!)

            R 2 Replies Last reply
            0
            • J James R Twine

              When you said an "MFC based service" before, do you really mean a MFC service, or an ATL service with "support MFC" checked.  If you have the latter, you need to "fool" MFC by doing the following:

              	CWinApp	waWA;
              
              	waWA.m_hInstance = _Module.GetModuleInstance();
              	afxCurrentInstanceHandle = _Module.GetModuleInstance();    // Or ::GetModuleHandle( NULL )
              	afxCurrentResourceHandle = _Module.GetResourceInstance();  // Or ::GetModuleHandle( NULL )
              

              Then things that refrence the global CWinApp instance will work correctly.  Kludgy, but that is what you get for mixing MFC and ATL with VC++ 6.0! :)    Peace! -=- James


              If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
              Tip for new SUV drivers: Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
              DeleteFXPFiles & CheckFavorites (Please rate this post!)

              R Offline
              R Offline
              RoyceF
              wrote on last edited by
              #10

              No, there is no ATL support in this project.

              1 Reply Last reply
              0
              • J James R Twine

                When you said an "MFC based service" before, do you really mean a MFC service, or an ATL service with "support MFC" checked.  If you have the latter, you need to "fool" MFC by doing the following:

                	CWinApp	waWA;
                
                	waWA.m_hInstance = _Module.GetModuleInstance();
                	afxCurrentInstanceHandle = _Module.GetModuleInstance();    // Or ::GetModuleHandle( NULL )
                	afxCurrentResourceHandle = _Module.GetResourceInstance();  // Or ::GetModuleHandle( NULL )
                

                Then things that refrence the global CWinApp instance will work correctly.  Kludgy, but that is what you get for mixing MFC and ATL with VC++ 6.0! :)    Peace! -=- James


                If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
                Tip for new SUV drivers: Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
                DeleteFXPFiles & CheckFavorites (Please rate this post!)

                R Offline
                R Offline
                RoyceF
                wrote on last edited by
                #11

                GetModuleHandle(NULL) returns 0x00400000, which is not a valid handle.

                J 1 Reply Last reply
                0
                • R RoyceF

                  GetModuleHandle(NULL) returns 0x00400000, which is not a valid handle.

                  J Offline
                  J Offline
                  James R Twine
                  wrote on last edited by
                  #12

                  Have you tried using it?  Even if it was invalid, using FindResource(...) with a NULL hModule parameter should default to using the load image (EXE).    Are the resources present in the executable itself, and not in another DLL?  Are you sure they are being linked in correctly?  One way to test is to open a new instance of DevStudio, and open the EXE file being sure to specify "Resources" in the "Open As" combobox.  You can them be sure that the resources are actually there and accessable - you should be able to double-click on them and see them in the binary editor.    I am running out of ideas here...    Peace! -=- James


                  If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
                  Tip for new SUV drivers: Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
                  DeleteFXPFiles & CheckFavorites (Please rate this post!)

                  R 2 Replies Last reply
                  0
                  • J James R Twine

                    Have you tried using it?  Even if it was invalid, using FindResource(...) with a NULL hModule parameter should default to using the load image (EXE).    Are the resources present in the executable itself, and not in another DLL?  Are you sure they are being linked in correctly?  One way to test is to open a new instance of DevStudio, and open the EXE file being sure to specify "Resources" in the "Open As" combobox.  You can them be sure that the resources are actually there and accessable - you should be able to double-click on them and see them in the binary editor.    I am running out of ideas here...    Peace! -=- James


                    If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
                    Tip for new SUV drivers: Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
                    DeleteFXPFiles & CheckFavorites (Please rate this post!)

                    R Offline
                    R Offline
                    RoyceF
                    wrote on last edited by
                    #13

                    Yea, so am I! Yes, when I use the invalid handle, I just get another null.

                    1 Reply Last reply
                    0
                    • J James R Twine

                      Have you tried using it?  Even if it was invalid, using FindResource(...) with a NULL hModule parameter should default to using the load image (EXE).    Are the resources present in the executable itself, and not in another DLL?  Are you sure they are being linked in correctly?  One way to test is to open a new instance of DevStudio, and open the EXE file being sure to specify "Resources" in the "Open As" combobox.  You can them be sure that the resources are actually there and accessable - you should be able to double-click on them and see them in the binary editor.    I am running out of ideas here...    Peace! -=- James


                      If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
                      Tip for new SUV drivers: Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
                      DeleteFXPFiles & CheckFavorites (Please rate this post!)

                      R Offline
                      R Offline
                      RoyceF
                      wrote on last edited by
                      #14

                      Yes, the resources are in the EXE. I have opened the EXE in binary mode with the IDE's resource editor and I can see them.

                      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