oceanwaves Posted December 23, 2013 Share Posted December 23, 2013 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 More sharing options...
Moderators Melba23 Posted December 23, 2013 Moderators Share Posted December 23, 2013 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 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
oceanwaves Posted December 23, 2013 Author Share Posted December 23, 2013 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 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 More sharing options...
Moderators Melba23 Posted December 23, 2013 Moderators Share Posted December 23, 2013 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 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
oceanwaves Posted December 23, 2013 Author Share Posted December 23, 2013 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. . 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 More sharing options...
Moderators Melba23 Posted December 23, 2013 Moderators Share Posted December 23, 2013 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? M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
oceanwaves Posted December 23, 2013 Author Share Posted December 23, 2013 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? 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. 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