JScript Posted September 29, 2011 Share Posted September 29, 2011 I've put the script in code tag and I lost access to the previous topic! Can someone explain me how I do this?Here's the code: #Include <Memory.au3>$bVar = StringToBinary("JScript")$TcpRxLen = 256$tMemB = DllStructCreate("byte[" & $TcpRxLen & "]") ; Create structDllStructSetData($tMemB, 1, $bVar)$bOld = DllStructGetData($tMemB, 1)DllStructSetData($tMemB, 1, $bOld & StringToBinary(" - João Carlos."))MsgBox(4096, "Teste", BinaryToString(DllStructGetData($tMemB, 1))) Thanks, João Carlos. http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!) Somewhere Out ThereJames Ingram Download Dropbox - Simplify your life!Your virtual HD wherever you go, anywhere! Link to comment Share on other sites More sharing options...
Ramzes Posted September 29, 2011 Share Posted September 29, 2011 I don't know what do you mean by merge binary parts but I hope it will useful: Easier way (not using DLLStructure): $Name = StringToBinary("Ramzes") $String = StringToBinary("abcdef") $Val1 = StringToBinary("jscript") MsgBox(32, "", BinaryToString($Name) & @CR & BinaryToString($String) & @CR & BinaryToString($Val1)) Using DLLStructure : Global $Array[4] = ["black", "red", "white", "yellow"] $Str = "" For $i = 0 To UBound($Array) - 1 $Str &= "byte[" & StringLen($Array[$i]) & "];" Next $Str = DllStructCreate($Str) For $i = 0 To UBound($Array) - 1 DllStructSetData($Str, $i + 1, $Array[$i]) Next MsgBox(32, "", BinaryToString(DllStructGetData($Str, 4))) Sorry for my bad English but nobody is perfect. [font=arial, helvetica, sans-serif]Ramzes[/font] Link to comment Share on other sites More sharing options...
Yashied Posted September 29, 2011 Share Posted September 29, 2011 $b1 = StringToBinary('JScript') $b2 = StringToBinary(' - Joao Carlos.') $b3 = $b1 + $b2 ConsoleWrite($b1 & @CR) ConsoleWrite($b2 & @CR) ConsoleWrite($b3 & @CR) ConsoleWrite(BinaryToString($b3) & @CR) mLipok 1 My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More... Link to comment Share on other sites More sharing options...
JScript Posted September 29, 2011 Author Share Posted September 29, 2011 (edited) @Ramzes, Works as It should! Thanks! @Yashied, Great, but works with binary files jpg images? João Carlos. Edited September 29, 2011 by jscript http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!) Somewhere Out ThereJames Ingram Download Dropbox - Simplify your life!Your virtual HD wherever you go, anywhere! Link to comment Share on other sites More sharing options...
Ramzes Posted September 29, 2011 Share Posted September 29, 2011 @jscript Do you think about read image bytes and convert them to binary? $Read = StringToBinary(FileRead("imaget.jpg")) ConsoleWrite($Read & @CR) Sorry for my bad English but nobody is perfect. [font=arial, helvetica, sans-serif]Ramzes[/font] Link to comment Share on other sites More sharing options...
JScript Posted September 29, 2011 Author Share Posted September 29, 2011 @Ramzes, No, assuming that I already have an image being transmitted over the network in binary format, on the other computer I'll have to join the binary parts to compose the picture again, but I was making use of Hex ($ bBmp) to join parties. João Carlos. http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!) Somewhere Out ThereJames Ingram Download Dropbox - Simplify your life!Your virtual HD wherever you go, anywhere! Link to comment Share on other sites More sharing options...
martin Posted September 29, 2011 Share Posted September 29, 2011 Wouldn't it be easier to open the files in binary mode and then you wouldn't need to convert? Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
JScript Posted September 29, 2011 Author Share Posted September 29, 2011 Wouldn't it be easier to open the files in binary mode and then you wouldn't need to convert?OK, I do not want to convert, I want to know how to join the parts that come on the other computer to compose the picture again. The only way I found was using:;--------------------------------------------------------------------------------- If IsBinary($vRecv) Then ; The data received is bitmap variable. $bBmp &= Hex($vRecv) ContinueLoopEndIf;--------------------------------------------------------------------------------- In this way: $bBmp += $vRecv, not work! João Carlos. http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!) Somewhere Out ThereJames Ingram Download Dropbox - Simplify your life!Your virtual HD wherever you go, anywhere! Link to comment Share on other sites More sharing options...
Yashied Posted September 29, 2011 Share Posted September 29, 2011 $tBuffer = DllStructCreate('byte[8388608]') ; 8 MB $pBuffer = DllStructGetPtr($tBuffer) $iOffset = 0 ... If IsBinary($vRecv) Then DllStructSetData(DllStructCreate('byte[' & BinaryLen($vRecv) & ']', $pBuffer + $iOffset), 1, $vRecv) $iOffset += BinaryLen($vRecv) ContinueLoop EndIf ... $bBmp = DllStructGetData(DllStructCreate('byte[' & $iOffset & ']', $pBuffer), 1) Wiliat87 1 My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More... Link to comment Share on other sites More sharing options...
JScript Posted September 29, 2011 Author Share Posted September 29, 2011 (edited) @Yashied, Your code is more faster than this?: If IsBinary($vRecv) Then ; The data received is bitmap variable. $bBmp &= Hex($vRecv) ContinueLoop EndIf João Carlos. Edited September 29, 2011 by jscript http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!) Somewhere Out ThereJames Ingram Download Dropbox - Simplify your life!Your virtual HD wherever you go, anywhere! Link to comment Share on other sites More sharing options...
martin Posted September 29, 2011 Share Posted September 29, 2011 OK, I do not want to convert, I want to know how to join the parts that come on the other computer to compose the picture again. The only way I found was using:;---------------------------------------------------------------------------------If IsBinary($vRecv) Then ; The data received is bitmap variable. $bBmp &= Hex($vRecv) ContinueLoopEndIf;--------------------------------------------------------------------------------- In this way: $bBmp += $vRecv, not work! João Carlos. True, but since (I thought) you only want to create the file why not just write the $vRecv to the file using FileWrite which will append the data and not worry about adding things together or clever complicated concatenations. Then when everything is written you have recreated the original file.So you read some binary data, send the binary data, receive binary data and write the binary data. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
JScript Posted September 29, 2011 Author Share Posted September 29, 2011 True, but since (I thought) you only want to create the file why not just write the $vRecv to the file using FileWrite which will append the data and not worry about adding things together or clever complicated concatenations. Then when everything is written you have recreated the original file.So you read some binary data, send the binary data, receive binary data and write the binary data.That's the thing: I will not write to disk but in memory! João Carlos. http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!) Somewhere Out ThereJames Ingram Download Dropbox - Simplify your life!Your virtual HD wherever you go, anywhere! Link to comment Share on other sites More sharing options...
TheBrainiac Posted November 27, 2011 Share Posted November 27, 2011 And thus, the thread died. I have the same problem - I want to merge two binary variables into one, but AutoIt keeps treating it as a string. I'll tell you when I figure out how to do it (efficiently)! Link to comment Share on other sites More sharing options...
MazeM Posted June 14, 2017 Share Posted June 14, 2017 (edited) Resurrection...that's how I do it: Create a first struct that fits all binary parts you want to merge. Get a pointer to that struct Repeat this for every binary: Create a new struct that fits one binary in it, using the pointer (instead of allocating own memory) Increase the pointer by the binary size Write the binary to each struct Read the first struct Local $data1_size = 6 Local $data2_size = 6 Local $data_struct = DllStructCreate("char data[" & $data1_size + $data2_size & "]") Local $data_lp = DllStructGetPtr($data_struct) Local $data1_struct = DllStructCreate("char data[" & $data1_size & "]", $data_lp) $data_lp += $data1_size Local $data2_struct = DllStructCreate("char data[" & $data2_size & "]", $data_lp) DllStructSetData($data1_struct, "data", "Hillo ") DllStructSetData($data2_struct, "data", "World!") DllStructSetData($data1_struct, "data", "e", 2) ConsoleWrite(DllStructGetData($data_struct, "data")) You can avoid the pointer increment if you have a predefined number of binary variables to merge, e.g. two: Local $data1_size = 6 Local $data2_size = 6 Local $data12_struct = DllStructCreate("char data1[" & $data1_size & "];char data2[" & $data1_size & "]") Local $data12_lp = DllStructGetPtr($data12_struct) Local $data_struct = DllStructCreate("char data[" & $data1_size + $data2_size & "]", $data12_lp) DllStructSetData($data12_struct, "data1", "Hillo ") DllStructSetData($data12_struct, "data2", "World!") DllStructSetData($data12_struct, "data1", "e", 2) ConsoleWrite(DllStructGetData($data_struct, "data")) As shown in the examples it works with strings, too. Maze Edited June 14, 2017 by MazeM typo 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