erifash Posted October 26, 2005 Posted October 26, 2005 (edited) Hello, I am trying to recreate Larry's binary read/write functions in two functions: _BinRead() and _BinWrite(). They use hex formatted strings like Larry's, but are not comma seperated. The binary read function works fine, the only problem is with the binary write function. For some reason it will create a 0-byte file and not write data to it . The code looks fine to me but it doesn't work, so can someone else please take a look at it? Func _BinWrite( $sFile, $sHex ) Local $GENERIC_WRITE = 0x40000000, $OPEN_ALWAYS = 4, $FILE_ATTRIBUTE_NORMAL = 0x00000080 Local $c = -1 Local $hDLL = DllOpen("kernel32.dll") Local $iBytes = StringLen($sHex) / 2 Local $hFile = DllCall($hDLL, "hwnd", "CreateFile", "str", $sFile, "long", $GENERIC_WRITE, "long", 0, "ptr", 0, "long", $OPEN_ALWAYS, "long", $FILE_ATTRIBUTE_NORMAL, "long", 0) Local $AFW_ptr = DllStructCreate("byte[" & $iBytes & "]") For $i = 1 to $iBytes $c += 2 DllStructSetData($AFW_ptr, 1, Dec(StringMid($sHex, $c, 2)), $i) Next Local $AFW_r = DllCall($hDLL, "int", "WriteFile", "hwnd", $hFile, "ptr", DllStructGetPtr($AFW_ptr), "long", $iBytes, "long_ptr", 0, "ptr", 0) DllStructDelete($AFW_ptr) DllCall($hDLL, "int", "CloseHandle", "hwnd", $hFile[0]) DllClose($hDLL) SetError($AFW_r[0]) Return $AFW_r[4] EndFunc;Example useage: _BinWrite("num.txt", "3132333435") ;Writes the string "12345" to num.txt Thanks. Edited October 26, 2005 by erifash My UDFs:_FilePrint() | _ProcessGetName() | _Degree() and _Radian()My Scripts:Drive Lock - Computer Lock Using a Flash DriveAU3Chat - Simple Multiuser TCP ChatroomStringChunk - Split a String Into Equal PartsAutoProxy - Custom Webserver
Valuater Posted October 26, 2005 Posted October 26, 2005 is this correct Local $sHex = "3132333435" Local $iBytes = StringLen($sHex) / 2 MsgBox(0,"Test", $iBytes) message box returns the number 5 8)
erifash Posted October 26, 2005 Author Posted October 26, 2005 (edited) Yes, it finds out how many hex digits to set into struct $AFW_ptr. 2 hex digits = 1 byte. Edited October 26, 2005 by erifash My UDFs:_FilePrint() | _ProcessGetName() | _Degree() and _Radian()My Scripts:Drive Lock - Computer Lock Using a Flash DriveAU3Chat - Simple Multiuser TCP ChatroomStringChunk - Split a String Into Equal PartsAutoProxy - Custom Webserver
w0uter Posted October 26, 2005 Posted October 26, 2005 $hFile should be $hFile[0] My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll
erifash Posted October 26, 2005 Author Posted October 26, 2005 $hFile should be $hFile[0]Thank you very much! It's amazing how a little error can throw off a whole script! My UDFs:_FilePrint() | _ProcessGetName() | _Degree() and _Radian()My Scripts:Drive Lock - Computer Lock Using a Flash DriveAU3Chat - Simple Multiuser TCP ChatroomStringChunk - Split a String Into Equal PartsAutoProxy - Custom Webserver
w0uter Posted October 26, 2005 Posted October 26, 2005 post them if they are done. i would like them My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll
erifash Posted October 26, 2005 Author Posted October 26, 2005 post them if they are done. i would like them Okies, post is here:http://www.autoitscript.com/forum/index.ph...ndpost&p=119715 My UDFs:_FilePrint() | _ProcessGetName() | _Degree() and _Radian()My Scripts:Drive Lock - Computer Lock Using a Flash DriveAU3Chat - Simple Multiuser TCP ChatroomStringChunk - Split a String Into Equal PartsAutoProxy - Custom Webserver
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