Hello. I can not print plain text of several characters. I use this function here https://msdn.microsoft.com/en-us/library/windows/desktop/dd162959(v=vs.85).aspx

Here is the code of the console application that starts the function:

int _tmain(int argc, _TCHAR* argv[]) { LPTSTR printerName = (LPTSTR)_T("XP-58"); CString str = "la-la-la"; LPBYTE pByte = new BYTE[str.GetLength() + 1]; memcpy(pByte, (VOID*)LPCTSTR(str), str.GetLength()); DWORD count = 7; BOOL result = RawDataToPrinter(printerName, pByte, count); std::cout << result << std::endl; system("pause"); return 0; } 

The printer name is correct, it opens, because the number 1 is written in the console after the completion of work.

The problem is that the document is added to the print queue, and immediately removed from there, as if already printed, although the printer did not print anything at all.

There are suspicions that something with a printer port, it is connected to USB002. When I send to print something from a notebook, then in the print queue you can see that the USB002 port is registered, but through my program there is a task in the print queue without a port.

How to set the printer port when opened? Or maybe I have another problem?

  • Do you have UNICODE declared? And then you have "T" everywhere, and in the code you select new BYTE for some reason. - Athari
  • Not. Please tell me how to announce? I made a breakpoint after writing the bytes to the printer, the variables say that 7 bytes were written. - user178898
  • I also suspect that you need to specify the printer port somewhere. Can I specify it for the OpenPrinter function? Just when I make a print from some kind of program, for example from a notebook. then the USB002 port is written in the document queue for printing, and when I send to print through my program, the port is not written. And the document is added to the queue and immediately deleted. - user178898

1 answer 1

Long thought on this issue.

It is not clear where you get the printerName "XP-58". Most likely, there is no such printer, and the job is simply sent to a standard virtual printer, which is analogous to / dev / null or print to a file.

Most likely, this value is incorrect, and you must first call EnumPrinters() and find the correct name for the printer / print server.

PS This is just a theory, and far from the fact that it will work.

  • The name of the printer was taken from the Control Panel - Devices and Printers. Now I will try to number printers)) Thanks - user178898
  • I just saw code examples of how people write the name of the printer model - as it is called in the control panel. For example "Deskjet D2300" - user178898
  • I tried to display the names of the printers, one of them has the name X and the port U. I understand that the name and the port were not fully derived, but only by the first character, that is, XP-58 and USB002. It turns out the name is correct. Tell me, can you still be able to specify the printer port in the OpenPrinter function? - user178898