FieldSoftware
Home

PrinterCE SDK
   General Info
   Download
   Purchase & Pricing

Developer Info
   eVC MFC
   eVC C/C++
   eVB

Special Features
   AsciiCE
   PrintDC
   BarcodeCE

Documentation
   PrinterCE SDK
   AsciiCE
   PrintDC
   BarcodeCE

Special Topics
  Supported Printers
  Bluetooth Printing
  Network Printing

  DLL Load Error

.Net CF C# or VB.Net:
  PrinterCE.NetCF SDK

-----------------------------

Software Developers
  PrinterCE SDK
 
PrinterCE.NetCF SDK
  PocketHTMLprint SDK

Printing Utilities
  PrintPocketCE
  PIEprint
  PocketPixPrint
  PocketShot
 
PocketClipPrint

 Arcade Games
  SockOut
  MazeCraze

Contact Info

PrinterCE - MFC Installation and Usage
Download PrCEUser.h - PrinterCE Defines file 

  1. Download & install PrinterCE on your device & desktop PC (see instructions on Download page)
  2. On your desktop PC, click Start menu -> Run -> type "regsvr32 \path\prenginece.dll" where "path" is the path to where you saved the desktop version of PrEngineCE.dll. Click OK and you should see a "LoadLIbrary succeeded" message box.
  3. Create your MFC Project - Be sure to enable ActiveX controls in the MFC wizard.
  4. Select the Project -> Add to Project -> Components and Controls
  5. The Components and Controls Gallery will pop up (it may take some time) - select Registered ActiveX Controls.
  6. Find and select the PrinterCE, BarcodeCE and/or AsciiCE2 class entry and click OK to insert the desired component(s). This will insert two “wrapper class” files for each component (printerce.h/printerce.cpp, barcodece.h/barcodece.cpp and asciice2.h/asciice2.cpp) which provides MFC with all of the information needed to support the inserted components. [NOTE: If you do not see the PrinterCE related controls, click on "Add Control" button. Then browse over to where you saved the desktop version of PrEngineCE.dll, select and click OK. You should now see the controls and can complete this step].
  7. Click OK to Confirm Classes and Close the Controls Gallery.
  8. IMPORTANT NOTE FOR AsciiCE2 USERS: There is a known bug in MFC that causes incorrect "wrapper classes" to be generated for methods that pass BYTE or BYTE* parameters (see MSDN Q241862). Two AsciiCE2 methods ("Read" and "Write") pass blocks of data through BYTE arrays. If your application uses the AsciiCE2 "Read" or "Write" methods, click on the following links to download corrected "asciice2.h" and "asciice2.cpp" files. Then copy these into your MFC app's directory, overwriting the files that MFC created for you. 
    [Download asciice.h]       [Download asciice.cpp]
  9. Select View menu -> Resource Symbols
  10. On the Resource Symbols dialog, click New and type in IDC_PRINTERCE for the new resource name. Click OK and Close the dialog box.
  11. Now you need to declare the class and create it. You need to decide where to do this, but it may look something like the following:

#include “printerce.h”                 // This defines the CPrinterCE class
CPrinterCE PrinterCE1;            // Set up an instance of the class

void SomeFunction()
{
      static BOOL OneTimeFlag=FALSE;
      if (!OneTimeFlag) {
            //Only create one instance of PrinterCE!!
            OneTimeFlag=TRUE;
           
RECT rc;        //Since PrinterCE is not visible, value of RECT is not important
            PrinterCE1.Create(NULL,0,rc,this,IDC_PRINTERCE);
      }
      //PrinterCE1 should now be up and running, so do whatever you want…
      //   For this example, we’ll do the Hello World…
      PrinterCE1.SelectPrinter();
      PrinterCE1.DrawText(_T(“Hello World”),0,0,NULL);
      PrinterCE1.EndDoc();
}

Compile your program, download it to your WinCE device (double-check that you have installed PrinterCE onto your device) and run it. You should see the printer dialog box, and then get a printed page that says “Hello World”

Using MFC
There are some issues that MFC/CE developers must deal with that are unfortunate results of ActiveX controls being designed to work with both eVB and MFC. The eVB environment automatically handles these situations… maybe someday MFC will also. Until then, MFC developers must do the “handling”. 

Function Calls
The PrinterCE documentation follows the eVB scheme that “subroutines” (functions that do NOT return a value) do not place parameters within parentheses, while “functions” (which DO return a value) do use parens. Of course, MFC always uses parens. So when the documentation defines the DrawCircle method as: “object.DrawCircle x, y, radius, [color], [ aspect]” the MFC programmer must convert this to : PrCE.DrawCircle(x,y,radius,color,aspect);
 

PrinterCE Properties
The PrinterCE properties must have “Get” or “Put” pre-appended to the property name for MFC. For example, the FontBold property is specified in the documentation as: object.FontBold [= Boolean]. An eVB program can set this property by PrinterCE.FontBold=True. An MFC program must call PrinterCE.SetFontBold(VARIANT_TRUE); Similarly, to get the current X coordinate from PrinterCE, MFC calls xCoord=PrinterCE.GetTextX();

VARIANT BOOL
Every C++ developer knows that the Boolean value FALSE is 0 and TRUE is 1. But in eVB, TRUE is –1 (although FALSE is still 0). MFC defines the type VT_BOOL for this situation with the values VARIANT_TRUE and VARIANT_FALSE. All PrinterCE functions that expect a Boolean value look for either VARIANT_TRUE or VARIANT_FALSE. Note that PrinterCE functions are designed to work fine with the standard TRUE/FALSE as well as VARIANT_TRUE/VARIANT_FALSE, but any PrinterCE functions that return Boolean values will return the VARIANT versions.

VARIANT Data Types
Certain PrinterCE functions use “optional” parameters. For example, the DrawText method is defined as: “object.DrawText string, [x], [y], [count]” where x, y and count are “optional”. In C++, these sort of optional parameters are handled by overloading functions so that you might have several variants of DrawText() to deal with all possible calls. eVB cannot deal with overloaded functions, so any “optional” parameters must be passed as VARIANT data types. (Please check the online documentation for more information on VARIANTs and MFC’s VARIANT class wrapper CComVariant).

Basically, a VARIANT can represent a wide variety of data types including VT_EMPTY. When an eVB program calls a PrinterCE function without one or more of the optional parameters, it eVB automatically passes an “empty” VARIANT for each “omitted” parameter. An MFC program can instead pass NULL (0) for an empty parameter and PrinterCE will work fine. But when an MFC program actually wants to pass a value for one of these optional params, a VARIANT value must be passed. The MFC CComVariant class eases much of the pain of using variants. Note that you need to #include <atlbase.h> in order to use both VARIANT and CComVariant data types in your MFC program.  

PrCEUser.h - MFC & VC++ Constants defined
Copy and include this file (PrCEUser.h) to get all of the PrinterCE user constants predefined.

Wrapping up – an MFC Example:  
An example is worth its weight in gold, so below is the source code for an MFC function that prints out some text and an image. Note that VARIANTs are used rather than CComVariants to demonstrate how to use them. Click here to see a scan of the output of this example. Follow the steps above to create the initial MFC program and add PrinterCE to it..

//atlbase.h allows use of both VARIANT and the CComVariant class
#include <atlbase.h>
#include "printerce.h" //Define CPrinterCE class

CPrinterCE m_PrinterCE;  //Instance of PrinterCE
#include "PrCEUser.h"  //PrinterCE defs file that defines all user constants

void CPrEngineTestDlg::OnTestprint()
{
  RECT rc;   // dummy used to create PrinterCE instance
  m_PrinterCE.Create(NULL,0,rc,this,IDC_PRINTERCE);

  //Check out the CComVariant class because it does a lot of
  //  the grunt work for you. I will just use straight VARIANTS here.
  VARIANT cv,cvx,cvy,cvsiz;

  VariantInit(&cv);      //You have to init variants before you use them
  VariantInit(&cvx);
  VariantInit(&cvy);
  VariantInit(&cvsiz);

  m_PrinterCE.SelectPrinter();

  //Lets demo positioning and drawing text
  // Assigning a value to a variant requires 2 steps:
  //    define the "type" and the "value"  
 
cvx.vt=VT_I4;      //Define a couple of VARIANT longs and assign them
  cvx.lVal=1440;      // In TWIPS - 1440 TWIPS per inch
  cvy.vt=VT_I4;
  cvy.lVal=2880;
  m_PrinterCE.SetFontSize(16);

  m_PrinterCE.DrawText(_T("16 pt font, no bold or italic"),&cvx,&cvy,NULL);
  m_PrinterCE.SetFontBold(VARIANT_TRUE); //Use VARIANT_TRUE rather than TRUE
  m_PrinterCE.DrawText(_T("Bold"),NULL,NULL,NULL);
  m_PrinterCE.SetFontItalic(VARIANT_TRUE);
  m_PrinterCE.DrawText(_T("Bold & Italic"),NULL,NULL,NULL);

  //Change ScaleMode to inches and use FLOAT values for x,y
  m_PrinterCE.SetScaleMode(vbInches);
  cvx.vt=cvy.vt=VT_R4;      //Float type
  cvx.fltVal=0.75;
  cvy.fltVal=6.25;
  //Lets also set BOLD value to max of 1000
  m_PrinterCE.SetFontName(_T("Courier New"));
  m_PrinterCE.SetFontBoldVal(1000);
  m_PrinterCE.DrawText(_T("Bold & Italic : 1000"),&cvx,&cvy,0);
  m_PrinterCE.SetFontBoldVal(700);
  m_PrinterCE.DrawText(_T("Bold & Italic : 700"),NULL,NULL,0);
  m_PrinterCE.SetFontBoldVal(500);
  m_PrinterCE.DrawText(_T("Bold & Italic : 500"),NULL,NULL,0);
  m_PrinterCE.SetFontBoldVal(300);
  m_PrinterCE.DrawText(_T("Bold & Italic : 300"),NULL,NULL,0);
  m_PrinterCE.SetFontBoldVal(100);
  m_PrinterCE.DrawText(_T("Bold & Italic : 100"),NULL,NULL,0);
  m_PrinterCE.SetFontBold(VARIANT_TRUE);
  m_PrinterCE.DrawText(_T("Bold & Italic : Straight bold"),NULL,NULL,0);

  //Finally, lets draw a picture
  cv.vt=VT_BOOL;                      //Type is BOOL
  cv.boolVal=VARIANT_TRUE;      //value is True (VARIANT_TRUE)
  //Center on the page
  float fltx,flty;
  fltx=m_PrinterCE.GetPrPgWidth() / 2.0;
  flty=m_PrinterCE.GetPrPgHeight() / 2.0;
  m_PrinterCE.SetJustifyHoriz(vbCenter);      //Center horizontally
  m_PrinterCE.SetJustifyVert(vbCenter);      //Center vertically
  //The "keepaspect" optional value must be a variant bool
  cvsiz.vt=VT_R4;
  cvsiz.fltVal=2.0;      //Fit picture in 2" box
 m_PrinterCE.DrawPicture(_T("\\Images\\Owl.bmp"),fltx,flty,&cvsiz,&cvsiz,&cv);

  m_PrinterCE.EndDoc();
  VariantClear(&cv);
  VariantClear(&cvx);
  VariantClear(&cvy);
  VariantClear(&cvsiz);
}