Code is below, I want all 3 of those strings to be made into 1, the reason I don't just make it 1 variable is because the third part is dynamic, I am just hardcoding it for testing purposes. The second output (msgbox) is wrong, what is wrong with this?


.386
.model flat, stdcall
option casemap:none

include \masm32\include\windows.inc

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

include \masm32\include\user32.inc
includelib \masm32\lib\user32.lib

include \masm32\include\Winmm.inc
includelib \masm32\lib\Winmm.lib

.data
cmd_open_start db "open ",0
str_alias_type db " ALIAS mp3 type MPEGVideo", 0
bufferPlayMP3 db "mp3", 0
.data?

.code

start:
invoke lstrcat, addr cmd_open_start, addr bufferPlayMP3
invoke MessageBox, 0, addr cmd_open_start, addr bufferPlayMP3, 0
invoke lstrcat, addr cmd_open_start, addr str_alias_type
invoke MessageBox, 0, addr cmd_open_start, addr bufferPlayMP3, 0
push 0
call ExitProcess
end start
Posted on 2003-06-04 20:15:27 by KewLexX
Your recieving buffer (cmd_open_start) is not large enough to hold the final string.

wsprintf is better suited to this type of thing (remove the leading and trailing spaces from your strings):

FormatString db "Open %s %s",0
cmd_open_start db 256 DUP (0)

invoke wsprintf,OFFSET cmd_open_start,OFFSET FormatString,OFFSET bufferPlayMP3,OFFSET str_alias_type

if you are using MASM that is all you need if you are using another assembler don't forget to fix the stack:

add esp,16
Posted on 2003-06-04 20:58:13 by donkey
Thanks, Ill give it a try, but I have a few questions (I need to learn :)

How come this works, if I replace the order of the way I declare my variables, it works on my machine: I had

cmd_open_start db "open ",0
str_alias_type db " type MPEGVideo ALIAS TheMP3", 0
bufferPlayMP3 db "mp3", 0

and changed to

cmd_open_start db "open ",0
bufferPlayMP3 db "mp3", 0
str_alias_type db " type MPEGVideo ALIAS TheMP3", 0

and it worked.. but I can't do that in my case because BufferPlayMP3 will be in .data? section

Also, What do brackets do around a register/variable name? do they move the contents at THAT memory location into the register?
mov eax, for example.
Posted on 2003-06-04 21:05:35 by KewLexX
All variables are contiguous in memory so what happened was you overwrote the end of the first variable and continued into the next. When you displayed it, it just read memory until the first 0 byte so you would have this :
Var 1 represented by X

Var 2 represented by Y
Var 3 represented by Z

Var1 db "Hello",0
Var2 db "There",0
Var3 db "KewLexX",0

XXXXXXYYYYYYZZZZZZZZ
HELLO[b]0[/b]THERE[b]0[/b]KewLexX[b]0[/b]

When you overwrote it it looked like this
XXXXXXYYYYYYZZZZZZZZ
HELLOKewLexX[b]0[/b]ewLexX[b]0[/b]
As you can see if you attempt to add Var3, it now begins with a null and nothing will be added because it is considered an empty string.

MASM doesn't know where one variable starts and another ends, the labels you give it are just pointers to addresses in memory, when you assign 10 bytes and try to write 20 it will just continue writing into the next variable.
Posted on 2003-06-04 21:12:40 by donkey
brackets usually mean memory. mov eax, = mov dword data value pointed by the address in edi to eax.
Posted on 2003-06-05 03:13:45 by roticv