Outputting a string to STDOUT with our libc functions

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • raashid bhatt

    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(ST D_OUTPUT_HANDLE );

    WriteFile(handl e, "hello world!", 12, NULL, NULL);
    CloseHandle(han dle);
    return 0;
    }

    link /ENTRY:main program.obj kernel32.lib
  • Andrew Poelstra

    #2
    Re: Outputting a string to STDOUT with our libc functions

    On 2008-08-17, raashid bhatt <raashidbhatt@g mail.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(ST D_OUTPUT_HANDLE );
    >
    WriteFile(handl e, "hello world!", 12, NULL, NULL);
    CloseHandle(han dle);
    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 apoelstra@wpsof tware.com
    To email me, use the above email addresss with .com set to .net

    Comment

    • santosh

      #3
      Re: Outputting a string to STDOUT with our libc functions

      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(ST D_OUTPUT_HANDLE );
      >
      WriteFile(handl e, "hello world!", 12, NULL, NULL);
      CloseHandle(han dle);
      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.

      Comment

      • Keith Thompson

        #4
        Re: Outputting a string to STDOUT with our libc functions

        Andrew Poelstra <apoelstra@supe rnova.homewrite s:
        [...]
        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_Keit h) kst-u@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"

        Comment

        • gw7rib@aol.com

          #5
          Re: Outputting a string to STDOUT with our libc functions

          On 17 Aug, 18:47, raashid bhatt <raashidbh...@g mail.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(ST D_OUTPUT_HANDLE );
          >
              WriteFile(handl e, "hello world!", 12, NULL, NULL);
              CloseHandle(han dle);
              return 0;
          >
          }
          >
          link /ENTRY:main program.obj kernel32.lib
          Of course, printf can also do formatting - that's what the "f" stands
          for.

          Comment

          Working...