I was wondering how i would go about doing console i/o without using the masm32 syntax of Stdin and StdOut and without using the win32 api. I've been looking all over for it and all i have been able to find is references to invoke StdOut. What if someone were to use things like printf or fprintf. Does that get translated to win32 api calls? Any help is appreciated. Thanks!
Posted on 2002-01-05 17:19:19 by purdue6985
printf is inside msvc.dll.. (I think atleast) when you write to the console you are required to use API to do it. There is wsprintf() however, a kernel function, so that you can format your strings first then output them using StdOut.
Posted on 2002-01-05 18:46:16 by Eagle17
what if i wanted to write my own I/O functions. How would i go about doing that without using any api calls? I'm just asking because i've only seen references to using interrupts for I/O. Sorry if this is a stupid question. I'm new to assembly and all the info i find on the subject refers to DOS or using the win32api.
Posted on 2002-01-05 20:38:14 by purdue6985
Short answer: you have to use the win32 api.
Interrupts were the DOS api.
Posted on 2002-01-05 20:45:02 by f0dder
I've been working on an import lib for CRTDLL.DLL which exports (all?) the C
standard library functions. As you can see it's a work in progress
(I'll add more if needs be) and requires some more work but you may find it
handy. Just include CRTDLL.INC in your source file and link with CRTDLL.LIB.

If someone else has been working on or knows of something similar please yell
out so we don't duplicate the work. I'd be quite happy if someone actually had
a complete implib, MASM's been annoying me with its inabilty to generate
arbitrary linker records other quirks with exporting data and name decoration.

Anyways...





Exported from crtdll.dll:

extern _imp___iob:DWORD ; array of standard streams

;-----------------------------------------------------------------------------
; stdio.h
;-----------------------------------------------------------------------------
printf PROTO C :DWORD, :VARARG
fprintf PROTO C :DWORD, :DWORD, :VARARG
puts PROTO :DWORD ; manual stack balance
fflush PROTO :DWORD ; manual stack balance

;-----------------------------------------------------------------------------
; stdlib.h
;-----------------------------------------------------------------------------
system PROTO :DWORD ; manual stack balance
free PROTO :DWORD ; manual stack balance
malloc PROTO :DWORD ; manual stack balance
exit PROTO :DWORD ; manual stack balance

Usage:

test_proc proc
invoke puts, CTEXT ('Hello World!')
add esp, 4

mov eax, _imp___iob
add eax, 32
invoke fflush, eax ; stdout
add esp, 4

invoke printf, CTEXT ('Good morning %s'), CTEXT ('Vietnam!', 13, 10)

mov eax, _imp___iob
add eax, 32
invoke fflush, eax ; stdout
add esp, 4

mov eax, _imp___iob
add eax, 64 ; stderr
invoke fprintf, eax, CTEXT ('Hello STDERR!', 13, 10)

mov eax, _imp___iob
add eax, 32
invoke fflush, eax ; stdout
add esp, 4

invoke system, CTEXT ('pause')
add esp, 4

ret
test_proc endp



See the attachment for the full example.

btw Thanks to huh, bitrake et al for the handy macro.

Cheers,
Boggy
Posted on 2002-01-05 21:38:33 by Boggy
I mucked up the calling conventions in the inc file, sorry. They should all be C protos. Anyway I'll post back in a few days with a more completed export lib that uses the proper calling conventions. Look out for it soon.
Posted on 2002-01-06 02:01:10 by Boggy
purdue6985,

f0dder is right, if you want to perform console IO you must use the appropriate API calls to do it. You can use the MASM32 ones or write your own but they will all use the same API function calls to do it.

Regards,

hutch@movsd.com
Posted on 2002-01-06 03:43:00 by hutch--