UpdateResource Failure

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Hi

I would like to modify icon resoures in a exe file.

I load the icon file to a byte array and then i pass it to the
updateresource method.

After that, I look into the exe file with the resource hacker, and the icon
is invalid, however it contains the same byte array as I loaded from an
icon.

What did I do wrong?

The source is the following :

Private Sub UpdateIcon(ByVal FileName As String, ByVal Icon_Group As
Boolean, ByVal LCID As Integer, id As Long, ByVal IconFileName As String)
Const NoDelete As Long = 0

Dim ResHandle As Long: ResHandle = Win32.BeginUpdateResource(FileName,
ByVal NoDelete)

If ResHandle = 0 Then
Throw InvalidOperation, Nothing, "Can't access the resource section!"
Else
Dim RT_Type As Long: RT_Type = IIf(Icon_Group, RT_GROUP_ICON,
Win32.RT_ICON) '--- set the resource type

Dim IconBuffer() As Byte: IconBuffer = FileToBuffer(IconFileName)
'--- Load the entire file to a buffer by the get statement

Call UpdateResourceNT(ResHandle, RT_Type, id, LCID, IconBuffer(0), ByVal
CLng(UBound(IconBuffer) - LBound(IconBuffer) + 1))

If Win32.EndUpdateResource(ResHandle, 0) = 0 Then
Debug.Print "Win32.EndUpdateResource Failed"
Throw InvalidConstraint, Nothing, "UpdateResource Failed"
End If

End If

End Sub


.



Relevant Pages

  • Re: Import exeutable icon
    ... To add icon to application you need to add ICON ... Shell by default reads first ICON resource ... Following the doc I managed to import an exe to my VC ... as a .exe file. ...
    (microsoft.public.win32.programmer.kernel)
  • Re: icon change
    ... >i mean i want to change the icon of ANOTHER exe file, ... data is already in the resource data format. ... and res data structures to accomplish it. ...
    (microsoft.public.vb.winapi)
  • Re: Insert Icon into the Resource file
    ... dont have source code with me and i dont do, open .exe file in msdev ... Resource Hacker. ... My notes on the subject said, "Updating resource with an icon from a .exe is ...
    (microsoft.public.vc.mfc)
  • How to embed any resource in ready EXE..
    ... how to embed any resource or code (e.g. ICON ... or BMP) to a ready EXE file whose code does not exist... ...
    (microsoft.public.dotnet.languages.vc)
  • Re: Proper use of #getImageBlock in runtime [LONG!]
    ... When Dolphin reads an icon or bitmap, ... It can load it from a "resource" embedded in an executable file ... where the FileLocator is an instance of one of the subclasses of FileLocator ... We can define a PackageRelativeFileLocator which includes the name of a package ...
    (comp.lang.smalltalk.dolphin)