;
 ; ------------------------------------------------------
 ;
 ; Function LCaseExt(sFileName As String) As String
 ;    sExt = LCaseExt(sFileName)
 ; End Function
 ;
 ; ------------------------------------------------------
;
 .486            ; 32-bit instruction set
 .model flat     ; Protected memory, 4GB limit
 .code           ; Start of code

LCaseExt proc near

   push esi         ; preserve register
   xor eax, eax     ; zero default return
   mov esi,[esp+12] ; copy string descriptor
   push ebx         ; preserve register
   mov esi,[esi]    ; extract string pointer
   test esi, esi    ; validate string pointer
   jz _exitp        ; exit if null str passed
   mov ecx,[esi-4]  ; extract str byte length
   test ecx, ecx    ; validate string length
   jz _exitp        ; exit if zero len passed
   mov ebx, ecx     ; copy byte length of str

  _period:
   cmp [esi+ecx-2], word ptr 46 ; '.'
   je _calc
   sub ecx, 2       ; zero based byte offset
   jnz _period      ; continue search for '.'
   jmp _alloc       ; no period, alloc full len

  _calc:
   add esi, ecx     ; offset start of extension
   sub ebx, ecx     ; calculate extension length

  _alloc:
   shr ebx, 1       ; convert length to char cnt
   mov edx,8876543h ; api address patched on init
   push ebx         ; SysAllocStringLen len param
   push esi         ; pass string to copy pointer
   call edx         ; call SysAllocStringLen api

  _lcase:
   dec ebx
   js _exitp
   mov dx,[eax+ebx*2] ; extract wchar into dx
   cmp dx, 65         ; If iChr < 65 Then
   jb _lcase          ;     GoTo _lcase
   cmp dx, 90         ; If iChr > 90 Then
   ja _lcase          ;     GoTo _lcase
   add dx, 32         ; iChr = iChr + 32
   mov [eax+ebx*2],dx ; lcase wchar into src
   jmp _lcase

  _exitp:
   mov edx,[esp+20] ; copy return descriptor
   mov [edx], eax   ; assign function result

   pop ebx       ; restore register
   pop esi       ; restore pointer register
   xor eax, eax  ; clear eax tell VB all okay
   ret 12        ; cleanup (lpObj, param, rc)

LCaseExt endp  ; end of procedure
end LCaseExt   ; end of code, indicate entry point
