I am using a CAD Library via DllCall().
I am loading a list of files, using a function.
I have to save to memory, each of these files, so I can access them through selection on a ListView.
Spoiler
Each file needs to be saved to memory of a specific size (using VarSetCapacity) and I need to be able to access that specific memory address later, (upon selection in the ListView) so I am storing that (unique?) memory address in v.ptrBelow is an (abridged) function to load the files.
Code: Select all
LoadFileList()
{
for k, v in oList
{
idx := A_Index
szFilePath := v.FilePath
hDrw := lcCreateDrawing()
lcDrwLoad(hDrw,szFilePath,0)
bytes := lcDrwSaveMem(hDrw,0,0)
VarSetCapacity(Mem%idx%,bytes,0)
lcDrwSaveMem(hDrw,&Mem%idx%,bytes)
v.ptr := &Mem%idx%
}
return
}
Code: Select all
;i: index of Listview, hence file
OnChange(i)
{
global oList, hLcWnd
mem := oList[i].ptr
hDrw := lcCreateDrawing()
lcDrwLoadMem(hDrw,mem,hLcWnd)
return
}
[ie. subroutines, not functions]. I'd like to clean up the code, so that I have far fewer global variables.
Problem is, I don't know to then correctly define, store, these dynamically created memory addresses mem%idx%
What I have tried:
! Assume-global mode:
> Works. (But creates individual global variables!)
! store the memory in the object oTSV.
> I don't believe this can be done. I don't believe VarSetCapacity() takes an object reference as a parameter?
! define the memory mem%idx%, dynamically, as a global, inside the function: like global mem%idx%
> this fails. "The following variable name contains an illegal character"
Is there another way I should be doing this?
- a.) If these DXF files were represented as strings (not blobs of binary memory) I'd store them in the object oList, as text, and that would be my desired solution.
That's a request I am making for the developer.
However, what's the best way to store a bunch of memory addresses like this, in AHK?
- b.) Interestingly, when I write the memory addresses in assume-global mode, my function onChange() can actually read the (global) memory addresses, as stored by oList.ptr
I figure this is because the CAD library DLL, operates on the memory address (As I am passing pointers to memory addresses.)
Obviously then, these memory addresses need to be... global? But is there a way to store them, more protected? A little more OOP? Maybe even... not showing up in my ListVars?