45/54 Page
Mechatro, INC.
User Manual
Rev. 1.5
MTP-850P / 8100P / 8100P3
4.4 Commands for your program
Inserting command in your program
You can either insert command in your program or type in Windows dialogue box.
Below is sample code
Write User Code by WIN32 API
#include <stdio.h>
#include <windows.h>
int main(void)
{
BOOL testWriteUserData(HANDLE hPrint);
char
PrinterName[]="Mechatro Thermal Printer Series";
HANDLE
hPrinter;
DOC_INFO_2
DocInfo;
DWORD
JobId;
memset(&DocInfo,
0x0, sizeof(DocInfo));
DocInfo.pDocName
=
"Test";
DocInfo.pOutputFile = NULL;
DocInfo.pDatatype = "raw";
DocInfo.dwMode
=
DI_CHANNEL;
if(!OpenPrinter(PrinterName, &hPrinter, NULL))
return
-1;
if(!(JobId = StartDocPrinter(hPrinter, 1, (LPBYTE)&DocInfo)))
return
-1;
if(!StartPagePrinter(hPrinter))
return
-1;
testWriteUserData(hPrinter);
if(!EndPagePrinter(hPrinter))
return
-1;
if(!EndDocPrinter(hPrinter))
return
-1;
ClosePrinter(hPrinter);
return
0;
}
BOOL testWriteUserData(HANDLE hPrinter)
{
char
TestCode[]="\x1B@";
DWORD
Written;
if(!WritePrinter(hPrinter, TestCode, sizeof(TestCode)-1, &Written))
return
FALSE;
return
TRUE;
}