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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Why doesn't this work?

Why doesn't this work?

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
4 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
    Nemok
    wrote on last edited by
    #1

    HICON hIcon; LPBYTE lpBuffer; hIcon=dlg.GetIconHandle(); lpBuffer=(LPBYTE)::GlobalLock(hIcon); HANDLE hUpd=BeginUpdateResource("D:\\n.exe",0); UpdateResource((HMODULE)hUpd, RT_ICON,MAKEINTRESOURCE(1), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPBYTE)lpBuffer, GlobalSize(hIcon)); EndUpdateResource(hUpd, FALSE); GlobalUnlock(lpBuffer); I'm using this code to take the icon from an exe and replace the icon in another exe, but it doesn't work. Every time lpBuffer is empty after GlobalLock. the hIcon handle is retrieved by ExtractIcon(); What am I doing wrong? Please help!

    J 1 Reply Last reply
    0
    • N Nemok

      HICON hIcon; LPBYTE lpBuffer; hIcon=dlg.GetIconHandle(); lpBuffer=(LPBYTE)::GlobalLock(hIcon); HANDLE hUpd=BeginUpdateResource("D:\\n.exe",0); UpdateResource((HMODULE)hUpd, RT_ICON,MAKEINTRESOURCE(1), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPBYTE)lpBuffer, GlobalSize(hIcon)); EndUpdateResource(hUpd, FALSE); GlobalUnlock(lpBuffer); I'm using this code to take the icon from an exe and replace the icon in another exe, but it doesn't work. Every time lpBuffer is empty after GlobalLock. the hIcon handle is retrieved by ExtractIcon(); What am I doing wrong? Please help!

      J Offline
      J Offline
      Jorgen Sigvardsson
      wrote on last edited by
      #2

      I doubt you can do lpBuffer=(LPBYTE)::GlobalLock(hIcon);. See this MSDN article[^] for more information on icons and resources. It links to a program written in C which has some code you can look at too. Please note that the structs in the article are wrong. Look at the code in the linked project instead. I believe you will have to fill out an entire ICONDIR, as icons are stored that way (an icon can contain several images). Then the appropriate number of ICONDIRENTRYs and ICONIMAGEs. That's what's supposed to be inside the resource part. But you are talking about replacing the icon in one exe from another one. I believe you can do the copy without too much work. Just grab a pointer to the icon resource in the source exe, and use it to update the icon entry in the other exe. I think that should work. The linked project has all the details. Good luck :) -- Arigato gozaimashida!

      N 1 Reply Last reply
      0
      • J Jorgen Sigvardsson

        I doubt you can do lpBuffer=(LPBYTE)::GlobalLock(hIcon);. See this MSDN article[^] for more information on icons and resources. It links to a program written in C which has some code you can look at too. Please note that the structs in the article are wrong. Look at the code in the linked project instead. I believe you will have to fill out an entire ICONDIR, as icons are stored that way (an icon can contain several images). Then the appropriate number of ICONDIRENTRYs and ICONIMAGEs. That's what's supposed to be inside the resource part. But you are talking about replacing the icon in one exe from another one. I believe you can do the copy without too much work. Just grab a pointer to the icon resource in the source exe, and use it to update the icon entry in the other exe. I think that should work. The linked project has all the details. Good luck :) -- Arigato gozaimashida!

        N Offline
        N Offline
        Nemok
        wrote on last edited by
        #3

        Well this is my problem: How can I grab a pointer from the resource (HICON)??? I was trying to do just that by using GlobalLock(). Do you know any other way to do this???

        J 1 Reply Last reply
        0
        • N Nemok

          Well this is my problem: How can I grab a pointer from the resource (HICON)??? I was trying to do just that by using GlobalLock(). Do you know any other way to do this???

          J Offline
          J Offline
          Jorgen Sigvardsson
          wrote on last edited by
          #4

          Read the MSDN article. It'll tell you what you can do with an HICON (hint: GetIconInfo() and build resource data from that) -- Arigato gozaimashida!

          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