News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Change Exe Icon

Started by ecube, November 17, 2006, 12:05:53 AM

Previous topic - Next topic

ecube

Can anyone tell me why this isn't working, it just changes the icon to blank and makes the program not work. I've only been testing this with programs that already have icons.


  .386
      .model flat, stdcall
      option casemap :none   ; case sensitive

; #########################################################################

      include \masm32\include\windows.inc
      include \masm32\include\kernel32.inc
      includelib \masm32\lib\kernel32.lib

szUpdateResource proto :DWORD,:DWORD,:DWORD,:DWORD 
MAKELANGID PROTO :USHORT,:USHORT   
ChangeExeIcon proto :DWORD,:DWORD
           CTEXT MACRO text:VARARG
            LOCAL TxtName
              .data
               TxtName BYTE text,0
              .code
            EXITM <ADDR TxtName>
     ENDM   


.code
start:
invoke ChangeExeIcon,CTEXT("c:\changeme.exe"),CTEXT("C:\Program Files\mIRC\mirc.exe")
invoke ExitProcess,0

ChangeExeIcon proc tochange:DWORD,inPut:DWORD
LOCAL hFile:DWORD
LOCAL hCopy:DWORD
invoke BeginUpdateResource,tochange,TRUE
mov hFile,eax
invoke LoadLibraryEx,inPut,NULL,LOAD_LIBRARY_AS_DATAFILE
mov hCopy,eax
invoke EnumResourceNames,hCopy ,RT_ICON,addr szUpdateResource,hFile
invoke EnumResourceNames,hCopy ,RT_GROUP_ICON,addr szUpdateResource,hFile
invoke FreeLibrary,hCopy
invoke EndUpdateResource,hFile,FALSE
ret
ChangeExeIcon endp


szUpdateResource proc hModule:DWORD,lpszType:DWORD,lpszName:DWORD,lParam:DWORD
LOCAL hUpdate:DWORD
LOCAL hRes:DWORD
LOCAL nSizeOfRes:DWORD
LOCAL pData:DWORD
LOCAL hResLoaded:DWORD
mov ecx,lParam
mov hUpdate,ecx
invoke FindResource,hModule,lpszName,lpszType
  mov hRes,eax
invoke LoadResource,hModule, hRes
  mov hResLoaded ,eax
  invoke LockResource,hResLoaded
  mov pData,eax
  invoke SizeofResource,hModule,hRes
  mov nSizeOfRes,eax
  invoke MAKELANGID,LANG_ENGLISH,SUBLANG_ENGLISH_US
  mov ecx,eax
  invoke UpdateResource,hUpdate,lpszType,lpszName,ecx,pData,nSizeOfRes
  invoke GetModuleHandle, CTEXT("kernel32.dll")
  mov ecx,eax
  invoke GetProcAddress,ecx,CTEXT("UnlockResource")
  push hResLoaded
  call eax
   invoke FreeResource,hResLoaded
   mov eax,TRUE
  ret
szUpdateResource endp


MAKELANGID proc usPrimaryLanguage:USHORT, usSubLanguage:USHORT
movzx eax, usPrimaryLanguage
movzx ebx, usSubLanguage
shl ebx, 10
or eax, ebx
ret
MAKELANGID endp
end start

six_L

regards

six_L

#2
checked on msdn, then it works fine.
.386
.model flat,stdcall
option casemap:none
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc

includelib \masm32\lib\kernel32.lib
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
szUpdateResource proto :DWORD,:DWORD,:DWORD,:DWORD
MAKELANGID PROTO :USHORT,:USHORT   
ChangeExeIcon proto :DWORD,:DWORD
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
CTEXT MACRO text:VARARG
LOCAL TxtName
.data
        TxtName BYTE text,0
.code
        EXITM <offset TxtName>
ENDM   
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.code
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
start:
invoke ChangeExeIcon,CTEXT("c:\Tree_2.exe"),CTEXT("C:\LineGradient.exe")
invoke ExitProcess,0
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
ChangeExeIcon proc tochange:DWORD,inPut:DWORD
LOCAL hFile:DWORD
LOCAL hCopy:DWORD

invoke LoadLibraryEx,inPut,NULL,LOAD_LIBRARY_AS_DATAFILE
mov hCopy,eax
invoke BeginUpdateResource,tochange,FALSE
mov hFile,eax
invoke EnumResourceNames,hCopy ,RT_ICON,offset szUpdateResource,hFile
invoke EnumResourceNames,hCopy ,RT_GROUP_ICON,offset szUpdateResource,hFile
invoke EndUpdateResource,hFile,FALSE
invoke FreeLibrary,hCopy
ret

ChangeExeIcon endp
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
szUpdateResource proc uses ecx hModule:DWORD,lpszType:DWORD,lpszName:DWORD,lParam:DWORD
LOCAL hUpdate:DWORD
LOCAL hRes:DWORD
LOCAL nSizeOfRes:DWORD
LOCAL pData:DWORD
LOCAL hResLoaded:DWORD

mov eax,lParam
mov hUpdate,eax
invoke FindResource,hModule,lpszName,lpszType
mov hRes,eax
invoke LoadResource,hModule, hRes
mov hResLoaded ,eax
invoke LockResource,hResLoaded
mov pData,eax
invoke SizeofResource,hModule,hRes
mov nSizeOfRes,eax
invoke MAKELANGID,LANG_ENGLISH,SUBLANG_ENGLISH_US
mov ecx,eax
invoke UpdateResource,hUpdate,lpszType,lpszName,ecx,pData,nSizeOfRes
;invoke FreeResource,hResLoaded
mov eax,TRUE
ret

szUpdateResource endp
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
MAKELANGID proc usPrimaryLanguage:USHORT, usSubLanguage:USHORT

movzx eax, usPrimaryLanguage
movzx ebx, usSubLanguage
shl ebx, 10
or eax, ebx
ret

MAKELANGID endp
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

end start

[attachment deleted by admin]
regards

sinsi

If I remove this
  invoke GetModuleHandle, CTEXT("kernel32.dll")
  mov ecx,eax
  invoke GetProcAddress,ecx,CTEXT("UnlockResource")
  push hResLoaded
  call eax

then my 2 test exe's end up with the same icons (using your code).

The SDK has this to say about UnlockResource (under "Obsolete Windows Programming Elements")
Quote
Not necessary and has no effect
and GetProcAddress returns EAX=0 when I debugged the original (XPHSP2), so it doesn't
seem to be in kernel32.dll.
Light travels faster than sound, that's why some people seem bright until you hear them.