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

AppendBkS proc near

   push esi         ; preserve ptr 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 str byte length
   shr ecx, 1       ; convert to wchar count
   jz _exitp        ; exit empty string passed

   cmp [esi+ecx*2-2], word ptr 92 ; backslash?
   je _alloc
   inc ecx          ; allocate for backslash

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

   mov [eax+esi*2-2], word ptr 92 ; assert backslash

  _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)

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