This SDK helps developers to use printer PP55
within Microsoft eVC 3.0.

In order to use PP55 the following steps must be performed:
  1. Invoke Printer Applet on PDA and make sure you connected the right printer and whether it is available from the PDA. For more specific information check the associated PDA helps.
  2. Attach the file named 'Printer.cpp' in your eVC PocketPC/PocketPC 2002 project. Include the file named Printer.h in the file from where you need to access the printer.
  3. Change, if necessary, the connection string in GetPrinterDC function. If your PDA will use a printer with different speeds and connection types, then the proper solution is to call the function with parameter 'NoChoice' set to 'false', which gives the ability to change selection of speed and/or orientation and/or paper size.
  4. Use the following sequence for printer usage:
    1. call any function for printing Text, Graphic or Barcode, as well as some non-standard ReadMagstripe, ReadPrinterStatus, and/or others.
    Or:
    1. call GetPrinterDC and check returned handle. Remember this handle to use it later in the other function calls. None of the other printing functions will work if this call returns 0.
    2. call fStartDoc(dc, doc_info) and check returned code for positive value
    3. call fStartPage(dc) and check returned code for positive value
    4. draw what you want to the dc - text and/or graphic using system functions Rectangle, Ellipse, DrawText, BitBlt, and so on ... any supported by WinCE
    5. call fEndPage(dc) and check returned code for positive value
    6. repeat steps 3, 4, 5 for every page you want to print
    7. call fEndDoc(dc) and check returned code for positive value
      - If some of functions fStartDoc, fStartPage, fEndPage or fEndDoc fails, then call fAbortDoc(dc) and go directly to the final step!
    8. call DeletePrinterDC to release allocated system resources. This function MUST be invoked. Failing to call it will prohibit further printer usage (until PDA reset)!
    For more information of how to use the functions see source code.
Some of the differences with 'standard' printers are:

Due to the nature of WinCE OS, there are some PDA that will work with 'impersonate' HDC, so retreiving the HDC via GetPrinterDC call, need to delete it later with DeletePrinterDC call!
Use the functions GetPrinterCaps and EscapePrinter instead of GetDeviceCaps and ExtEscape for proper and successful access to printer!
Do not change anything in the source code if you do not know exactly what you are doing!

Function Description
SetDefaultPrinter
Shows the printer selection dialog. Use to select default printer and connection type. Call it once as "Printer Setup" procedure and all next calls to the function GetPrinterDC with parameter NoChoice set to 'true' will use selected settings to connect with printer.
Usage: SetDefaultPrinter (hwndMain);
GetPrinterDC
Prepare usage of the printer. Invoke it before use the printer. Check returned value and NEVER forget to call appropriate DeletePrinterDC.
Usage:
HDC dc = GetPrinterDC (true)
if (!dc) then { ErrorBox("Fail to connect with printer!"); return false; }
DeletePrinterDC
Use to delete allocated system resources and close connection with printer. Never forget to call it for every obtained printer's HDC.
Usage: DeletePrinterDC (dc);
PrintText
Enable print WYSIWYG text. The text is printed with the passed point size (not the pixel size!). You can change foreground color, and/or font name via parameters. If you want to change background color, and/or horizontal alignment, and/or width of font, you need to modify source code. Horizontal align defaults to left. Width of the fonts can vary (see FW_ constants) but not all widths produce different output (this is a WinCE limitation). Font name defaults to 'Tahoma' and no other choices on many PDAs. The length of text if limited by OS and used controls (probably 32Kb is the length limit).
Note: the text will be followed by feed defined in Printer Applet.
Usage:
if (!PrintText (TextToPrint, 18, 0)) then { ErrorBox("Fail to print text! Check the printer connection and paper."); return false; }
PrintGraphic
Enable print of WinCE HBITMAP. To load raster image of .BMP, .JPG, .GIF, .PNG and some other file formats use SHGifFileToBmp function. If function return 0 then given file name is not recognized as valid raster format. If image dimensions are out of printer ones, use the stretch option. Available options are to stretch by: page width, or whole page (i.e. fit in two directions - always print image onto one page). If the image is smaller or bigger that the current page width (orientation of paper was assumed), picture is enlarged or shrunk. If the image still does not fit into the selected paper size, the rest is printed on next page(s). If the orientation is portrait and there are no margins (default), the print is continuous never mind how many pages are required.
Note: the graphic will be followed by feed defined in Printer Applet.
Usage:
HBITMAP bmp = SHGifFileToBmp (FileName)
if (!bmp) return false;
if (!PrintGraphic (bmp)) { ErrorBox("Fail to print graphic! Check the printer connection and paper."); return false; }
PrintWindow
Enable print of WinCE HWND. Allows printing of a window's content, stretching it to the current printer width. The transparent color is discarded when printing, if there is no need of transparent color pass CLR_INVALID.
Note: The graphic will be followed by feed defined in Printer Applet.
Usage:
If (!PrintWindow (GetFocus (), GetSysColor (COLOR_WINDOW))) { MessageBox("Fail to print window! Check the printer connection and paper."); return false; }
DefinePrinterLogo
Enable to define WinCE HBITMAP as printer's logo. All limitations and features are the same as PrintGraphic, plus additional limitations comes from the printer: the image can not exceed 384 pixels width (which is the fixed printer's width) and 248 pixels height. The image is threated as true-color. Every pixel is converted to gray level (0-255), and the levels bellow 128 are treated as black, all others are threated as white.
If the dimensions are out of permited, the downloading is not performed.
Note: the process of converting color image to monochrome is very slow.
Command to print logo is GS / n, where n (0-3) defines printing mode. See WritePrinterDirect.
Usage: if (!DefinePrinterLogo(LogoBMP)) { ErrorBox("Fail to define logo!") return false; }
ReadMagstripe
Read magnetic card (if the environment exist; check via function ReadPrinterCaps for the CAPS_MAGSTRIPE value). If you want to read three tracks at once, check for the CAPS_THREE_HEAD value, otherwise command will be reject by the printer. Successful reading is indicated by returned values, if nothing is returned, the timeout has expired.
Usage:
char* tracks[3] = { 0 }, track1 [100], track2 [100];
size_t sizes[3] = { 0 };
tracks[0] = track1; sizes [0] = sizeof (track1);
tracks[1] = track2; sizes [1] = sizeof (track2);
if (!ReadMagstripe(tracks, sizes)) ErrorBox("MCR timeout expire! Try again or reject.")
PrintBarcode
Allow printing barcodes. Pass the barcode data itself, some of the BARCODE_ type, the width, the height, the font, the text position and the feed after printed barcode. The barcode data must be proper, if it is not, or the barcode is not fit in printer width (48mm) it will not be printed without notification of that. Change the barcode width by BARCODE_WIDTH_ constants, and/or the duplicate text positions by BARCODE_TEXTS_ constants, and/or the font by BARCODE_FONT_ constants.
Usage:
if (!PrintBarcode ("123456789012", BARCODE_EAN13, BARCODE_WIDTH_NORMAL, 100, BARCODE_TEXTS_BOTH, BARCODE_FONT_B, 77)) { ErrorBox("Fail to print barcode! Check printer connection and paper."); return false; }
ReadPrinterStatus
Allows checking the printer about some conditions, see STATUS_ constants.
Use it to ensure that PP55 printer is properly connected.
Usage:
if (!ReadPrinterStatus(&Status)) { ErrorBox("Fail to read status from printer!"); return false; }
ReadPrinterInfo
Allows checking the printer's battery voltage and head temperature. Voltages above 6.0V are functional for the printer, otherwise any attempt to print will turn off the printer. The temperature of the printing head is measured in Celsius (if the CAPS_FAHRENHEIT then in Fahrenheit) degree. The voltage value is multiplied by 10.
Can be used to ensure that the PP55 printer is properly connected.
Usage:
if (!ReadPrinterInfo(&Temp, &Volt)) { ErrorBox("Fail to read info from printer!"); return false; }
ReadPrinterCaps
Allows to check the printer about some equipment and features (see CAPS_ constants) and to retrieve the printer's internal name (including version number and language version). The name is composed from 27 character name (space padded) and three-digit number without dot (where the first digit is major firmware version, next two digits are minor version), followed by two-letter language code (EN stay for English, JP for Japan, and so on).
Use it to ensure that PP55 printer is properly connected.
Usage:
char Name [30];
int Caps;
if (!ReadPrinterCaps(&Caps, Name, sizeof(Name))) { ErrorBox("Fail to read info from printer!"); return false; }
ControlPassthrough
Activates or deactivates passthrough mode. Need to retreive HDC before with GetPrinterDC call, and delete it later with DeletePrinterDC call.
Usage:
....
ControlPassthrough (dc, true); // no command will accept by printer and RS line can be used by other(s)
....
if (!ControlPassthrough (dc, false)) ...
// commands are accepted again...
ForceClosePrinter
Use to disconnect printer placed in passthrough mode. DeletePrinterDC is called internaly by function. Using it in other conditions can discard some printing.
Usage:
ForceClosePrinter(dc); // check of returned value is redundant.
WritePrinterDirect
Writes data directly to the printer. You must know the printer commands, or the data will be treated as text and will be printed with the printer's internal font. Need to retreive HDC before with GetPrinterDC call, and delete it later with DeletePrinterDC call.
It is a low level function, so it is not recommended for use.
Usage:
WritePrinterDirect(dc, "\x1B\x4A\x64", 3); // will feed printer by 100/203 of inch.
ReadPrinterDirect
Reads data from the printer. You must know what exactly will come from the printer or the module will sleep until timeout expires. Need to retreive HDC before with GetPrinterDC call, and delete it later with DeletePrinterDC call.
It is a low level function, so it is not recommended for use.
Usage:
....
if (!WritePrinterDirect(dc, "\x1B\x76", 2)) return false; // pass status command
BYTE info;
DWORD Sz = ReadPrinterDirect(dc, &info, 1)
if (Sz != 1) return false;
....'info' will contain one byte status from printer.
GetPrinterCaps
Use it to obtain specific printer's properties, like GetDeviceCaps. Need to retreive HDC before with GetPrinterDC call, and delete it later with DeletePrinterDC call.
It is a low level function, so it is not recommended for use.
Usage:
GetPrinterCaps (dc, LOGPIXELSY); // will return vertical DPI resolution of printer
EscapePrinter
Use to access printer directly, via escape codes. Need to retreive HDC before with GetPrinterDC call, and delete it later with DeletePrinterDC call.
It is a low level function, so it is not recommended for use.
Usage:
EscapePrinter (dc, PASSTHROUGH, "\x1BT", 2, 0, 0); // printer will print short diagnostic info

If you have any problems or suggestions write to PocketPC support or visit our PocketPC PDA site.


© 2003-2004 Datecs Ltd.