Jump to content

MsgBox miss output if the binary has many zeros at ending...


Recommended Posts

Hi guys,

  The code as below:

#include <WinAPI.au3>

Local $iRead = 0
$hFile = _WinAPI_CreateFile("test.txt", 2, 2); the file content is :"just unicode."
$tBuffer = DllStructCreate("byte text[1000]")
;$tBuffer = DllStructCreate("char text[1000]")
$pBuffer = DllStructGetPtr($tBuffer, "text")
_WinAPI_ReadFile($hFile, $pBuffer, 1000, $iRead)

;you can see that has many zeros...
MsgBox(4096, "", DllStructGetData($tBuffer, "text") & @CRLF & _
        StringToBinary("just unicode.") & @CRLF)

$s = BinaryToString(DllStructGetData($tBuffer, "text"))

; In here, just output one string "just testing", no StringToBinary("just unicode.") & @CRLF
MsgBox(4096, "", $s & @CRLF & _
    StringToBinary("just unicode.") & @CRLF); it's missed..

I found the last MsgBox output only string, not as my expectation result. So why? Thanks for your help advance.

Link to comment
Share on other sites

  • Moderators

oceanwaves,

Windows regards Chr(0) as an "end of string" marker. As the MsgBox function calls the Windows API to display the required text, Windows truncates the test at the first Chr(0) it finds. Simple really. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

&nbsp;

oceanwaves,

Windows regards Chr(0) as an "end of string" marker. As the MsgBox function calls the Windows API to display the required text, Windows truncates the test at the first Chr(0) it finds. Simple really. :)

M23

&nbsp;

Thanks for your reply. It means I have to remove these zeros by manual. Because when I try to compare (BinaryToString($OriginalString)-->normal ver) with (BinaryToString($s)--->Includes many zeros ver), system thinks the 2 strings are different, but actually they are the same after translated from bingary to string, at least from human views....

Link to comment
Share on other sites

  • Moderators

oceanwaves,

It really helps if you post the code you use - just saying "system thinks the 2 strings are different" when I cannot tell which two strings you are comparing is not much of a clue. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

oceanwaves,

It really helps if you post the code you use - just saying "system thinks the 2 strings are different" when I cannot tell which two strings you are comparing is not much of a clue. ;)

M23

HI M23,

  Appreciate your nice help. :sorcerer: . The code as below:

#include <WinAPI.au3>
Local $iRead = 0
$hFile = _WinAPI_CreateFile("test.txt", 2, 2); the file content is :"just unicode."
$tBuffer = DllStructCreate("byte text[1000]")
;$tBuffer = DllStructCreate("char text[1000]")
$pBuffer = DllStructGetPtr($tBuffer, "text")
_WinAPI_ReadFile($hFile, $pBuffer, 1000, $iRead) ;you can see that has many zeros...
MsgBox(4096, "Binary", DllStructGetData($tBuffer, "text") & @CRLF & _
        StringToBinary("just unicode.", 1) & @CRLF)
$s = BinaryToString(DllStructGetData($tBuffer, "text"))
MsgBox(4096, "$s", $s)
If $s == "just unicode." Then MsgBox(4096, "", "equal!!!"); Never pop up, why?

The last statement will not be performed. Yes, because they have different "Binary", maybe someone will say. But after using BinaryToString funcion, they looks like be same. So for the string comparison, Autoit actual using binary caomparison?

Link to comment
Share on other sites

  • Moderators

oceanwaves,

The 2 strings are not identical. The string $s is as many bytes as there are in the buffer converted to ASCII - the literal string to which you compare it is much shorter. Try adding this at the end of that script and see what you get: ;)

$iLen_1 = StringLen($s)
$iLen_2 = StringLen("just unicode.")
ConsoleWrite($iLen_1 & " - " & $iLen_2 & @CRLF)
So there is no chance that the comparison will ever be True. ;)

What exactly are you trying to do with all this anyway? :huh:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

oceanwaves,

The 2 strings are not identical. The string $s is as many bytes as there are in the buffer converted to ASCII - the literal string to which you compare it is much shorter. Try adding this at the end of that script and see what you get: ;)

$iLen_1 = StringLen($s)
$iLen_2 = StringLen("just unicode.")
ConsoleWrite($iLen_1 & " - " & $iLen_2 & @CRLF)
So there is no chance that the comparison will ever be True. ;)

What exactly are you trying to do with all this anyway? :huh:

M23

 

Hi M23,

  Last week, I tried to understand Windows named pipes, and refer to example script under Autoit3/examples/GUI/advance. During the modify and debug example script, I found this problem..I supporse I received some message from clinet and maybe I need compare with something then decide what do we do...balabalabala....

   However, I really appreciate your answers  with patience. Now I know I need remove the zero by myself.  :rambo: 

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...