From: | Alastair M. Robinson |
Date: | 04 Aug 2000 at 19:32:17 |
Subject: | Standard out from a library... |
Hi Emanuele,
> I have written a shared library, and in some functions of its i call
> printf().... well when in the main program i open the lib and i call one of
> these function, nothing is outputted.
> Surely the library works, all the others functions are ok, i think that the
> library doesn't know stdout, how can i do ?
> I am using StormC v3.0.
As you've found out, you can't use stdio from within a library.
The best way around this depends on why you're printing to stdout - if it's
just for debugging, then the best way is to link with the Debug.lib on the
Dev CD and use KPrintF() or KPutStr(). These functions send data to the
serial port, but it can be redirected to a shell window using Sushi or
similar.
If you're using printf as part of the useful function of your library, then
you can use dos.library/PutStr(), which will automatically fetch the calling
process's output filehandle. If you need any formatting, you might be able
to use sprintf() to construct your string, but otherwise use
exec.library/RawDoFmt()
*HOWEVER* - if you do this, your library can only be safely used from DOS
processes - not from tasks. If your library is 'public' then you should
document this warning!
All the best,
Why don't they make mouse-flavored cat food?