0

To print a receipt under Linux system I'm using this code:

char *buff
fd = open("/dev/usb/lp0", O_RDWR);
if(!write(fd, buff, len)) return 0;

Ever device under Linux system is a file, we can open it and write data without problem.

My question is about windows system using c++ language.

Lhoussaine
  • 59
  • 1
  • 11
  • You shouldn't in practice use that on Linux; better `popen("lp", "w")` – Basile Starynkevitch Jan 25 '16 at 15:22
  • 1
    under windows you will have to use the printing apis, msdn should have docs on it – Kai Iskratsch Jan 25 '16 at 15:25
  • 2
    On Windows you can [ShellExecute](https://msdn.microsoft.com/en-us/library/windows/desktop/bb762153)(NULL, "print", "receipt1234.txt", "", "C:\\receipts") – Fozi Jan 25 '16 at 15:25
  • im going to test popen("lp", "w") wish it will be a portable routine ? about shellExecute i dont have any idea how it works ! – Lhoussaine Jan 25 '16 at 15:30
  • It is not different on Windows. But the odds that the device driver provides "LPT1" are not that great, parallel printers have gone the way of the dodo a long time ago. If the programming manual does not provide hints then give the manufacturer a call. – Hans Passant Jan 25 '16 at 15:31
  • To my knowledge, there is no "portable" way to access the printer. Each operating system has its own way(s), and you will need to write separate code for each. `#ifdef`, here we come. – DevSolar Jan 25 '16 at 16:34
  • Is there a link where i can find some c++ examples ? i mean for windows system. – Lhoussaine Jan 25 '16 at 16:53
  • @KaiIskratsch you don't have to. In DOS era people simply use [`copy file.txt LPT1`](https://en.wikipedia.org/wiki/Device_file#DOS.2C_TOS.2C_OS.2F2.2C_and_Windows). In modern Windows there are various other options like the [`print` command](http://stackoverflow.com/q/32595421/995714). A similar way can be used if you map the thermal printer to a device like that – phuclv Feb 25 '17 at 06:26

0 Answers0