I have a structure:



MRUSTUFF STRUCT
DisplayName BYTE 50 dup (?)
MRUPath BYTE MAX_PATH dup (?)
ParseType DWORD ?
SectionName BYTE 20 dup (?)
ValueName BYTE 20 dup (?)
ValueBase DWORD ? (0)
Count BYTE 20 dup (?)
DataType BYTE 2 dup (?)
ExeName BYTE 20 dup (?)
MRUSTUFF ends

MRUInfo MRUSTUFF <>


I want to read in a file line by line and parse it and fill each structure item in (done).
I associate the structure with a LVITEM.lParam <-problem sort of - when I get the structure from a selected LVITEM.lParam, it always shows the structure for the last listview item inserted, which makes sense to me now because the memory address of the struct is still filled with the last info I filled it with. Question is, how can I create a new structure for each listview item so the data is different for each listview item.lParam and when I get a selected LVITEM the structure holds the correct info?

I parse a file and fill the structure and listview with the following code:
http://www.asmcommunity.net/board/index.php?topic=8793

I want to create a new structure in memory each time I jump back to the DisplayName label


then when I do:


[snip]
mov iStart, -1
@@:
invoke SendMessage, hListView2, LVM_GETNEXTITEM, iStart, LVNI_ALL or LVNI_SELECTED
cmp eax, NOMORE
je Done
mov iStart, eax

; Get select listview items info
mov lvi.imask, LVIF_PARAM; or LVIF_TEXT
push iStart
pop lvi.iItem
mov lvi.iSubItem, 0
push MRUInfo
pop lvi.lParam ;, offset MRUInfo
invoke SendMessage, hListView2, LVM_GETITEM, 0, addr lvi
PrintString MRUInfo.DisplayName
jmp @B

it always shows the structure for the last item inserted.

Did I make sense...
Posted on 2002-11-12 20:01:14 by Gunner

Did I make sense...


You explained enough that what you wanted could be figured out :grin:

Your MRUInfo structure is static. IE there is only one instance of it in
your program. As such (as you noticed) it does not matter how many
items are in your List View. Each will still be pointing to the same
structure which isnt what you need.

What you need to do is when a new List View item needs to be filled,
create the structure dynamically in memory with HeapAlloc or such. This
will require casting of a register or some other method to access it and
fill in the fields. After the fields are entered, point LVITEM.lParam to the
address in memory where it was created.

This allows each List View item to have its own structure.

When you remove a List View item, dont forget to free the memory :alright:
Posted on 2002-11-13 09:08:30 by Graebel
Can anyone give me a little direction? So far I gotten as far as HeapAlloc passing the heap handle returned from GetProcessHeap and sizeof MRUInfo for the size and gotten a pointer to a memory block. How do I use this memory block for a dynamically created MRUInfo structure so I can fill in the structure fields? I did a search for casting and most said basically the same thing for what I want to do so I have tried: ( I added another field to my MRUInfo structure to save the memory pointer so I can free it later.

<SNIP>
DisplayName:
invoke HeapAlloc, hHeap, HEAP_ZERO_MEMORY, s izeof MRUInfo
PrintDec eax
mov edx, eax

mov .MRUInfo.MemPtr, eax
mov edi, .MRUInfo.DisplayName
@@:
<SNIP>

But everytime I try to build I get the following error:
error A2166: structure field expected

Maybe I misunderstood the posts I read, direct me please :-)

I even tried lea instead of mov but still gotten the same error.
I am *VERY* confused
Posted on 2002-11-13 23:07:24 by Gunner

mov edx, eax

mov .MRUInfo.MemPtr, eax
mov edi, .MRUInfo.DisplayName
@@:
<SNIP>


I think thats pretty close. You did not cast the register however...
At least not properly. Try something like this:

move edx, eax

assume edx:ptr MRUInfo <<-- cast the register
mov .MRUInfo.MemPtr, eax
mov edi, .MRUInfo.DisplayName
@@:

When you dont need the cast any more use:
assume edx:NOTHING
Posted on 2002-11-14 09:53:42 by Graebel
Thank you for the help, but it is still not working, I now get the following error when building:
GRiFLE.asm(625) : error A2175: invalid qualified type : MRUInfo
GRiFLE.asm(625) : error A2158: type is wrong size for register

line 625 is the assume ebx: ptr MRUInfo
arrrrgh...
Posted on 2002-11-14 15:54:03 by Gunner
Argh, did I say that? Man im getting senile...

Its
assume edx:ptr MRUSTUFF
Posted on 2002-11-14 17:23:10 by Graebel
Awesome!!! Finally compiled! Thank you Graebel. If you are in my neck of the woods, I will buy you a drink ;)
Time to have some fun! Now I have to read up on this.
Posted on 2002-11-14 18:17:08 by Gunner