I tested this procedure in a dialog but my test dialog crashing after showing the result string.
Btw, this procedure may safely running in a runtime window app. What is wrong?

(using Tasm5)



StrCat PROC Str1:DWORD, Str2:DWORD, ResultBuff:DWORD
USES edi, esi
LOCAL Str1Len:DWORD, Str2Len:DWORD

mov edi, Str1
call calcLen
mov Str1Len, ecx ; 1. String length
mov edi, Str2
call calcLen
mov Str2Len, ecx ; 2. String length
mov ecx, Str1Len

mov esi, Str1
mov edi, ResultBuff
mov ecx, Str1Len
repnz movsb ; ResultBuf = Str1

mov ecx, Str2Len ; edi points to end of string
mov esi, Str2 ; esi points to 2. string
repnz movsb ; ResultBuf = Str1 + Str2

mov ecx, Str1Len
add ecx, Str2Len
mov byte ptr ResultBuff[ecx], 0 ; NULL terminator.

RET

calcLen:
mov ecx, -1
mov al, 0
repnz scasb
not ecx
dec ecx
RETN

StrCat ENDP


;=================================================
USAGE:
.data

s1 db 'HonkiPonki',0
s2 db 'Torino',0

.data?

buffer db 100 dup(?)

.code
call StrCat, offset s1, offset s2, offset buffer
call SetDlgItemText, hwnd_, IDC_EDT1, offset buffer
Posted on 2003-01-23 12:49:41 by cakmak
Here is another example of strcat:




.386
.model flat,stdcall
option casemap:none

include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\crtdll.lib

extern strcat:proc
extern printf:proc

.data
dest db 'This is '
db 18 dup(0)
src db 'a strcat example.',0
format db '%s',0
.code
start:
push offset src
push offset dest
call strcat
add esp,8
push offset dest
push offset format
call printf
add esp,8
invoke ExitProcess,0
end start

Posted on 2003-01-23 14:01:15 by Vortex
cakmak,

I bet that your procedure overwrites the stack in this line:

mov byte ptr ResultBuff, 0 ; NULL terminator.

Things should work as expected if you load ResultBuff into a register first, then add ECX to that register, and store 0 where the result points to, e.g.:

mov eax, ResultBuff
mov BYTE PTR , 0

(Untested)

Regards, Frank

EDIT: instead of computing the terminator's offset, you could exploit the fact that EDI points to it anyway at this stage of the procedure :-)
Posted on 2003-01-23 14:35:30 by Frank
thansk, Vortex for alternate StrCat example...
and thanks Frank for suggestion, you were right. Problem solved, I really wanted the reason of my fault. Again big thanks...:)

Regards
Posted on 2003-01-24 11:22:44 by cakmak