;
 ; ------------------------------------------------------
 ;
 ; Remove trailing backslash if present
 ;
 ; Function RemoveBackslash(sPath As String) As String
 ;    Fast sStr = RemoveBackslash(sPath)
 ; End Function
 ;
 ; ------------------------------------------------------
;
 .486            ; 32-bit instruction set
 .model flat     ; Protected memory, 4GB limit
 .code           ; Start of code

TrimBkS proc near

   push esi         ; preserve register
   mov esi,[esp+12] ; copy source descriptor
   xor eax, eax     ; zero default return
   mov esi,[esi]    ; extract string pointer
   test esi,esi     ; validate string pointer
   jz _exitp        ; exit null string passed

   mov ecx,[esi-4]  ; extract byte len of str
   shr ecx, 1       ; convert to wchar count
   jz _exitp        ; exit empty string passed

   cmp [esi+ecx*2-2], word ptr 92 ; backslash?
   jne _alloc
   dec ecx          ; allocate remove backslash

  _alloc:
   mov edx,8876543h ; api address patched on init
   push ecx         ; SysAllocStringLen len param
   push esi         ; pass string to copy pointer
   call edx         ; call SysAllocStringLen api

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

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

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