AFAIK you need to format the buffer as expected by the ExtEscape()
API layout. I never used Escape()
, but ExtEscape()
- and it worked with a Zebra printer.
Here is what the MSDN doc states:
lpszInData [in] A pointer to the input structure required for the specified escape. The first word in the buffer contains the number of bytes of input data. The remaining bytes of the buffer contain the data itself.
So you may code this as such:
cmm := '00'; // reserve space for the initial `word`
for i := 0 to commands.Count-1 do
cmm := cmm + commands[i] + #10;
pword(cmm)^ := length(cmm)-2; // store the length
if ExtEscape(Printer.Canvas.Handle, PASSTHROUGH, Length(cmm), pointer(cmm), 0, nil)<0 then
raise Exception.Create('Error at printing to printer');
Printer.EndDoc;
Be aware that if your command is not well formatted (e.g. missing chars), it may just create an out of memory error in the printer spooler - yes, I've seen that! In this case, you may have to kill then restart the Printer Spooler service... fix your code... and try again...
And do not forget to put the ESC
character at the beginning of each of your commands[]
, as requested by the Zebra doc.