Serializing objects for persistent variables when AHK is reloaded

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
User avatar
JoeSchmoe
Posts: 129
Joined: 08 Dec 2014, 08:58

Serializing objects for persistent variables when AHK is reloaded

16 Jul 2021, 18:19

Hi, brilliant coders...

Is there a way to write multiple ClipboardAll objects to the same file and then read them back into different ClipboardAll buffers?

I'm trying to write a specialized clipboard manager that would store a library of named ClipboardAll objects that I could paste rapidly into documents (for my work, I have a library of graphics, formatted text, etc., that I need to use rapidly).

Somehow, I need AHK to "remember" the library of Clipboards when I reboot the computer or restart AHK. I'd like very much to put all of the ClipboardAlls into one file so I don't feel like I'm ruining my hard disk whenever I restart AHK.

Any tips?
lexikos
Posts: 9690
Joined: 30 Sep 2013, 04:07
Contact:

Re: Serializing objects for persistent variables when AHK is reloaded

16 Jul 2021, 20:28

ClipboardAll data is just a sequence of bytes. So how would you store multiple sequences of bytes within a file (another sequence of bytes), while still being able to tell them apart?

ClipboardAll data itself contains multiple sequences of bytes:
Binary data returned by the Data property (see above) internally consists of a four-byte format type, followed by a four-byte data-block size, followed by the data-block for that format. If the clipboard contained more than one format (which is almost always the case), these three items are repeated until all the formats are included. The data ends with a four-byte format type of 0.
Source: ClipboardAll - Syntax & Usage | AutoHotkey v2
You can use the same approach: write the ClipboardAll size followed by the data, repeat. When reading, read the size, allocate or resize a Buffer, read the data into the Buffer, then create a ClipboardAll object from it.

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: No registered users and 60 guests