The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: six_L on August 06, 2009, 09:43:29 AM

Title: LVSortProc
Post by: six_L on August 06, 2009, 09:43:29 AM
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.
Title: Re: LVSortProc
Post by: six_L on September 14, 2009, 02:52:20 AM
does not none encounter the trouble?
Title: Re: LVSortProc
Post by: Slugsnack on September 14, 2009, 07:07:36 PM
can you be a bit more clear as to what your problem actually is ?
Title: Re: LVSortProc
Post by: six_L on October 06, 2009, 07:49:56 AM
the result about ip address is as follwing
Quote100.100.100.1
100.100.100.11
100.100.100.2
source code include
Title: Re: LVSortProc
Post by: Tedd on October 06, 2009, 01:44:31 PM
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.
Title: Re: LVSortProc
Post by: six_L on October 08, 2009, 01:18:03 AM
hey,Tedd
Thank you very much.
this is the accurate answer.