Jump to content

AutoIt3Wrapper Resource Update


Jos
 Share

Recommended Posts

  • Developers

I have uploaded a TEST version of Autoit3wrapper with the buildin resource update called AutoIt3WrapperPE.au3 http://www.autoitscript.com/autoit3/scite/..._SciTE4AutoIt3/

This is the _UpdateResources() function I currently use:

Func _UpdateResources($Filename, $InpResFile, $RSection, $RType = 1, $RLanguage = 2057)
    Local $hDll, $result, $rh, $hFile, $tSize, $tBuffer, $pBuffer, $poBuffer, $bread = 0
    $hDll = DllOpen("kernel32.dll")
;
    If $InpResFile = "" Or Not FileExists($InpResFile) Then
    ; No resource file defined thus delete the existing resource
        $tBuffer = DllStructCreate("char Text[1]"); Create the buffer.
        DllStructSetData($tBuffer, 1, Binary("0x00"))
        $poBuffer = DllStructGetPtr($tBuffer)
        $tSize = 0
        $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)
    EndIf
; Open the Resource File
    $hFile = _WinAPI_CreateFile($InpResFile, 2, 2)
; Process te different Update types
    Switch $RSection
        Case 16; *** RT_VERSION
        ; Begin resource Update
            $result = DllCall($hDll, "ptr", "BeginUpdateResource", "str", $Filename, "int", 0)
            $rh = $result[0]
        ;Version section
            $tSize = FileGetSize($InpResFile) - 64
            $tBuffer = DllStructCreate("char Text[64];char Text[" & $tSize & "]"); Create the buffer.
            $pBuffer = DllStructGetPtr($tBuffer)
            $poBuffer = DllStructGetPtr($tBuffer, 2); Skip first 64 bytes for Version structure
            _WinAPI_ReadFile($hFile, $pBuffer, FileGetSize($InpResFile), $bread, 0)
            _WinAPI_CloseHandle($hFile)
            $result = DllCall($hDll, "int", "UpdateResource", "ptr", $rh, "Long", $RSection, "Long", $RType, "short", $RLanguage, "ptr", $poBuffer, 'dword', $tSize)
            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())

        Case 3; *** RT_ICON
        ;ICO section
            $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)
            _WinAPI_CloseHandle($hFile)
        ; Read input file header
            Local $IconType = DllStructGetData($tB_Input_Header, "Type")
            Local $IconCount = DllStructGetData($tB_Input_Header, "ImageCount")
        ; Created IconGroup Structure
            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)
        ; process all internal Icons
            For $x = 1 To $IconCount
            ; Set pointer correct in the input struct
                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.
            ; get info form the input
                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")
            ; Update the ICO Group header struc
                $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)
            ; Get data pointer
                Local $pB_IconData = DllStructGetPtr($tB_Input_Header) + $IconImageOffset
            ; Begin resource Update
                $result = DllCall($hDll, "ptr", "BeginUpdateResource", "str", $Filename, "int", 0)
                $rh = $result[0]
            ; add Icon
                $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
        ; Add Icongroup entry
            $pB_IconGroupHeader = DllStructGetPtr($tB_IconGroupHeader)
        ; Begin resource Update
            $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))
            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())
        Case 10,24; *** RT_RCDATA and RT_MANIFEST
        ; Begin resource Update
            $result = DllCall($hDll, "ptr", "BeginUpdateResource", "str", $Filename, "int", 0)
            $rh = $result[0]
            $tSize = FileGetSize($InpResFile)
            $tBuffer = DllStructCreate("char Text[" & $tSize & "]"); Create the buffer.
            $pBuffer = DllStructGetPtr($tBuffer)
            _WinAPI_ReadFile($hFile, $pBuffer, FileGetSize($InpResFile), $bread, 0)
            _WinAPI_CloseHandle($hFile)
            $result = DllCall($hDll, "int", "UpdateResource", "ptr", $rh, "Long", $RSection, "Long", $RType, "short", $RLanguage, "ptr", $pBuffer, 'dword', $tSize)
            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())
    EndSwitch
;
    DllClose($hDll)
;
EndFunc  ;==>_UpdateResources

@The Kandie Man ...could you give it a try on your x64 system ? (it is using the method of updating the BIN file at this moment .... thanks :D

Jos

EDIT: fixed the 63->64 thanks

EDIT: Several updates to the func

Edited by 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

  • Replies 86
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Yup, it works for 64bit executables. Excellent work.

- The Kandie Man ;-)

"So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire

Link to comment
Share on other sites

  • Developers

Yup, it works for 64bit executables. Excellent work.

- The Kandie Man ;-)

Thanks for testing ....

Now I need to check your approach to see how similar/different we did things :D

Also still would like to know what to do to update the resources of the EXE produced by aut2exe, but other then that I am fine with this option for the moment.

Also saves me from having to run UPX separately ...

Edited by 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

Was looking to a nice freeware file compare (hex) utility... do you know any ? (i know I had one on my previous PC but don't recall its name.

I am using HxD and CFF Explorer for normal Hex viewing but they don't do comparing of 2 files afaik.

In TotalCommander there is command to show file differences in text/binary way.

It's in File menu as "Compare by content".

I know it's not freeware just for your info Jos.

Link to comment
Share on other sites

I am using XVI32 as my hex editor as well as CFF Explorer. I am looking for a good free hex file comparing utility as well. Of course, finding good free stuff is hard because it is drowned out by all the expensive proprietary stuff when googling.

Try Tiny Hexer. It has compare amongst other features and is IMO a decent freeware hex editor. Keep up the good results. :D
Link to comment
Share on other sites

Try Tiny Hexer. It has compare amongst other features and is IMO a decent freeware hex editor. Keep up the good results. :D

Thanks. This is just what Jos and I were looking for.

- The Kandie Man ;-)

"So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire

Link to comment
Share on other sites

  • Developers

Try Tiny Hexer. It has compare amongst other features and is IMO a decent freeware hex editor. Keep up the good results. :D

That works fine ..thanks Michael :P

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

  • Developers

Updated the TEST version of AutoIt3WrapperPE:

- Several fixed in the resource file/manifest addition.

- Support internal AUT2EXE commands like /console /pack /nopack . This means it requires the latest version of aut2exe that comes with the latest Beta installer but also available in the Download directory: http://www.autoitscript.com/autoit3/scite/..._SciTE4AutoIt3/

Would appreciate when people can test the several Resource options on some of their script to see if they all still work.

Things that changed for Additional files is:

#AutoIt3Wrapper_Res_SaveSource=y will add the source to RT_RCDATA , 999

#AutoIt3Wrapper_Res_File_Add=filename will add now to RT_RCDATA, Sequential number starting with 1

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

  • Developers

Made a couple more changes : v1.9.5.10:

- always run aut2exe.exe on an XP machine.

- Cleanup of temp.rc file fixed.

- some other minor cosmetics

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

I suspect that modifying an already compiled script messes with a checksum that is generated when the script is compiled into AutoItSC.bin to produce the portable script. Therefore, it errors. Sorry about the confusion.

You need to checksum a file even after reshacking to my knowledge when the checksum is checked like as Windows setup does with files in XP. To fix the checksum, I use ModifyPE CLI utility. Use /? on ModifyPE for help. If it helps then good but unfortunately it is compiled from ASM source so porting to a AutoIt script would be differcult.

Usage:

ModifyPE "file" -c
Link to comment
Share on other sites

The checksum isn't set on AutoIt files.

Edit: I should say, the PE checksum isn't set (at least not at compile time or by Aut2Exe). I made sure of that when I added /console because I wanted to ensure it was re-calculated if needed.

It's possible that the code in use here strips stuff outside a PE section, which means it strips the script. A quick test can confirm, add a small resource, a few bytes, whatever the smallest you can do is, then check the size of the compiled script versus one compiled without the resource. My guess is you're going to find the size to be smaller with the one you tried to update the resources with.

I really wish I could remember why the method Jos is using is bad. Maybe this is why it's bad, it's not compatible with how we do things with AutoIt.

Edited by Valik
Link to comment
Share on other sites

  • Developers

@Mhz,

What is the problem/issue you got with the updated files?

I have done some checking but am not sure why this needs to be done and can't find much about it on the MSDN site yet.

Edited by 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

@Jos

I have no problems.

ModifyPE is just a suggestion_if_it is needed to correct the checksum of a modified file. You may_not_need it after updating resources in compiled AutoIt scripts.

Sorry if I seemed misleading. :D

Link to comment
Share on other sites

  • Developers

@Jos

I have no problems.

ModifyPE is just a suggestion_if_it is needed to correct the checksum of a modified file. You may_not_need it after updating resources in compiled AutoIt scripts.

Sorry if I seemed misleading. :D

No problem... i am learning here as I go along so just absorbing all info. The scripts I checked indeed do not have a PEChecksum at all set as Valik stated.

Was just wondering it it would case any issues ... :P

I am trying to puzzle the RT_VERSION together at this moment to also avoid the need for RC.exe & RCDLL.DLL to be included and ran.

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

  • Developers

I am getting a strange thing here and must be overlooking something (or stumbled on a Bug). I am building the VERSION Struct but when I build the STRING struct needed for it I get something strange. This example code will build the proper structure but is missing the last character for both the szKey and Value.

When i uncomment the 2 lines to add the last character things look good but that shouldn't be needed. ideas ? :D

The struct is save to a file for easy viewing with a hex editor.

#Include <WinAPI.au3>
$dP = _Res_BuildStringTableEntry("Comments","Test comment")
$fh = _WinAPI_CreateFile("testpe.txt",1,4)
$bwritten=0
_WinAPI_WriteFile($fh,DllStructGetPtr($dp),DllStructGetSize($dp),$bwritten)
_WinAPI_CloseHandle($fh)

Func _Res_BuildStringTableEntry($Key,$value)
    Local $p_VS_String = DllStructCreate( _
            "short   wLength;" & _  ;Specifies the length, in bytes, of this String structure. 
            "short   wValueLength;" & _;Specifies the size, in words, of the Value member. 
            "short   wType;" & _         ;Specifies the type of data in the version resource. This member is 1 if the version resource contains text data and 0 if the version resource contains binary data. 
            "wchar szKey[" & StringLen($key) & "];" & _;Specifies an arbitrary Unicode string. The szKey member can be one or more of the following values. These values are guidelines only. 
            "char   Padding[" & Mod(6+StringLen($key),4) & "];" & _ ;Contains as many zero words as necessary to align the Value member on a 32-bit boundary. 
            "wchar   Value[" & StringLen($value) & "]" );Specifies a zero-terminated string. See the szKey member description for more information. 
            DllStructSetData($p_VS_String,"Wlength",DllStructGetSize($p_VS_String))
            DllStructSetData($p_VS_String,"wValueLength",StringLen($value))
            DllStructSetData($p_VS_String,"szKey",$key)
;~          DllStructSetData($p_VS_String,"szKey",StringRight($key,1),StringLen($key))
            DllStructSetData($p_VS_String,"Value",$value)
;~          DllStructSetData($p_VS_String,"Value",StringRight($value,1),StringLen($value))
    Return $p_VS_String
EndFunc
Edited by 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

  • Developers

mmm total stripped down example of my problem:

Local $p_VS_String = DllStructCreate("wchar   szKey[8]" )
DllStructSetData($p_VS_String,"szKey","12345678")
ConsoleWrite('szKey = ' & DllStructGetData($p_VS_String,"szKey") & @crlf)

Looks like a hex 00 is added/replacing the last CHAR ....

Edited by 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

I am getting a strange thing here and must be overlooking something (or stumbled on a Bug). I am building the VERSION Struct but when I build the STRING struct needed for it I get something strange. This example code will build the proper structure but is missing the last character for both the szKey and Value.

When i uncomment the 2 lines to add the last character things look good but that shouldn't be needed. ideas ? :D

The struct is save to a file for easy viewing with a hex editor.

#Include <WinAPI.au3>
    $dP = _Res_BuildStringTableEntry("Comments","Test comment")
    $fh = _WinAPI_CreateFile("testpe.txt",1,4)
    $bwritten=0
    _WinAPI_WriteFile($fh,DllStructGetPtr($dp),DllStructGetSize($dp),$bwritten)
    _WinAPI_CloseHandle($fh)
    
    Func _Res_BuildStringTableEntry($Key,$value)
        Local $p_VS_String = DllStructCreate( _
                "short   wLength;" & _ ;Specifies the length, in bytes, of this String structure. 
                "short   wValueLength;" & _;Specifies the size, in words, of the Value member. 
                "short   wType;" & _   ;Specifies the type of data in the version resource. This member is 1 if the version resource contains text data and 0 if the version resource contains binary data. 
                "wchar szKey[" & StringLen($key) & "];" & _;Specifies an arbitrary Unicode string. The szKey member can be one or more of the following values. These values are guidelines only. 
                "char   Padding[" & Mod(6+StringLen($key),4) & "];" & _;Contains as many zero words as necessary to align the Value member on a 32-bit boundary. 
                "wchar   Value[" & StringLen($value) & "]" );Specifies a zero-terminated string. See the szKey member description for more information. 
                DllStructSetData($p_VS_String,"Wlength",DllStructGetSize($p_VS_String))
                DllStructSetData($p_VS_String,"wValueLength",StringLen($value))
                DllStructSetData($p_VS_String,"szKey",$key)
  ;~             DllStructSetData($p_VS_String,"szKey",StringRight($key,1),StringLen($key))
                DllStructSetData($p_VS_String,"Value",$value)
  ;~             DllStructSetData($p_VS_String,"Value",StringRight($value,1),StringLen($value))
        Return $p_VS_String
    EndFunc
I think this will fix it. The problem is that you have to do StringLen()+1 because it is a null terminated string and you have to give it that extra byte value to place the null char. If you don't, it is automatically truncated.

#Include <WinAPI.au3>
$dP = _Res_BuildStringTableEntry("Comments","Test comment")
$fh = _WinAPI_CreateFile("testpe.txt",1,4)
$bwritten=0
_WinAPI_WriteFile($fh,DllStructGetPtr($dp),DllStructGetSize($dp),$bwritten)
_WinAPI_CloseHandle($fh)

Func _Res_BuildStringTableEntry($Key,$value)
    Local $p_VS_String = DllStructCreate( _
            "short   wLength;" & _    ;Specifies the length, in bytes, of this String structure.
            "short   wValueLength;" & _;Specifies the size, in words, of the Value member.
            "short   wType;" & _         ;Specifies the type of data in the version resource. This member is 1 if the version resource contains text data and 0 if the version resource contains binary data.
            "wchar szKey[" & StringLen($key)+1 & "];" & _;Specifies an arbitrary Unicode string. The szKey member can be one or more of the following values. These values are guidelines only.
            "char   Padding[" & Mod(6+StringLen($key),4) & "];" & _ ;Contains as many zero words as necessary to align the Value member on a 32-bit boundary.
            "wchar   Value[" & StringLen($value)+1 & "]" );Specifies a zero-terminated string. See the szKey member description for more information.
            DllStructSetData($p_VS_String,"Wlength",DllStructGetSize($p_VS_String))
            DllStructSetData($p_VS_String,"wValueLength",StringLen($value)); TKM: Not sure if this one also has to have its length increased by one.  Doing so increases the value of the third byte by one
            DllStructSetData($p_VS_String,"szKey",$key)
;~             DllStructSetData($p_VS_String,"szKey",StringRight($key,1),StringLen($key))
            DllStructSetData($p_VS_String,"Value",$value)
;~             DllStructSetData($p_VS_String,"Value",StringRight($value,1),StringLen($value))
    Return $p_VS_String
EndFunc

I think this is what you were looking for. Let me know if it is still erroring.

Edit Added a comment to the code.

- The Kandie Man ;-)

Edited by The Kandie Man

"So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire

Link to comment
Share on other sites

  • Developers

I don't think we want a Null terminated string in this struct and don't understand why WHAR[] would need to be NULL terminated in a structure.

I have a feeling its a bug in AutoIt3. :D

here is a simple example that shows a null termination isn't needed:

Local $p_VS_String = DllStructCreate("wchar   szKey[8]" )
DllStructSetData($p_VS_String,"szKey","12345678")
ConsoleWrite('szKey = ' & DllStructGetData($p_VS_String,"szKey") & @crlf)
Local $p_VS_String = DllStructCreate("wchar   szKey[8]" )
DllStructSetData($p_VS_String,"szKey","12345678")
DllStructSetData($p_VS_String,"szKey","8",8)
ConsoleWrite('szKey = ' & DllStructGetData($p_VS_String,"szKey") & @crlf)
Edited by 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

I don't think we want a Null terminated string in this struct and don't understand why WHAR[] would need to be NULL terminated in a structure.

I have a feeling its a bug in AutoIt3. :D

here is a simple example that shows a null termination isn't needed:

Local $p_VS_String = DllStructCreate("wchar   szKey[8]" )
     DllStructSetData($p_VS_String,"szKey","12345678")
     ConsoleWrite('szKey = ' & DllStructGetData($p_VS_String,"szKey") & @crlf)
     Local $p_VS_String = DllStructCreate("wchar   szKey[8]" )
     DllStructSetData($p_VS_String,"szKey","12345678")
     DllStructSetData($p_VS_String,"szKey","8",8)
     ConsoleWrite('szKey = ' & DllStructGetData($p_VS_String,"szKey") & @crlf)
I see, but I thought the very defintion a wchar string is zero terminated.

From the FreeBasic help file:

The end of the string is marked by the character 0, so that character must never be part of a WString or the content will be truncated.

True, you can fill the last value of the string with a character, however, it would no longer fit the definition of a zero terminated wchar string.

- The Kandie Man ;-)

"So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire

Link to comment
Share on other sites

  • Developers

Just checked the autoit3 source and it is making room for a null termination, but still think it should be possible to store a string in a struct without a null at the end.

I agree for a "normal" string or wstring its required to have it null terminated because you are not using fixed lengths.

With structures that is supposed to be different and you define the length of each portion of the struct, or store in one of the "words" the lenght of the CHAR[] section of the structure.

Edited by 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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...