Uriziel01 Posted January 28, 2008 Posted January 28, 2008 I want to read some data from some file my code looks like this: #Include <WinAPI.au3> $hFile="C:\boot.ini" Global $pBuffer $ile=256 $tBuffer = DllStructCreate("char Text[4096]"); Step 1 - Create the buffer. $pBuffer = DllStructGetPtr($tBuffer); Step 2 - Get a pointer to that buffer. $wynik=_WinAPI_ReadFile($hFile, $pBuffer, 256,$ile) MsgBox(0,"",$wynik) MsgBox(0,"",$pBuffer) $wynik returns me "False" $pBuffer returns me adress for the buffer And where is data from the readed file ? Why false ? HELP PLEASE And another question, can I read with thif function images to bianry code? If no, then with function allow me to do this ? I just want to read some picture to string and next convert this text,string,hex or whatever again to picture.
Richard Robertson Posted January 28, 2008 Posted January 28, 2008 Yes, $pBuffer is the pointer to the buffer. You use DllStructGetData on your $tBuffer.
Uriziel01 Posted January 28, 2008 Author Posted January 28, 2008 Ok nevermind, i maked it with this code: #include <File.au3> $file = FileOpen ( "C:\boot.jpg", 16 ) If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf $size=FileGetSize ("C:\boot.jpg") MsgBox(0,"",$size) $chars = FileRead($file, $size) MsgBox(0, "Char read:", $chars) $tresc=$chars FileClose($file) _FileCreate( "C:\bootnowy.jpg") Sleep(50) $file2 = FileOpen ( "C:\bootnowy.jpg", 16 ) If $file2 = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf FileWrite("C:\bootnowy.jpg", $tresc) FileClose($file2)
GaryFrost Posted January 28, 2008 Posted January 28, 2008 In answer to your question: #include <WinAPI.au3> Global Const $OF_READ = 0x00000000 Global Const $OFS_MAXPATHNAME = 128 Global Const $tag_OFSTRUCT = "byte cBytes;byte fFixedDisk;long nErrCode;long Reserved1;long Reserved2;char szPathName[" & $OFS_MAXPATHNAME & "]" _Main() Func _Main() Local $t_OFSTRUCT = DllStructCreate($tag_OFSTRUCT) Local $hFile, $ile, $tBuffer, $pBuffer, $wynik DllStructSetData($t_OFSTRUCT, "cBytes", DllStructGetSize($t_OFSTRUCT)) $hFile = _WinAPI_OpenFile("C:\boot.ini", $t_OFSTRUCT, $OF_READ) ConsoleWrite($hFile & @LF) Global $pBuffer $ile = 0 $tBuffer = DllStructCreate("char Text[4096]"); Step 1 - Create the buffer. $pBuffer = DllStructGetPtr($tBuffer); Step 2 - Get a pointer to that buffer. $wynik = _WinAPI_ReadFile($hFile, $pBuffer, 256, $ile) ConsoleWrite($wynik & @LF) ConsoleWrite(DllStructGetData($tBuffer, "Text") & @LF) ConsoleWrite($ile & @LF) ConsoleWrite(_WinAPI_CloseHandle($hFile) & @LF) EndFunc ;==>_Main Func _WinAPI_OpenFile($sFile, ByRef $tOFSTRUCT, $iStyle) $pOFSTRUCT = DllStructGetPtr($tOFSTRUCT) $iResult = DllCall("kernel32.dll", "hwnd", "OpenFile", "str", $sFile, "ptr", $pOFSTRUCT, "uint", $iStyle) If @error Then Return SetError(-1, -1, 0) Return $iResult[0] EndFunc ;==>_WinAPI_OpenFile SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference.
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