hi everyone!
I want to make a function for everyone to change a icon.
but i have to less experience:





.386
.model flat,stdcall
option casemap:none

include <windows.inc>
include <kernel32.inc>
include <user32.inc>
includelib <user32.lib>
includelib <kernel32.lib>

.data
lpmsg1 DB 1024 DUP (0)
lpmsg DD 0
ErrorMessage macro
; DWORD lpmsg;string pointer
call GetLastError
mov ecx,eax
invoke FormatMessage, FORMAT_MESSAGE_ALLOCATE_BUFFER or FORMAT_MESSAGE_FROM_SYSTEM, NULL, eax, LANG_NEUTRAL,ADDR lpmsg,0,NULL
invoke MessageBox, NULL, lpmsg, 0, MB_OK
endm

hRessource DD 0
hIcon DD 0
hLockRes DD 0
hExe DD 0
hOwnIcon DD 0
hInstance DD 0
Error DB 'Super-Error', 0
Buffer DB 'c:\target1.exe', 0



checkforErros macro HandleRe:REQ
LOCAL error1
LOCAL noError
OR EAX, EAX
JZ error1
MOV HandleRe, EAX
JMP noError
error1:
INVOKE MessageBox, 0, ADDR Error, ADDR Error,0
JMP endesdf
noError:
ENDM

.code
start:
MOV EAX, offset lpmsg1
MOV lpmsg, EAX

invoke GetModuleHandle, NULL
mov hInstance, eax

INVOKE LoadLibrary, addr Buffer ;hExe
checkforErros hExe

INVOKE LoadIcon, hExe, 1000
checkforErros hIcon

INVOKE LoadIcon, hInstance, 1000
checkforErros hOwnIcon

INVOKE LockResource, hIcon
INVOKE BeginUpdateResource, ADDR Buffer, 0
;ErrorMessage
checkforErros hRessource
mov ecx, SUBLANG_DEFAULT
shl ecx, 10
add ecx, LANG_NEUTRAL
invoke SizeofResource, hRessource, hOwnIcon
INVOKE UpdateResource, hRessource, RT_ICON, hIcon,ECX, hOwnIcon, eax

endesdf:
ret
END start

I updated the source.

Greets BBB
Posted on 2003-10-21 05:10:48 by Bubu-Boy
I can't begin to list the misconceptions there, first the value returned by LoadIcon is not useable in update resource, you must first convert it to raw data. The proper sequence to update a resource is as follows:
; Create buffers to store the data

invoke GlobalAlloc,GMEM_FIXED,ResourceSize
mov pData,eax

; ##################################
; You must copy the data into the buffer here
; ##################################

invoke BeginUpdateResource,OFFSET TargetFile,FALSE
mov hUpdate,eax

; Write the data to the resource section
invoke UpdateResource, hUpdate, RT_TYPE, ResNumber, NULL, pData, ResourceSize

; End the update
invoke EndUpdateResource,hUpdate,FALSE

; Done with the buffer
invoke GlobalFree,pData
Posted on 2003-10-21 05:33:41 by donkey
more things about your code:
[b]INVOKE LoadLibrary, addr Buffer[/b]            ;hExe

checkforErros hExe

[b]INVOKE BeginUpdateResource, ADDR Buffer, 1[/b]
checkforErros hRessource

You cannot update the resources of a file that is executing, if you perform a load library the file is in effect executing at that point and you are not allowed to update the resources. The BeginUpdateResource will always fail.:
pFileName
Pointer to a null-terminated string that specifies the executable file in which to update resources. An application must be able to obtain write access to this file; it cannot be currently executing. If pFileName does not specify a full path, the system searches for the file in the current directory.
Posted on 2003-10-21 05:45:53 by donkey
Maybe you should use SetClassLong.

C example : SetClassLong(hwndDlg,GCL_HICON,(LONG)LoadIcon(hInstance,MAKEINTRESOURCE(IDC_ICONO)));


MSDN SetClassLong

I hope it works for you.
:alright:
Posted on 2003-10-21 06:19:41 by Eternal Idol Birmingham
Hi donkey,

the things wich are clear for me yoiu underlined.:tongue:
But how the Icon(with fails everytime) and obtain the datasize is unclear for me.


; Create buffers to store the data
invoke GlobalAlloc,GMEM_FIXED,ResourceSize
mov pData,eax

; ##################################
; You must copy the data into the buffer here
; ##################################

that's just the dingbat i stop at.

Greets BBB!
Posted on 2003-10-21 11:04:11 by Bubu-Boy
Dont let my thread die, please.

Greets BBB
Posted on 2003-10-22 05:35:30 by Bubu-Boy
I think I already told you how to do it...
:o
Posted on 2003-10-22 05:45:12 by Eternal Idol Birmingham
Hi, i want to change the exe-icon.
But I have troubles to load and convert the icon from the sourceexe.

Greets
Posted on 2003-10-22 05:51:17 by Bubu-Boy
If you want to change it in design time download reshacker.

Do you want to change the icon on run-time?

If you, then you must use the SetClassLong as I told you before.
Posted on 2003-10-22 05:56:33 by Eternal Idol Birmingham
thank Eternal Idol Birmingham.
But I dont want to change it at runtime. And the icon shuld be replaced.
Si I cant use your suggestion, or?

Greets your BBB
Posted on 2003-10-22 06:10:52 by Bubu-Boy
Read this please:

DOWNLOAD RESHACKER : http://www.users.on.net/johnson/resourcehacker/

Now I'm your babysitter ;)
Posted on 2003-10-22 06:18:44 by Eternal Idol Birmingham
hi Eternal Idol Birmingham
i want to programm that by my self.
I love programming.

Greets !
Posted on 2003-10-22 06:41:31 by Bubu-Boy
You were in right path then, you want to make a resouce editor.
Please try to improve your English.

I'll try to help you next weekend, now I'm at work and I'cant code that much.

See you.

:)
Posted on 2003-10-22 06:46:30 by Eternal Idol Birmingham
Eternal Idol Birmingham your shouldn;t code anything for me.
That I want programm it by my selfe should be clear cuz i startet to programm it.

Greets !
I have just problems to get the icon from a exe.


INVOKE LoadLibrary, addr Buffer ;hExe
checkforErros hExe
INVOKE LoadIcon, hExe, 100
;fails !!!!!! but why


Greets your BBB
Posted on 2003-10-22 06:59:20 by Bubu-Boy
now the source ist like this:




.386
.model flat,stdcall
option casemap:none

include <windows.inc>
include <kernel32.inc>
include <user32.inc>
includelib <user32.lib>
includelib <kernel32.lib>

.data
lpmsg1 DB 1024 DUP (0)
lpmsg DD 0
ErrorMessage macro
; DWORD lpmsg;string pointer
call GetLastError
mov ecx,eax
invoke FormatMessage, FORMAT_MESSAGE_ALLOCATE_BUFFER or FORMAT_MESSAGE_FROM_SYSTEM, NULL, eax, LANG_NEUTRAL,ADDR lpmsg,0,NULL
invoke MessageBox, NULL, lpmsg, 0, MB_OK
endm

hRessource DD 0
hIcon DD 0
hLockRes DD 0
hExe DD 0
hOwnIcon DD 0
hInstance DD 0
Error DB 'Super-Error', 0
Buffer DB 'c:\target1.exe', 0



checkforErros macro HandleRe:REQ
LOCAL error1
LOCAL noError
OR EAX, EAX
JZ error1
MOV HandleRe, EAX
JMP noError
error1:
INVOKE MessageBox, 0, ADDR Error, ADDR Error,0
JMP endesdf
noError:
ENDM

.code
start:
MOV EAX, offset lpmsg1
MOV lpmsg, EAX

invoke GetModuleHandle, NULL
mov hInstance, eax

INVOKE LoadLibrary, addr Buffer ;hExe
checkforErros hExe

INVOKE LoadIcon, hExe, 1000
checkforErros hIcon

INVOKE LoadIcon, hInstance, 1000
checkforErros hOwnIcon

INVOKE LockResource, hIcon
INVOKE BeginUpdateResource, ADDR Buffer, 0
;ErrorMessage
checkforErros hRessource
mov ecx, SUBLANG_DEFAULT
shl ecx, 10
add ecx, LANG_NEUTRAL
invoke SizeofResource, hRessource, hOwnIcon
INVOKE UpdateResource, hRessource, RT_ICON, hIcon,ECX, hOwnIcon, eax

endesdf:
ret
END start



Posted on 2003-10-22 09:10:05 by Bubu-Boy
come on! Boby-Boy is back.

Whats about my cute sample, who will tell me, what i have made wrong.


Thanks you in advance.
Your BBB
Posted on 2003-12-18 14:02:15 by Bubu-Boy