This SDK helps developers to use printer PP55
within Microsoft eVB 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.BAS' as module to your eVB PocketPC project.
  3. Change, if necessary, the connection string in PrinterSupport.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 other function calls. None of the other printing functions will work if this call returns 0.
    2. call StartDoc(dc, doc_info) and check returned code for positive value
    3. call StartPage(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 EndPage(dc) and check returned code for positive value
    6. repeat steps 3, 4, 5 for every page you want to print
    7. call EndDoc(dc) and check returned code for positive value
      - If some of functions StartDoc, StartPage, EndPage or EndDoc fails, then call AbortDoc(dc) and go directly to the final step!
    8. call DeleteDC 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.

    Due to the nature of WinCE OS, there are some PDA that will not work using this code. Try to use alternative version of the source code, where the following functions:

    are changed to the ones with suffix 'Ex' at the end of function name.
    For example: where used GetPrinterDC - the new and approriate is GetPrinterDCEx.
    The same for ALL mentioned above functions. None other changes are required.

  5. IMPORTANT: the PrinterSupport functions are not reentrant! To preclude such situation add the following guardian code in the begining of every printing function:
    Private Sub CommandPrintSomethingXXX_Click()
      If working Then Exit Sub
      working = True
      ...................
      If Not PrintText (text, points) Then ' check to ensure correct printing
        Call MessageBox(Screen.ActiveForm.hwnd, "Can not connect to the printer!", "Error Printing", MB_ICONEXCLAMATION)
        ...................

    and pairing with the following at the end of every printing function:
      working = False
      .................
    End Sub ' CommandPrintSomethingXXX_Click()

    where the 'working' is global variable of type boolean.
    It is good practice to check variable before exit program too:
    Private Sub Form_OKClick()
      If working Then Exit Sub
      App.End
    End Sub
Some of the differences with 'standard' printers are:

Due to the eVB limitations there is tricky support for UDT.
Do not change anything in the source code if you do not know exactly what you are doing!

Function Description
SetDefaultPrinter
Selects the default printer. The selection will be printer, to be connected, in call to GetPrinterDC with NoChoce set to 'True'. If you know, which printer and connection want to use, then use older way to connect but do not forget to check values in source code correspond to the currently connected printer, especially the connection string (do not change others, if you do not know what you do)!
Usage:
If Not SetDefaultPrinter () Then MessageBox("Fail to select default printer!"): Exit
GetPrinterDC/Ex
Prepare usage of the printer. Invoke it before use the printer directly. Check returned value and NEVER forget to call appropriate DeleteDC/Ex.
If you don't want to use SetDefaultPrinter, then never forget to check values in source code correspond to the currently connected printer, especially the connection string (do not change others, if you do not know what you do) and restore usage of old way by uncomment some source lines! Pass the parameter 'False' to view printer dialog and allow changing of some default settings.
Note: the connection string MUST be the same with one, used in Printer Applet.
Examples: "IRDA", "COM1: 9600", "COM1: 57600" or "COM1: 115200".
Usage:
Dim dc as Long
dc = GetPrinterDC (True)
If dc = 0 Then MessageBox("Fail to connect with printer!"): Exit
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 width of font, and/or font name via parameters. If you want to change background color 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 Not PrintText (TextToPrint, 18, 0, False, False, False, False) Then MessageBox("Fail to print text! Check the printer connection and paper."): Exit
PrintGraphic
Enable print of WinCE HBITMAP. To load raster image of .BMP, .JPG, .GIF, .PNG and some other file formats use SHLoadImageFile function. If function return 0 then given file name is not recognized as valid raster format. There is no stretch options i.e. image will fit whole page.
Note: the graphic will be followed by feed defined in Printer Applet.
Usage:
Dim bmp As Long
bmp = SHLoadImageFile (FileName)
If bmp = 0 Then Exit
If Not PrintGraphic (bmp) Then MessageBox("Fail to print graphic! Check the printer connection and paper."): Exit
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 -1.
Note: it's very important to set focus to the requested control! 0 HWND is the whole desktop. The graphic will be followed by feed defined in Printer Applet.
Usage:
someControl.SetFocus
If Not PrintWindow (GetFocus, someControl.BackColor) Then MessageBox("Fail to print window! Check the printer connection and paper."): Exit
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 Not DefinePrinterLogo(LogoBMP) Then MessageBox("Fail to define logo!"): Exit
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:
Dim Track1 As String
Dim Track2 As String
Track1 = String(1, 0) ' all but zero length
Track2 = String(1, 0) ' all but zero length
If Not ReadMagstripe(Track1, Track2, "") Then MessageBox("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, and/or the width by BARCODE_WIDTH_ constants.
Usage:
If Not PrintBarcode ("123456789012", BARCODE_EAN13, BARCODE_WIDTH_NORMAL, 100, False, BARCODE_TEXTS_BOTH, 77) Then MessageBox("Fail to print barcode! Check printer connection and paper."): Exit
ReadPrinterStatus
Allows checking the printer about some conditions, see STATUS_ constants.
Use it to ensure that PP55 printer is properly connected.
Usage:
If Not ReadPrinterStatus(Status) Then MessageBox("Fail to read status from printer!"): Exit
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 Not ReadPrinterInfo(Temp, Volt) Then MessageBox("Fail to read info from printer!"): Exit
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:
If Not ReadPrinterCaps(Caps, Name) Then MessageBox("Fail to read info from printer!"): Exit
ControlPassthrough
Activates or deactivates passthrough mode.
Usage:
....
ControlPassthrough (dc, True) - no command will accept by printer and RS line can be used by other(s)
....
If ControlPassthrough (dc, False) Then ...
commands are accepted again...
ForceClosePrinter
Use to disconnect printer placed in passthrough mode. DeleteDC 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.
It is a low level function, so it is not recommended for use.
Usage:
Dim Cmd As String
Cmd = ByteToMemoryString(27) & ByteToMemoryString(Asc("J")) & ByteToMemoryString(100)
WritePrinterDirect(dc, Cmd, 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.
It is a low level function, so it is not recommended for use.
Usage:
....
Dim Cmd As String
Cmd = ByteToMemoryString(27) & ByteToMemoryString(Asc("v"))
If Not WritePrinterDirect(dc, Cmd, 2) Then Exit - pass status command
Dim Sz As Long
Sz = ReadPrinterDirect(dc, Cmd)
If Sz <> 1 Then Exit
....Cmd will contain one byte status from printer.

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


© 2003 Datecs Ltd.