News:

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

LVSortProc

Started by six_L, August 06, 2009, 09:43:29 AM

Previous topic - Next topic

six_L

LVSortProc proc uses ebx edi esi lParam1,lParam2,lParamSort
LOCAL ItemData1:LV_ITEM
LOCAL ItemData2:LV_ITEM
LOCAL Tbuff1[256]:BYTE
LOCAL Tbuff2[256]:BYTE

; lParamSort pointer to LVSORT structure
mov edi,lParamSort
mov ebx,[edi.LVSORT].column
mov esi,[edi.LVSORT].handle

mov eax,lParam1
mov ItemData1.iItem,eax
mov ItemData1.iSubItem,ebx
mov ItemData1.imask,LVIF_TEXT + LVIF_PARAM
lea eax,Tbuff1
mov ItemData1.pszText,eax
mov ItemData1.cchTextMax,255
invoke SendMessage,esi,LVM_GETITEM,0,ADDR ItemData1

mov eax,lParam2
mov ItemData2.iItem,eax
mov ItemData2.iSubItem,ebx
mov ItemData2.imask,LVIF_TEXT + LVIF_PARAM
lea eax,Tbuff2
mov ItemData2.pszText,eax
mov ItemData2.cchTextMax,255
invoke SendMessage,esi,LVM_GETITEM,0,addr ItemData2

cmp [edi.LVSORT].Gtype,1
mov edi,[edi.LVSORT].direction
jb P1
ja I1

; String sort
invoke lstrcmpi,addr Tbuff1,addr Tbuff2
or edi,edi
jz @f
neg eax
@@:
ret

; lParam sort
P1:
mov eax,ItemData2.lParam
mov ecx,ItemData1.lParam
cmp ecx,eax
jae @f
mov eax,-1
jmp P2
@@:
jne @F
mov eax,0
jmp P2
@@:
mov eax,1
P2:
or edi,edi
jz @F
neg eax
@@:
ret

; Image sort
I1:
mov eax,ItemData2.iImage
mov ecx,ItemData1.iImage
cmp ecx,eax
jae @F
mov eax,-1
jmp @I2
@@:
jne @F
mov eax,0
jmp @I2
@@:
mov eax,1
@I2:
or edi,edi
jz @F
neg eax
@@:
ret

LVSortProc endp

the error result is gotten for IP address.
regards

six_L

does not none encounter the trouble?
regards

Slugsnack

can you be a bit more clear as to what your problem actually is ?

six_L

the result about ip address is as follwing
Quote100.100.100.1
100.100.100.11
100.100.100.2
source code include
regards

Tedd

You're trying to sort them as strings (alphabetically) when you'd like to sort them as values (numerically.)
So, instead of using a direct strcmp, you can use inet_addr (in winsock) to get the ip-address as a value, then bswap it because it's in network byte-order ('reversed'), and use that as the dword value to compare ip-addresses against each other.
No snowflake in an avalanche feels responsible.

six_L

hey,Tedd
Thank you very much.
this is the accurate answer.
regards