News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

linked list problem

Started by ragdog, June 11, 2008, 11:12:40 AM

Previous topic - Next topic

ragdog

hi

i have a problem with my listbox

i add string with     invoke SendMessage, hList, LB_ADDSTRING,0,addr hName1
and a substring      invoke SendMessage, hList, LB_SETITEMDATA, eax, addr  hName2

all my strings and sub string is in the cfg.ini

if i get the substring of a entry in listbox  print only the last substring

invoke SendMessage,hList,LB_GETCURSEL, 0, 0
INVOKE SendMessage, hList, LB_GETITEMDATA,eax, 0
invoke MessageBox,hWnd,eax,0,MB_OK

can your help me

my source is added







[attachment deleted by admin]

MichaelW

The statement:

invoke SendMessage, hList, LB_SETITEMDATA, eax, addr hName2

Is setting the item data for each list item to the address of hName2, so the message box always displays the last string that was copied to hName2. The only simple fix I see is to use an array of strings and set the item data for each item to the address of the associated array element.
eschew obfuscation

ragdog

have you an idea to fix this problem?

thanks for you reply

MichaelW

This is not a good fix, but it appears to work:

GetMenuPath Proc USES ESI EDI hWnd:DWORD

LOCAL aptr:DWORD

    .data?
      hName1  db 256 dup(?)
      hTemp   db 256 dup(?)
      hName2  db 256 dup(?)
      array   db 9 dup(256 dup(?))
    .code

MOV aptr, OFFSET array

    ; 2048 = 8 * 256 and you have 9 items

    mov hTemp, 0
    invoke GetPrivateProfileString, CTEXT("Menu1"), NULL,0,\
                                    addr hTemp, 2048, addr szMenuCfg
    or eax, eax
    jnz @F
    jmp @Ret
   @@:
    xor esi, esi

    .while (byte ptr hTemp[esi] != 0)
      invoke GetPrivateProfileString, CTEXT ("Menu1"), addr hTemp[esi], 0,\
                                          addr hName1, 256, addr szMenuCfg
      invoke lstrcpy,addr hName2,addr hName1

      lea edx, hName1
      xor edi, edi
      push eax

      .while (eax)
        .if byte ptr[edx+edi] == ','
          mov byte ptr[edx+edi], 0
          .break
         .endif
         inc edi
          dec eax
      .endw
      lea edx, hName2
      xor ecx, ecx
      push eax
      .while (eax)
        .if byte ptr [edx+ecx] == ','
          mov byte ptr[edx+ecx], 0
          .break
        .endif
        inc  ecx
        dec eax
      .endw
      pop  eax
      sub eax, ecx
      add eax,3
      ;invoke lstrcpyn, addr  hName2, addr hName2[ecx+1], eax
     
INVOKE lstrcpyn, aptr, ADDR hName2[ECX+1], EAX
     
      invoke SendMessage, hList, LB_ADDSTRING,0,addr hName1     
      ;invoke SendMessage, hList, LB_SETITEMDATA, eax, addr hName2
     
INVOKE SendMessage, hList, LB_SETITEMDATA, EAX, aptr

      add esi, 9

ADD aptr, 256

    .endw
  @Ret:
    ret
GetMenuPath endp
eschew obfuscation

ragdog

thanks it works nice :U

   
is arry  limited or can I create an unlimited number of sub-entries?


greets
ragdog

MichaelW

I'm not sure what you mean by 'unlimited', but an array in the uninitialized data section should work OK up to a large number of elements, and it is easier to manage than allocated memory. I think any reasonable size string that is used only within the procedure should be LOCAL, for example:

LOCAL temp[2048]:BYTE
eschew obfuscation

jj2007

Quote from: MichaelW on June 11, 2008, 09:24:46 PM
I'm not sure what you mean by 'unlimited', but an array in the uninitialized data section should work OK up to a large number of elements, and it is easier to manage than allocated memory. I think any reasonable size string that is used only within the procedure should be LOCAL, for example:

LOCAL temp[2048]:BYTE


"reasonable size string" means in this context: keep (size of all) stack variables below page size, i.e. 4096 bytes; otherwise you need to increase the stack size.