; wParam = ptrStringW
use32
  push esi
  mov esi, [esp + $10]
  or esi, esi
  jz NoMem

  cld
;Search for CR
Loop1:
  lodsw
  or ax, ax
  jz EndOfString
  cmp ax, $0d
  je FoundCR
  cmp ax, $0a
  jne Loop1

; LF   / 0A   / 10
  mov ecx, 2
  sub esi, ecx
  jmp Found

FoundCR:
; CR   / 0D   / 13
; CRLF / 0D0A / 1310
; Test if LF
  lodsw
  cmp ax, $0a
  je FoundCRFL

; CR   / 0D   / 13
  mov ecx, 2
  sub esi, 4
  jmp Found

FoundCRFL:
; CRLF / 0D0A / 1310
  mov ecx, 4
  sub esi, ecx

Found:
  mov eax, esi
  mov esi, [esp + $14]
  or esi, esi
  jz NoLenPtr

  mov [esi], ecx
NoLenPtr:
  pop esi
  ret $10

EndOfString:
NoMem:
  xor eax, eax
  pop esi
  ret $10
