NO

Author Topic: How2 send output to printer  (Read 2872 times)

jwzumwalt

  • Guest
How2 send output to printer
« on: April 25, 2009, 10:06:33 PM »
I have been unsuccessful in trying all the examples I could find on the web to send output to the printer. One even mentioned turning the compilers ANSI compatibility off.

How do you do it?

Here are some of the things I have tried...

   fprintf(stdprn, "\n\t\rQuestion: Who shaves the barber?\n\r");
   fprintf(stdprn, "\n\t\rAnswer: She doesn't need to shave.\f");

   FILE *stdprn;
   stdprn = fopen("PRN","wb");
   fprintf(stdprn,"Hello World\n\n");
   fprintf(stdprn,"From Windows: TEST Test test\f");
   fclose(stdprn);
« Last Edit: April 27, 2009, 02:15:01 AM by jwzumwalt »

Offline DMac

  • Member
  • *
  • Posts: 272
Re: How2 send output to printer
« Reply #1 on: April 27, 2009, 06:18:33 PM »
Try this:

Code: [Select]
#define WIN32_LEAN_AND_MEAN

#include <stdio.h>
#include <windows.h>

int main(int argc, char *argv[])
{
     // Windows manages access to the parallel port.  The easiest way to send
     //  output to the parallel port is to use the Windows API.

     HANDLE hParallelPort;
     BOOL fSuccess;
     DWORD dwBytesWritten;

     char buf [MAX_PATH];
     memset(&buf,0,sizeof buf);

     hParallelPort = CreateFile("LPT1", GENERIC_READ | GENERIC_WRITE,
                          0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);

     if (INVALID_HANDLE_VALUE != hParallelPort)
     {
          sprintf(buf,"Question: Who shaves the barber?\r\n");
          fSuccess = WriteFile(hParallelPort, &buf, strlen(buf), &dwBytesWritten, NULL);

               if(fSuccess)
               {
                     sprintf(buf,"Answer: She doesn't need to shave.\r\n");
                     fSuccess = WriteFile(hParallelPort, &buf, strlen(buf), &dwBytesWritten, NULL);
               }

               // All done Free resources
               fSuccess = CloseHandle(hParallelPort);
     }
     return fSuccess;
}

Regards,
DMac
No one cares how much you know,
until they know how much you care.