i have a problem that add a selected icon ton my exe
can your help me?

.model flat,stdcall 
option casemap:none 
include    windows.inc
include    kernel32.inc
includelib kernel32.lib
    szTargetExe db 'test.exe',0
    szTargetFile db 'main.ico',0
    hMod dd 0
    hFile dd 0
    dwSize dd 0
    invoke CreateFile, ADDR szTargetFile, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0
    test eax,eax
    js _exit
    mov hFile,eax
    invoke GetFileSize, eax, 0
    mov dwSize,eax
    invoke CloseHandle, hFile

    invoke BeginUpdateResource, ADDR szTargetExe, 0
    or eax,eax
    jz _exit
    mov hMod,eax
    invoke UpdateResource, eax, RT_GROUP_ICON, 100, 0, addr szTargetFile, dwSize 
    invoke EndUpdateResource, hMod, 0

    invoke ExitProcess, 0
end start

thanks in forward
Posted on 2007-02-24 09:50:13 by ragdog
I don't think it wants an addr to the file name - try loading the file into memory and pass the memory pointer inside UpdateResource.
Posted on 2007-02-24 09:53:58 by JimmyClif

HANDLE BeginUpdateResource(LPCTSTR pFileName, BOOL DeleteExistingResources);

So it does want filename.

I remember playing around with this a bit, and there was some trickery wrt. the resource LangIDs - can't remember the specifics though, and I'm heading out now...
Posted on 2007-02-24 10:28:45 by f0dder
Yes f0dder, BeginUpdateResource needs the filename of the file you want to edit. But UpdateResource, which does the actual job, does not want the filename of the icon - instead it wants a pointer to a buffer with the "to replace" data.

BOOL UpdateResource(? ? ?

? ? HANDLE hUpdate,
? ? LPCTSTR lpType,
? ? LPCTSTR lpName,
? ? WORD wLanguage,
? ? LPVOID lpData,
? ? DWORD cbData

I might have explained myself wrong ;)
Posted on 2007-02-24 10:36:04 by JimmyClif
One more thing, BeginUpdateResource() system call and such do not work on Windows 95/98/ME... Although you can call them in mentioned Operating Systems, the Kernel will not do anything but ignoring the calls.
Posted on 2007-02-24 14:34:46 by XCHG