468,736 Members | 1,875 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,736 developers. It's quick & easy.

Outputting a string to STDOUT with our libc functions

how to print something with out calling libc functions like printf ,
puts etc..

This is the direct method how libc printf works on windows
so why not use this one and get rid of MSVCRT.DLL linking
but make suer to link it with kernel32.lib

#include <windows.h>

int __stdcall main(int argc, char **argv)
{
HANDLE handle;
handle = GetStdHandle(STD_OUTPUT_HANDLE);

WriteFile(handle, "hello world!", 12, NULL, NULL);
CloseHandle(handle);
return 0;
}

link /ENTRY:main program.obj kernel32.lib
Aug 17 '08 #1
4 1732
On 2008-08-17, raashid bhatt <ra**********@gmail.comwrote:
how to print something with out calling libc functions like printf ,
puts etc..

This is the direct method how libc printf works on windows
so why not use this one and get rid of MSVCRT.DLL linking
but make suer to link it with kernel32.lib

#include <windows.h>

int __stdcall main(int argc, char **argv)
{
HANDLE handle;
handle = GetStdHandle(STD_OUTPUT_HANDLE);

WriteFile(handle, "hello world!", 12, NULL, NULL);
CloseHandle(handle);
return 0;
}
Because that will work on Windows and only Windows.

puts("Hello, world!")

will work on *all* platforms supporting C. (Excepting C99 'freestanding'
compilers, which generally are only used for small embedded platforms.

--
Andrew Poelstra ap*******@wpsoftware.com
To email me, use the above email addresss with .com set to .net
Aug 17 '08 #2
raashid bhatt wrote:
how to print something with out calling libc functions like printf ,
puts etc..

This is the direct method how libc printf works on windows
so why not use this one and get rid of MSVCRT.DLL linking
but make suer to link it with kernel32.lib

#include <windows.h>

int __stdcall main(int argc, char **argv)
{
HANDLE handle;
handle = GetStdHandle(STD_OUTPUT_HANDLE);

WriteFile(handle, "hello world!", 12, NULL, NULL);
CloseHandle(handle);
return 0;
}

link /ENTRY:main program.obj kernel32.lib
This will tie your code to the Windows API while using puts will mean
that your program can run wherever a conforming ISO C implementation is
available, which is far more widespread than implementations of the
Windows API.

Aug 17 '08 #3
Andrew Poelstra <ap*******@supernova.homewrites:
[...]
puts("Hello, world!")

will work on *all* platforms supporting C. (Excepting C99 'freestanding'
compilers, which generally are only used for small embedded platforms.
Or C90 freestanding implementations; the distinction between
freestanding and hosted implementations isn't new in C99.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Aug 18 '08 #4
On 17 Aug, 18:47, raashid bhatt <raashidbh...@gmail.comwrote:
how to print something with out calling libc functions like printf ,
puts etc..

This is the direct method how libc printf works on windows
so why not use this one and get rid of MSVCRT.DLL linking
but make suer to link it with kernel32.lib

#include <windows.h>

int __stdcall main(int argc, char **argv)
{
* * HANDLE handle;
* * handle = GetStdHandle(STD_OUTPUT_HANDLE);

* * WriteFile(handle, "hello world!", 12, NULL, NULL);
* * CloseHandle(handle);
* * return 0;

}

link /ENTRY:main program.obj kernel32.lib
Of course, printf can also do formatting - that's what the "f" stands
for.
Aug 18 '08 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Graham Ashton | last post: by
12 posts views Thread by gc260262 | last post: by
4 posts views Thread by xdevel | last post: by
29 posts views Thread by Andrea | last post: by
7 posts views Thread by Pietro Cerutti | last post: by
3 posts views Thread by grbgooglefan | last post: by
reply views Thread by Christian Heimes | last post: by
7 posts views Thread by S James S Stapleton | last post: by
xarzu
2 posts views Thread by xarzu | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.