The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: ragdog on August 01, 2008, 01:29:44 PM

Title: UpdateRes from resource to Exe
Post by: ragdog on August 01, 2008, 01:29:44 PM
hi

i have a question with update the dialog in any exe with  resource file *.res to exe

in the Resource.RES have i only a dialog for the target exe

invoke _UpdateResource,CTEXT ("Resource.RES"),CTEXT ("Target.exe"),1000

_UpdateResource proc lpszAddFile:dword,lpszToFile:dword,lpszResId:dword
LOCAL hAddFile:DWORD
LOCAL dwFileSize:DWORD
LOCAL dwBytesRead:DWORD
LOCAL ReadPtr:DWORD   
LOCAL hUpdateRes:DWORD
LOCAL dwValue:BYTE
   
     pushad
        mov dwValue,0
       
     invoke CreateFile,lpszAddFile, GENERIC_READ,0,NULL,OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,NULL
        cmp eax,INVALID_HANDLE_VALUE
         jz @ret
        mov hAddFile,eax
     invoke GetFileSize,hAddFile,NULL
        mov dwFileSize,eax
    invoke GlobalAlloc,NULL,dwFileSize
        mov ReadPtr,eax
     invoke ReadFile,hAddFile,ReadPtr,dwFileSize,ADDR dwBytesRead,NULL
     invoke BeginUpdateResource,lpszToFile,FALSE 
         or eax,eax
         jz @F
        mov hUpdateRes,eax
     invoke UpdateResource,eax, RT_DIALOG,lpszResId,LANG_NEUTRAL,ReadPtr,dwFileSize
         or eax, eax
         jz @F
     invoke EndUpdateResource,hUpdateRes,FALSE
         or eax, eax
         jz @F
        mov dwValue, 1
  @@:
     invoke   GlobalFree,ReadPtr
     invoke CloseHandle,hAddFile
@ret:
      popad
      movzx eax,dwValue   ;return: 1=success 0=failed
        ret
_UpdateResource endp

can your help me please?

greets,
ragdog

Title: Re: UpdateRes from resource to Exe
Post by: PBrennick on August 02, 2008, 01:08:18 AM
GENERIC_WRITE
Title: Re: UpdateRes from resource to Exe
Post by: ragdog on August 02, 2008, 08:41:41 AM
hi

this CreateFile is only for read the .res
why i add GENERIC_WRITE by createfile?


greets
Title: Re: UpdateRes from resource to Exe
Post by: evlncrn8 on August 02, 2008, 10:19:31 AM
because UpdateResource writes the data back to the file, thus if you don't have the file open with the GENERIC_WRITE it will fail (open it with GENERIC_READ + GENERIC_WRITE)....
Title: Re: UpdateRes from resource to Exe
Post by: ragdog on August 02, 2008, 10:56:09 AM
i have added  GENERIC_READ + GENERIC_WRITE this works not!

works this ever updateresource with add res to exe?
i think this works only with add icon or data!