OK, I bet this will be a lot harder to do in assembly then it is
in visual basic, jscript, c/c++, or anything else ;)

I need to build a string so i can append it to a file..
in jscript syntax it would be something like this:

string_name = cFileName + ","; // makes ' test.jpg,' for example
append_to_file(string_name,file_name); //example function

Posted on 2002-01-12 22:24:46 by matthew
something like this should work

FirstPart db "Text",0
SecondPart db "%s.txt",0

CompleteString BYTE 512 dup(?)

invoke wsprintf, ADDR CompleteString, ADDR FirstPart, ADDR SecondPart
Posted on 2002-01-12 22:49:29 by smurf
Use a resource of your choosing to look up the memcpy function.
Posted on 2002-01-12 23:22:55 by -T-
Something from Microsoft SDK

Note It is important to note that wsprintf uses the C calling convention (_cdecl), rather than the standard call (_stdcall) calling convention. As a result, it is the responsibility of the calling process to pop arguments off the stack, and arguments are pushed on the stack from right to left. In C-language modules, the C compiler performs this task.

If i'm using stdcall, what difference is this going to make?

push ADDR SecondPart
push ADDR FirstPart
push ADDR CompleteString
call wsprintf
pop eax
end start

Do I have to do something like that with std calling convention?
Posted on 2002-01-12 23:33:09 by matthew
there are cat functions in masm32.lib

look them up in masm32.hlp
Posted on 2002-01-13 00:02:41 by Hiroshimator
matthew, you have to use the calling convention that the function was designed for, otherwise things break. C-Calling convention states that the caller must correct the stack (i.e. push three DWORDs, call the function, add 12 to the stack). MASM hides all this from you with INVOKE. STDCALL is were the function corrects the stack (i.e. push three DWORDs and call the function). If you don't follow the guidlines of the interface the stack won't be aligned. As long as wsprintf is defined to MASM as a C type function it will do the right thing when you use INVOKE. If you don't use INVOKE, you have to remember to correct the stack. This should be in a FAQ - there are many messages here reguarding this.
Posted on 2002-01-13 00:37:35 by bitRAKE

The basics of concantenating strings is no big deal at all.

a$ = b$ + c$ ' in basic

Translates in assembler to allocating a buffer big enough to hold all of the strings that you wish to append to it, then write them one after another to that buffer.

There are 2 string concantenation functions in the MASM32 library, one does single CATSTR type concantenation, the other which is written by Alex (The Svin) does multiple string concantenation in one function call.

You may wish to write a procedure of your own depending on what you need to do and if you are handling a large number of appended strings, what you may need to do is keep a global variable as a pointer to the end of the last write so that the next one starts in the right place.

This way you can keep appending strings at high speed.


Posted on 2002-01-13 05:06:44 by hutch--
Here it is:

It uses TASM style code, but i am sure you can convert it :)

; StrConCat2
; concatenates 2 strings into destination
; -lpsz_src1=source 1
; -lpsz_src2=source 1
; -lpsz_dest1=[destination]=lp_src1+lp_src2

StrConCat2 PROC
ARG lpsz_src1,lpsz_src2,lpsz_dest1:dword

;1. copy first string
mov esi,[lpsz_src1]
mov edi,[lpsz_dest1]

cmp al,0
jnz @@copy_path_loop

;2. copy filename
mov esi,[lpsz_src2]
dec edi
cmp al,0
jnz @@copy_filename_loop

StrConCat2 endp

Posted on 2002-01-13 05:27:36 by BogdanOntanu
If u want to concatenate two strings, I wouldn't use wsprintf because it does a lot more than that so it would execute a lot more code than you need. I would rather use the string copy and concatenate APIs.
Posted on 2002-01-14 10:04:18 by Hel
Why do you use:
CompleteString BYTE 512 dup(?)

I've gotten it working with:
CompleteString db ?

Whats the difference?
Posted on 2002-01-24 01:03:13 by matthew
Of course it *works*, but when you will copy your string, it will erase the contents of other variables that comes after, because the next thing declared after it in .data? will be erased by your string...

CompleteString BYTE 512 dup(?) *reserves* 512 bytes of memory... so the next variable will be 512 bytes after it.
Posted on 2002-01-24 01:55:52 by JCP