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. ATL MFC shell extension DLL LoadImage fails with 1813

ATL MFC shell extension DLL LoadImage fails with 1813

Scheduled Pinned Locked Moved C / C++ / MFC
c++graphicshelpcomlinux
6 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.
  • K Offline
    K Offline
    Kuniva
    wrote on last edited by
    #1

    Not sure if this is the right forum since it also has to do with ATL but.. I'm programming a shell extension dll (context menu) based off the article "The Complete Idiot's Guide to Writing Shell Extensions" by Michael Dunn. So I made an ATL project with MFC and COM support. At first I started by using SetMenuItemBitmaps() to set the menu item icons, but then I found out that this method doesn't support transparency. Because achieving transparency for menu icons is apparently far from straightforward, I had the marvelous idea of looking at the Tortoise CVS shell code. I incorporated some of the ideas like using LoadImage() and GDI plus on Vista to blit the icons to a bitmap and make them look good that way, but I also noticed that they didn't use ATL and did reference counting themselves (and as such are also easily able to access the DLL's instance handle). My problem now is that each LoadImage() call fails with error code 1813 which according to MSDN means "The specified resource type cannot be found in the image file.". Now my best bet is that I'm somehow using the wrong module handle (the one of the EXE perhaps instead of the DLL), but I've tried everything I can think of to get the correct handle including: 1. Use the m_hInstance member of the global CWinApp instance. 2. Just pass in NULL for LoadImage(). 3. Use GetModuleHandle() with the dll name passed in. This returns a handle but it still fails with 1813. 4. Use MFC's AfxFindResourceHandle() to get a handle to the dll instance. This fails with an assertion error in some MFC file saying the current resource handle is not set (so i tried setting it with AfxSetResourceHandle() to the theApp.m_hInstance handle, but that just crashed). I'm starting to wonder if the people from tortoise intentionally decided not to use ATL so they could get the instance handle from DllMain(). Either way, it seems to me that I've bumped into some internal MFC/ATL funkyness and I can't figure it out. So if anyone knows more about this or has any suggestions, do tell :) Oh yea, note: For the resource I'm testing with I'm simply using a string id such as "IDI_TORTU" which I then pass to LoadImage(). greets

    Kuniva --------------------------------------------

    C 1 Reply Last reply
    0
    • K Kuniva

      Not sure if this is the right forum since it also has to do with ATL but.. I'm programming a shell extension dll (context menu) based off the article "The Complete Idiot's Guide to Writing Shell Extensions" by Michael Dunn. So I made an ATL project with MFC and COM support. At first I started by using SetMenuItemBitmaps() to set the menu item icons, but then I found out that this method doesn't support transparency. Because achieving transparency for menu icons is apparently far from straightforward, I had the marvelous idea of looking at the Tortoise CVS shell code. I incorporated some of the ideas like using LoadImage() and GDI plus on Vista to blit the icons to a bitmap and make them look good that way, but I also noticed that they didn't use ATL and did reference counting themselves (and as such are also easily able to access the DLL's instance handle). My problem now is that each LoadImage() call fails with error code 1813 which according to MSDN means "The specified resource type cannot be found in the image file.". Now my best bet is that I'm somehow using the wrong module handle (the one of the EXE perhaps instead of the DLL), but I've tried everything I can think of to get the correct handle including: 1. Use the m_hInstance member of the global CWinApp instance. 2. Just pass in NULL for LoadImage(). 3. Use GetModuleHandle() with the dll name passed in. This returns a handle but it still fails with 1813. 4. Use MFC's AfxFindResourceHandle() to get a handle to the dll instance. This fails with an assertion error in some MFC file saying the current resource handle is not set (so i tried setting it with AfxSetResourceHandle() to the theApp.m_hInstance handle, but that just crashed). I'm starting to wonder if the people from tortoise intentionally decided not to use ATL so they could get the instance handle from DllMain(). Either way, it seems to me that I've bumped into some internal MFC/ATL funkyness and I can't figure it out. So if anyone knows more about this or has any suggestions, do tell :) Oh yea, note: For the resource I'm testing with I'm simply using a string id such as "IDI_TORTU" which I then pass to LoadImage(). greets

      Kuniva --------------------------------------------

      C Offline
      C Offline
      Code o mat
      wrote on last edited by
      #2

      Try using the resource ID (numeric) with MAKEINTRESOURCE instead of the "IDI_TORTU" thing... aside of that, you sure you are specifying the right flags to LoadImage, maybe you are trying to load a BITMAP instead of an ICON and it cannot find a BITMAP among the resources with that ID (since it is an ICON) thus the error?

      > The problem with computers is that they do what you tell them to do and not what you want them to do. < > Life: great graphics, but the gameplay sux. <

      K 1 Reply Last reply
      0
      • C Code o mat

        Try using the resource ID (numeric) with MAKEINTRESOURCE instead of the "IDI_TORTU" thing... aside of that, you sure you are specifying the right flags to LoadImage, maybe you are trying to load a BITMAP instead of an ICON and it cannot find a BITMAP among the resources with that ID (since it is an ICON) thus the error?

        > The problem with computers is that they do what you tell them to do and not what you want them to do. < > Life: great graphics, but the gameplay sux. <

        K Offline
        K Offline
        Kuniva
        wrote on last edited by
        #3

        Code-o-mat, The LoadImage call looks like this:

        HICON hIcon = (HICON) LoadImageA(handle, sIcon.c_str(), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);

        So it is loaded as type IMAGE_ICON, which it is in the resource file (I just copied the tortoise icon). Hmm I just tried it with a numeric identifier with MAKEINTRESOURCE and that does work however.. I want to use string identifiers like tortoise does because I'll be loading which icon to use from a configuration file (and I don't want to use numbers to indicate icons in that). I must be doing something wrong with the resources.. :/

        Kuniva --------------------------------------------

        C 1 Reply Last reply
        0
        • K Kuniva

          Code-o-mat, The LoadImage call looks like this:

          HICON hIcon = (HICON) LoadImageA(handle, sIcon.c_str(), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);

          So it is loaded as type IMAGE_ICON, which it is in the resource file (I just copied the tortoise icon). Hmm I just tried it with a numeric identifier with MAKEINTRESOURCE and that does work however.. I want to use string identifiers like tortoise does because I'll be loading which icon to use from a configuration file (and I don't want to use numbers to indicate icons in that). I must be doing something wrong with the resources.. :/

          Kuniva --------------------------------------------

          C Offline
          C Offline
          Code o mat
          wrote on last edited by
          #4

          Alternatively you could "convert" the strings you use in the configuration file into numeric IDs in your code (like if (strid == "IDI_TORTU") numid = IDI_TORTU; else ...). I always used MAKEINTRESOURCE with LoadImage so i'm not sure about string-identification...could it be that the method doesn't actually expects you to specify "IDI_TORTU" but rather the file name the resource was imported from, for example "my_tortu_icon.ico"?

          > The problem with computers is that they do what you tell them to do and not what you want them to do. < > Life: great graphics, but the gameplay sux. <

          K 1 Reply Last reply
          0
          • C Code o mat

            Alternatively you could "convert" the strings you use in the configuration file into numeric IDs in your code (like if (strid == "IDI_TORTU") numid = IDI_TORTU; else ...). I always used MAKEINTRESOURCE with LoadImage so i'm not sure about string-identification...could it be that the method doesn't actually expects you to specify "IDI_TORTU" but rather the file name the resource was imported from, for example "my_tortu_icon.ico"?

            > The problem with computers is that they do what you tell them to do and not what you want them to do. < > Life: great graphics, but the gameplay sux. <

            K Offline
            K Offline
            Kuniva
            wrote on last edited by
            #5

            Eureka! : ) No it was nothing like that. Seems all this time I've been looking in the wrong place. I didn't know that for your resources to have string identifiers, you need to remove the define in whatever your numeric resource header file is maintained by visual studio. I just deleted IDI_TORTU in resource.h and now it works like a charm (doh :) ). Thanks for your help, if I hadn't simply tested with MAKEINTRESOURCE I'd still be debugging for instance handles ;)

            Kuniva --------------------------------------------

            C 1 Reply Last reply
            0
            • K Kuniva

              Eureka! : ) No it was nothing like that. Seems all this time I've been looking in the wrong place. I didn't know that for your resources to have string identifiers, you need to remove the define in whatever your numeric resource header file is maintained by visual studio. I just deleted IDI_TORTU in resource.h and now it works like a charm (doh :) ). Thanks for your help, if I hadn't simply tested with MAKEINTRESOURCE I'd still be debugging for instance handles ;)

              Kuniva --------------------------------------------

              C Offline
              C Offline
              Code o mat
              wrote on last edited by
              #6

              We always learn something new... :)

              > The problem with computers is that they do what you tell them to do and not what you want them to do. < > Life: great graphics, but the gameplay sux. <

              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