Writing a Print Utility on Windows Mobile for Mobile Printer
By admin on Oct 2, 2007 in .NET, Programming
In my previous blog, How to Write a Print Driver for Mobile Thermal Printer, I showed you how to drive a print driver for a mobile printer. Now I am going to show you how I called the library from .NET to print out text, image and barcode.
Since the library is a DLL, you need to make the necessary declarations. Below is the code snippet in VB.NET
Declare Function PrintText Lib “SPRT.dll” (ByVal data As String) As Boolean
Declare Function PrintImage Lib “SPRT.dll” (ByVal serialNo As Integer) As Boolean
Declare Function PrintBarcode Lib “SPRT.dll” (ByVal type As Integer, ByVal data As String) As Boolean
Declare Function PortClose Lib “SPRT.dll” () As Boolean
Declare Function PortOpen Lib “SPRT.dll” (ByVal nPort As Integer) As Boolean
Declare Function SetFont Lib “SPRT.dll” (ByVal width As Integer, ByVal height As Integer,
ByVal underline As Integer, ByVal direction As Integer, ByVal white As Integer) As Boolean
Declare Function Initialize Lib “SPRT.dll” () As Boolean
Declare Function ReadData Lib “SPRT.dll” (ByRef data As String) As Integer
Declare Function SetBarcodeMode Lib “SPRT.dll” (ByVal mode As Integer,
ByVal height As Integer, ByVal width As Integer) As Boolean
After you declared the functions to be declared, the rest is simple. You can use the APIs in the library to print text, image or barcode.
Sasikumar | Jul 4, 2008 | Reply
Hi,
Amazing and really useful application. Really Great!. I have used your code, but only 2 lines are printed though I am giving 10 PrintText() commands to print. Can you please tell where do I need to fix up this?
Regards
Sasi
Am4dEuZ | Feb 21, 2010 | Reply
After 2 year wm 6.5 not have printer support…Regards the 2 lines problem(for those that read now), is sufficient to add a delay in PrintText (dll) :
LPSTR lpszOutput=new char[nCount+1];
Sleep(20);<–pay attention, is Sleep not sleep
and it work perfectly!
byz