UDT Tricks pt2
Date: 09.12.16 - 7:52pm
In a previous article we talked about how the VB6 runtime includes a cool feature that allows it to serialize and deseralize complex UDT structures to disk. (Primer on UDTs here)
In memory a string or array element would be pointers...so you cant use copymemory to grab them and transfer them. By dumping them to disk, the data will be packed appropriately and can be reloaded at any time fully configured.
So I have always had a thought in the back of my mind..this is so cool, but it feels sloppy to have to use all these temp files if you wanted to transfer a udt. Is there a way to do it without the temp files? Could I redirect it to memory or a different type of file handle? A socket?
I played with it some this last weekend and came up with a solution using API hooks on ReadFile, WriteFile, CreateFileA, CloseHandle, and GetFileType. The hook lib is done in C, with VB6 hook implementations.
It might be a little heavy handed, but it was an experiment. Time will tell if it has any practical value or is just a novelty. It doesnt add that much code, but could impact stability.
Below is a sample: (full source here)
Another implementation VB6 pipe-based UDT-serializing/deserializing InMemory by Schmidt was also pointed out to me. It has the added benefit of being lite weight with no external dependencies or hooking. Down side it does use fragmented logic with event call backs. (local copy)
It might not be obvious, but the reason we both wanted the Get/Put statements to be outside of the library code is because VB has restrictions about how UDTs can be passed as variants so its best to let the caller handle them in their own scope for flexibility.