AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Binary file reading and writing
Goto page Previous  1, 2
 
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
kiu



Joined: 18 Dec 2005
Posts: 234
Location: Italy - Galatro(RC)

PostPosted: Thu Feb 02, 2006 12:49 pm    Post subject: Reply with quote

if someone is interested:
http://www.autohotkey.net/~kiu/kiu-clipsave.exe
use it to save an image on clipboard in png and jpg.When launched it save the image in image.jpg and image.png
_________________
____________________
______________________
kiu - www.romeosa.com
Back to top
View user's profile Send private message Visit poster's website
PhiLho



Joined: 27 Dec 2005
Posts: 6836
Location: France (near Paris)

PostPosted: Fri Mar 17, 2006 10:28 am    Post subject: Reply with quote

If someone is interested: Smile
SetClipboardData is a pure AutoHotkey (with DllCall) solution to this problem.
_________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")
Back to top
View user's profile Send private message Visit poster's website
madewokherd



Joined: 07 Jul 2007
Posts: 5

PostPosted: Wed Aug 08, 2007 4:51 pm    Post subject: Reply with quote

PhiLho: This is perfect for a problem I have, but the project I'd like to use it in is open source (GPL). You haven't given a license, and I'd like to avoid any potential legal problems. I would expect that since you've posted your source code for all to see, you are ok with this kind of use. Would you give it a license compatible with the GPL so that I can use it?
_________________
jabber: madewokherd@gmail.com
Back to top
View user's profile Send private message Send e-mail AIM Address MSN Messenger
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10716

PostPosted: Wed Aug 08, 2007 4:58 pm    Post subject: Reply with quote

PhiLho is unavailable for a few weeks. Hopefully he'll notice your post the next time he gets a chance to visit the forum.
Back to top
View user's profile Send private message Send e-mail
Laszlo



Joined: 14 Feb 2005
Posts: 4710
Location: Boulder, CO

PostPosted: Wed Aug 08, 2007 5:10 pm    Post subject: Reply with quote

If you use my original version, it is absolutely free. You can even sell the script (not AHK) for profit, if you want. However, with the recent AHK updates, all of these functions can be greatly simplified and sped up.
Back to top
View user's profile Send private message
madewokherd



Joined: 07 Jul 2007
Posts: 5

PostPosted: Wed Aug 08, 2007 5:41 pm    Post subject: Reply with quote

Thanks.

On looking more carefully, I think I misunderstood PhiLho's script, and it doesn't provide something I need (it may not be possible, and certainly isn't trivial). I guess I'm better off reading/writing the whole file as a variable. :/
_________________
jabber: madewokherd@gmail.com
Back to top
View user's profile Send private message Send e-mail AIM Address MSN Messenger
apocalypse r
Guest





PostPosted: Tue Apr 08, 2008 1:16 am    Post subject: more functions + wish list Reply with quote

these were adapted from the functions in binreadwrite.ahk provided by PhilLo, and were designed for writing or reading just once; they open and close the handles automatically.

readfiletovar(filename, vartowritecontentsoffileto, bytestoread, startlocation, offset)
startlocation can be -1 for dont move, 0 for start at beginning, 1 for current location, 2 for end of file, and offset is the number of bytes to the left of startlocation to begin reading from (which can be negative). 0 stands for at specified start location

Code:
readfiletovar(_filename, byref _data, _byteNB = 0, _MoveMethod = -1, _offset = 0)
{
  local handle, granted, read
  handle := Dllcall("CreateFile", "Str", _filename, "UInt", 0x80000000, "UInt", 3, "UInt", 0, "UInt", 3, "UInt", 0, "UInt", 0)
  if (handle = INVALID_HANDLE_VALUE or handle = 0)
  {
    errorlevel = -1
    return, -1
  }
  if (_moveMethod != -1)
  {
    _offset := DllCall("SetFilePointer", "UInt", handle, "Int", _offset, "UInt", 0, "UInt", _moveMethod)
    if (_offset = -1)
    {
      ErrorLevel = -2
      dllcall("CloseHandle", "UInt", handle)
      return -2
    }
  }
  if (_byteNB = 0)
  {
    _byteNB := Dllcall("GetFileSize", "UInt", handle, "UInt", 0)
    if (_byteNB = 0xFFFFFFFF)
    {
      errorlevel = -3
      dllcall("CloseHandle", "UInt", handle)
      return -3
    }
  }
  granted := varsetcapacity(_data, _byteNB, 0)
  if (granted < _byteNB)
  {
    errorlevel := %granted%
    dllcall("CloseHandle", "UInt", handle)
    return -4
  }
  if (dllcall("ReadFile", "UInt", handle, "Str", _data, "UInt", _byteNb, "UInt *", read, "UInt", 0) = 0)
  {
    errorlevel := -5
    dllcall("CloseHandle", "UInt", handle)
    return -5
  }
  dllcall("CloseHandle", "UInt", handle)
  return read
}


writevartofile(filename, varcontainingdatatowritetofile, bytestowrite, startingposition, offset)
startlocation can be -1 for dont move, 0 for start at beginning, 1 for current location, 2 for end of file, and offset is the number of bytes to the left of startlocation to begin reading from (which can be negative). 0 stands for at specified start location

Code:
writevartofile(_filename, byref _data, _byteNB, _movemethod, _offset)
{
  local handle, datasize, written
  handle := dllcall("CreateFile", "Str", _filename, "UInt", 0x40000000, "UInt", 3, "UInt", 0, "UInt", 4, "UInt", 0, "UInt", 0)
  if (handle = INVALID_HANDLE_VALUE or handle = -1)
  {
    errorlevel := -1
    return, -1
  }
  if (_moveMethod != -1)
  {
    _offset := DllCall("SetFilePointer", "UInt", handle, "Int", _offset, "UInt", 0, "UInt", _moveMethod)
    if (_offset = -1)
    {
      errorLevel = -2
      dllcall("CloseHandle", "UInt", handle)
      return -2
    }
  }
  datasize := varsetcapacity(_data)
  if (_byteNB < 1 or byteNB > datasize)
    _byteNB := datasize
  if (dllcall("WriteFile", "UInt", handle, "Str", _data, "UInt", _byteNb, "UInt *", written, "UInt", 0) = 0 or written < _byteNB)
  {
    errorlevel := -3
    dllcall("CloseHandle", "UInt", handle)
    return -3
  }
  dllcall("CloseHandle", "UInt", handle)
  return written
}
Back to top
WankaUSR



Joined: 14 Aug 2007
Posts: 86

PostPosted: Sat Apr 12, 2008 11:51 am    Post subject: Reply with quote

can anyone please help me with a gui for this because i don't quite understand how to use functions
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group