snify Posted January 20, 2010 Share Posted January 20, 2010 (edited) Hey, I am using this Func expandcollapse popupFunc _Res_Update($Filename, $InpResFile, $RSection, $RType = 1, $RLanguage = 2057) Local $hDll, $result, $rh, $hFile, $tSize, $tBuffer, $pBuffer, $poBuffer, $bread = 0 If $InpResFile = "" Then $tBuffer = DllStructCreate("char Text[1]") DllStructSetData($tBuffer, 1, Binary("0x00")) $poBuffer = DllStructGetPtr($tBuffer) $tSize = 0 $hDll = DllOpen("kernel32.dll") $result = DllCall($hDll, "ptr", "BeginUpdateResource", "str", $Filename, "int", 0) $rh = $result[0] $result = DllCall($hDll, "int", "UpdateResource", "ptr", $rh, "Long", $RSection, "Long", $RType, "short", $RLanguage, "ptr", $poBuffer, 'dword', $tSize) $result = DllCall($hDll, "int", "EndUpdateResource", "ptr", $rh, "int", 0) DllClose($hDll) Return EndIf If Not FileExists($InpResFile) Then Return EndIf $hFile = _WinAPI_CreateFile($InpResFile, 2, 2) If Not $hFile Then Return EndIf $hDll = DllOpen("kernel32.dll") Switch $RSection Case 3 $tSize = FileGetSize($InpResFile) - 6 Local $tB_Input_Header = DllStructCreate("short res;short type;short ImageCount;char rest[" & $tSize + 1 & "]") ; Create the buffer. Local $pB_Input_Header = DllStructGetPtr($tB_Input_Header) _WinAPI_ReadFile($hFile, $pB_Input_Header, FileGetSize($InpResFile), $bread, 0) If $hFile Then _WinAPI_CloseHandle($hFile) Local $IconType = DllStructGetData($tB_Input_Header, "Type") Local $IconCount = DllStructGetData($tB_Input_Header, "ImageCount") Local $tB_IconGroupHeader = DllStructCreate("short res;short type;short ImageCount;char rest[" & $IconCount * 14 & "]") ; Create the buffer. Local $pB_IconGroupHeader = DllStructGetPtr($tB_IconGroupHeader) DllStructSetData($tB_IconGroupHeader, "Res", 0) DllStructSetData($tB_IconGroupHeader, "Type", $IconType) DllStructSetData($tB_IconGroupHeader, "ImageCount", $IconCount) For $x = 1 To $IconCount Local $pB_Input_IconHeader = DllStructGetPtr($tB_Input_Header, 4) + ($x - 1) * 16 Local $tB_Input_IconHeader = DllStructCreate("byte Width;byte Heigth;Byte Colors;Byte res;Short Planes;Short BitPerPixel;dword ImageSize;dword ImageOffset", $pB_Input_IconHeader) ; Create the buffer. Local $IconWidth = DllStructGetData($tB_Input_IconHeader, "Width") Local $IconHeigth = DllStructGetData($tB_Input_IconHeader, "Heigth") Local $IconColors = DllStructGetData($tB_Input_IconHeader, "Colors") Local $IconPlanes = DllStructGetData($tB_Input_IconHeader, "Planes") Local $IconBitPerPixel = DllStructGetData($tB_Input_IconHeader, "BitPerPixel") Local $IconImageSize = DllStructGetData($tB_Input_IconHeader, "ImageSize") Local $IconImageOffset = DllStructGetData($tB_Input_IconHeader, "ImageOffset") $pB_IconGroupHeader = DllStructGetPtr($tB_IconGroupHeader, 4) + ($x - 1) * 14 Local $tB_GroupIcon = DllStructCreate("byte Width;byte Heigth;Byte Colors;Byte res;Short Planes;Short BitPerPixel;dword ImageSize;byte ResourceID", $pB_IconGroupHeader) ; Create the buffer. DllStructSetData($tB_GroupIcon, "Width", $IconWidth) DllStructSetData($tB_GroupIcon, "Heigth", $IconHeigth) DllStructSetData($tB_GroupIcon, "Colors", $IconColors) DllStructSetData($tB_GroupIcon, "res", 0) DllStructSetData($tB_GroupIcon, "Planes", $IconPlanes) DllStructSetData($tB_GroupIcon, "BitPerPixel", $IconBitPerPixel) DllStructSetData($tB_GroupIcon, "ImageSize", $IconImageSize) $IconResBase += 1 DllStructSetData($tB_GroupIcon, "ResourceID", $IconResBase) Local $pB_IconData = DllStructGetPtr($tB_Input_Header) + $IconImageOffset $result = DllCall($hDll, "ptr", "BeginUpdateResource", "str", $Filename, "int", 0) $rh = $result[0] $result = DllCall($hDll, "int", "UpdateResource", "ptr", $rh, "Long", 3, "Long", $IconResBase, "short", $RLanguage, "ptr", $pB_IconData, 'dword', $IconImageSize) If $result[0] <> 1 Then ConsoleWrite('UpdateResources: $result[0] = ' & $result[0] & " - LastError:" & _WinAPI_GetLastError() & ":" & _WinAPI_GetLastErrorMessage()) $result = DllCall($hDll, "int", "EndUpdateResource", "ptr", $rh, "int", 0) If $result[0] <> 1 Then ConsoleWrite('EndUpdateResource: $result[0] = ' & $result[0] & " - LastError:" & _WinAPI_GetLastError() & ":" & _WinAPI_GetLastErrorMessage()) Next $pB_IconGroupHeader = DllStructGetPtr($tB_IconGroupHeader) $result = DllCall($hDll, "ptr", "BeginUpdateResource", "str", $Filename, "int", 0) $rh = $result[0] $result = DllCall($hDll, "int", "UpdateResource", "ptr", $rh, "Long", 14, "long", $RType, "short", $RLanguage, "ptr", $pB_IconGroupHeader, 'dword', DllStructGetSize($tB_IconGroupHeader)) $result = DllCall($hDll, "int", "EndUpdateResource", "ptr", $rh, "int", 0) Case 10, 16, 24 $result = DllCall($hDll, "ptr", "BeginUpdateResource", "str", $Filename, "int", 0) $rh = $result[0] $tSize = FileGetSize($InpResFile) -64 $tBuffer = DllStructCreate("char Text[64];char Text[" & $tSize & "]") $pBuffer = DllStructGetPtr($tBuffer) $poBuffer = DllStructGetPtr($tBuffer, 2); _WinAPI_ReadFile($hFile, $pBuffer, FileGetSize($InpResFile), $bread, 0) If $hFile Then _WinAPI_CloseHandle($hFile) If $bread > 0 Then $result = DllCall($hDll, "int", "UpdateResource", "ptr", $rh, "Long", $RSection, "Long", $RType, "short", $RLanguage, "ptr", $poBuffer, 'dword', $tSize) EndIf $result = DllCall($hDll, "int", "EndUpdateResource", "ptr", $rh, "int", 0) Case Else $result = DllCall($hDll, "ptr", "BeginUpdateResourceW", "wstr", $Filename, "int", 0) $rh = $result[0] $tSize = FileGetSize($InpResFile) $tBuffer = DllStructCreate("char Text[" & $tSize & "]") $pBuffer = DllStructGetPtr($tBuffer) _WinAPI_ReadFile($hFile, $pBuffer, FileGetSize($InpResFile), $bread, 0) If $hFile Then _WinAPI_CloseHandle($hFile) If $bread > 0 Then $result = DllCall($hDll, "int", "UpdateResourceW", "ptr", $rh, "wstr", StringUpper($RSection), "wstr", StringUpper($RType), "int", $RLanguage, "ptr", $pBuffer, 'dword', $tSize) If $result[0] <> 1 Then ConsoleWrite('UpdateResources other: $result[0] = ' & $result[0] & " - LastError:" & _WinAPI_GetLastError() & ":" & _WinAPI_GetLastErrorMessage()) EndIf $result = DllCall($hDll, "int", "EndUpdateResourceW", "hwnd", $rh, "int", 0) EndSwitch DllClose($hDll) EndFunc I use it with RC_DATA (ID = 10) But I want to make a String in the Resource. For Example: _ResUpdate ("File1.exe", "test.txt", 10, "STRINGONE") Is this possible? Thank you. Edited January 20, 2010 by snify Link to comment Share on other sites More sharing options...
Developers Jos Posted January 20, 2010 Developers Share Posted January 20, 2010 I use it with RC_DATA (ID = 10)But I want to make a String in the Resource.For Example:_ResUpdate ("File1.exe", "test.txt", "MYSTRING", "STRINGONE")Is this possible?You will have to use an updated version of the func which is part of AutoIt3Wrapper modified by wraithdu.Not sure if Zedna is planning to update his UDF set too (i assume that is what you are using here)Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now