Hello.
I need to put strings on the stack as parameters for MessageBoxA, but my current code just doesn't work
.386
.model flat, stdcall
option casemap :none
extern MessageBoxA@16:near
include C:\masm32\include\masm32rt.inc
include C:\masm32\include\PushText.inc
.data
a db "test!",0
b db "test!!",0
.code
main:
push 0
PushText "A"
PushText "B"
push 0
call MessageBoxA@16
end main
Hi Timo,
A few rules:
- include C:\masm32\include\PushText.inc: my crystal ball has no idea what's inside. Besides, some of us really hate "projects" with many little files that contain only a few lines of useful stuff. Put your macros into the main text, except if they are more than, say, a hundred lines long.
- use include \Masm32\include\..., not C:\Masm32; many members use other drives
- "doesn't work" is a safe recipe for not getting any help at all; tell us what doesn't work, i.e. error messages or other problems.
Quote from: jj2007 on July 09, 2021, 06:47:06 PM
Timo,
A few rules:
- include C:\masm32\include\PushText.inc: my crystal ball has no idea what's inside.
- use include \Masm32\include\..., not C:\Masm32; many members use other drives
- "doesn't work" is a safe recipe for not getting any help at all; tell us what doesn't work, i.e. error messages or other problems.
The fact of the matter is that there is nothing to report - there are no errors. It just doesn't work.
ptEsp=0
PushText MACRO arg, obs:=<0>
Local c1$, c1x$, q$, ct, txLen, tmp$, txRest, pNum
ifb <arg>
add esp, ptEsp
ptEsp=0
EXITM
endif
txLen SIZESTR <arg>
txRest=(txLen-2) mod 4
ct=3-txRest ; OPT_Errlines 0
tmp$ CATSTR <Len=>, %txLen, <, rest=>, %txRest, <, count=>, %ct
% echo tmp$
tmp$ equ <0>
mov edx, esp
pNum=0
While txLen gt 1
pNum=(pNum shl 8) or tmp$
txLen=txLen-1
c1$ SUBSTR <arg>, txLen, 1
tmp$ CATSTR <">, c1$, <">
ifidn c1$, <\>
c1x$ SUBSTR <arg>, txLen+1, 1
ifidn c1x$, <n>
tmp$ equ <13>
endif
endif
ifidn c1$, <n>
c1x$ SUBSTR <arg>, txLen-1, 1
ifidn c1x$, <\>
tmp$ equ <10>
endif
endif
ct=ct+1
if ct ge 4
if obs
push not pNum
else
push pNum
endif
ct=0
pNum=0
ptEsp=ptEsp+4
endif
Endm
if obs
.Repeat
not byte ptr [edx]
dec edx
.Until edx<esp
endif
ENDM
in PushText.inc
OK, thanks, now it's clearer:
- how did you assemble your code? With \Masm32\qEditor.exe, with RichMasm (http://masm32.com/board/index.php?topic=5314.0), with another IDE?
- if it was with qEditor, did you use the console assembly and link?
- does the *.exe file exist?
- when you run it from a DOS prompt, what do you see?
I compile with ml, and link with link as a console application(without any IDE). When you start the application, the command line opens, it is on the screen for a couple of seconds, and then it closes. Yes, there is an exe file
Ok. In the meantime, I found the post where you got the PushText.inc, and surprise, surprise: it was me :badgrin:
Try this:
main:
PushText "Hello "
print esp
PushText "World"
inkey esp
exit
end main
Note that after each PushText, the stack pointer is different. That is why MessageBox won't work, unless you store the new pointers somewhere. What exactly are your intentions with PushText?
Quote from: jj2007 on July 09, 2021, 07:09:23 PM
Ok. In the meantime, I found the post where you got the PushText.inc, and surprise, surprise: it was me :badgrin:
Try this:
main:
PushText "Hello "
print esp
PushText "World"
inkey esp
exit
end main
Strange, it works ...
I myself only need a stack to store arguments for commands.
Timo,
Passing arguments on the stack "by their address" for strings and by value for anything else is normal, are you trying to do something different ?
Quote from: hutch-- on July 09, 2021, 07:24:36 PM
Timo,
Passing arguments on the stack "by their address" for strings and by value for anything else is normal, are you trying to do something different ?
No, only pass arguments to commands
Quote from: Timofeyka on July 09, 2021, 07:19:23 PM
Strange, it works ...
I almost never post code that doesn't work :cool:
Quote from: Timofeyka on July 09, 2021, 07:21:48 PM
I myself only need a stack to store arguments for commands.
PushText is a fairly exotic way to do that, there are simpler ones, and you know them already:
.data
a db "test!",0
b db "test!!",0
So why do you want to take the complicated way?
Quote from: jj2007 on July 09, 2021, 07:31:03 PM
Quote from: Timofeyka on July 09, 2021, 07:19:23 PM
Strange, it works ...
I almost never post code that doesn't work :cool:
Quote from: Timofeyka on July 09, 2021, 07:21:48 PM
I myself only need a stack to store arguments for commands.
PushText is a fairly exotic way to do that, there are simpler ones, and you know them already:
.data
a db "test!",0
b db "test!!",0
So why do you want to take the complicated way?
I can't say to be honest, you just need to pass arguments to commands and call them without procedures and other rubbish.
The problem for us is what you are after is an old hacking technique to pre-load the stack and dump arguments into a location that does not normally accept arguments of that type. Later OS versions have broken that hack but its a grossly inefficient way to pass arguments. Conventional stack works fine and for speed, pass in registers but passing string data rather than addresses does not have a valid purpose apart from being a broken hacking technique.
Thanks for the answers. I decided to add variables to the stack.
Hi Timo,
Here is another example :
Passing strings to the stack (http://masm32.com/board/index.php?topic=5799.0)
And one more :biggrin:
include \masm32\MasmBasic\MasmBasic.inc
.code
MyTest proc uses edi esi ebx arg1:DWORD, arg2, TheString
LOCAL v1, v2, rc:RECT, buffer[100]:BYTE ; ordinary Locals first
_Local v3=123, v4:REAL4=123.456
_Local x$="Hello World", y$=TheString ; strings can be initialised, too
ClearLocals ; first line after the LOCALs
deb 1, "Perfect:", v1, v2, v3, v4, $x$, $TheString
ret
MyTest endp
Init
invoke MyTest, 123, 456, Chr$("String passed")
EndOfCode