News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

displaying text using API

Started by john113, April 21, 2008, 07:12:28 PM

Previous topic - Next topic

john113

Can someone please tell me why this code does not give a output of text box?




.data?
hStdout DWORD ?
IBytesWritten DWORD ?
IBytesToWrite DWORD ?
.data

Coordinates WORD 0003H, 0005H

.const
sConsoleTitle db"Hello!",0
sWriteText db"Press a key to exit!",0

.code

start:

invoke SetConsoleTitle, addr sConsoleTitle

invoke GetStdHandle,STD_OUTPUT_HANDLE

mov hStdout,EAX

invoke StrLen,addr sWriteText

mov IBytesToWrite,EAX

invoke SetConsoleCursorPosition,hStdout,Coordinates

invoke WriteFile,hStdout,addr sWriteText,IBytesToWrite,addr IBytesWritten,0

invoke CloseHandle,hStdout

invoke ExitProcess,0


end start


Vortex

.data?
hStdout DWORD ?
IBytesWritten DWORD ?
IBytesToWrite DWORD ?

.data

Coordinates COORD <3,5> ; better than Coordinates WORD 3,5

.const
sConsoleTitle db"Hello!",0
sWriteText db"Press a key to exit!",0

.code

start:

invoke SetConsoleTitle, addr sConsoleTitle

invoke GetStdHandle,STD_OUTPUT_HANDLE

mov hStdout,EAX

invoke StrLen,addr sWriteText

mov IBytesToWrite,EAX

invoke SetConsoleCursorPosition,hStdout,DWORD PTR [Coordinates]

invoke WriteFile,hStdout,addr sWriteText,IBytesToWrite,addr IBytesWritten,0

; invoke CloseHandle,hStdout - no need for this line

invoke ExitProcess,0

end start

john113

Hi

Thanks for the help.

But it still does not print a window, it just prints out Press any key to exit!

any idea why?

Vortex

Quote from: Unit on April 21, 2008, 08:15:38 PM
Hi

Thanks for the help.

But it still does not print a window, it just prints out Press any key to exit!

any idea why?

A bit confusing... Did you build the project as console application? Also, you need to add a function to your code to receive keyboard input.

kermit

the program is working correctly, it's a console application so the text appears in the console box.

add the "inkey" command as last command, then when u start the exe directly from explorer u will see that the console title is also changing as desired ...

john113

I was trying to create a Macro using it, then call the macro ---> print "message",13,10

I was able to get it to work and it prints the message on console window. How can I use the macro to print few lines?

if I try
print "message",13,10
print "message",13,10

It only prints one line..


MichaelW

For the MASM32 print macro, something like this will work:
print "this",13,10,"is",13,10,"a",13,10,"5-line",13,10,"message",13,10
eschew obfuscation

kermit

hm,

now i'm a bit confused too,
u have created a new macro with that code and named the macro "print" ?
i would change the macro name to something different so it can't be confused with the original masm macro.

in ur code u haveĀ  cursor positioning, so if u execute it twice there appears only 1 line on the console... maybe thats the explanation...