showbix
asked on
What's wrong with this code?
I have a TC++ 4.5 program and would expect the below output
Expected output
++++++++++++++++++++++++++ ++++++++++ +++++
RECOVERY Â : BERMULA Â Â Â Â Â Â
Trkh: 02/03/2004, Masa: 13:29:21
========================== ======
Transaksi : Â Â Â Â Â Â 00246155
========================== ======
RECOVERY Â : SELESAI Â Â Â Â Â Â
Trkh: 02/03/2004, Masa: 13:29:24
========================== ======
************************** ******
---- Laporan Sign On J/Wang ----
ID J/Wang: 4417J01 Â P/K: 02 Â Â
W.Pendahuluan: RM Â Â Â Â Â 0.00
Trkh: 02/03/2004, Masa: 13:30:20
========================== ======
   Welcome Friend To    Â
   ABC Comm Limited     Â
-------------------------- ------
Nombor Transaksi : Â Â Â 00246155
00459089 KADFON RM 5.00 Â Â Â Â
039 90392 Â Â Â Â Â Â Â Â Â Â Â
  5.00   1  RM     5.00
        ----------------
Jumlah Item   RM     5.00
00459090 KADFON RM 20.00 Â Â Â Â
039 90394 Â Â Â Â Â Â Â Â Â Â Â
  20.00   2  RM     40.00
        ----------------
Jumlah Item   RM     40.00
        ----------------
Jumlah Kutipan  RM     45.00
Jumlah Cukai   RM     0.00
Jumlah (Diskaun)RM Â Â Â Â 0.00
        ----------------
Jum.Perlu Bayar RM Â Â Â Â 45.00
        ================
Bayaran: Â Â Â Â Â Â Â Â Â Â Â Â
TUNAI Â Â Â Â Â RM Â Â Â Â 45.00
-------------------------- ------
    Sila Datang Lagi    Â
     TERIMA KASIH     Â
========================== ======
141702 4417J01 02032004 13:30:55
++++++++++++++++++++++++++ ++++++++++ +++++
But the output happen to be like this, which is not correct
++++++++++++++++++++++++++ ++++++++++ +++++
========================== ======
RECOVERY Â : BERMULA Â Â Â Â Â Â Â
Trkh: 02/03/2004, Masa: 13:29:21
========================== ======
Transaksi : Â Â Â Â Â Â 00246155
========================== ======
RECOVERY Â : SELESAI Â Â Â Â Â Â Â
Trkh: 02/03/2004, Masa: 13:29:24
========================== ======
************************** ******
---- Laporan Sign On J/Wang ----I
   Welcome Friend To     Â
   Welcome Friend To     Â
++++++++++++++++++++++++++ ++++++++++ ++++
This is my code.
++++++++++++++++++++++++++ ++++++++++ ++++
#define  STRICT
#include <windows.h>
#include <windowsx.h>
#include <string.h>
#include <stdio.h>
#include <io.h>
#include <fcntl.h>
#pragma hdrstop
#include "helpex.h"
#include "helpids.h"
#pragma argsused
int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
                                  LPSTR lpCmdLine, int nCmdShow)
{
      MSG msg;
      if (!hPrevInstance)
            if (!InitApplication(hInstanc e))
            return (FALSE);
      if (!InitInstance(hInstance, nCmdShow))
            return (FALSE);
      while (GetMessage(&msg, NULL, 0, 0)) {
           /* Only translate message if it is not an accelerator message */
           if (!TranslateAccelerator(hWn d, hAccTable, &msg)) {
                 TranslateMessage(&msg);
                 DispatchMessage(&msg);
           }
      }
      return (msg.wParam);
}
BOOL InitApplication(HINSTANCE hInstance)
{
      WNDCLASS wc;
      wc.style = 0;
      wc.lpfnWndProc = MainWndProc;
      wc.cbClsExtra = 0;
      wc.cbWndExtra = 0;
      wc.hInstance = hInstance;
      wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
      wc.hCursor = LoadCursor(NULL, IDC_ARROW);
      wc.hbrBackground = (HBRUSH)( COLOR_MENU+1 ); //GetStockObject(WHITE_BRU SH);
      wc.lpszMenuName ="MainMenu";
      wc.lpszClassName = "PRNDRV16";
      RegisterClass(&wc);
      wc.style = 0;
      wc.lpfnWndProc = DeviceComm;
      wc.cbClsExtra = 0;
      wc.cbWndExtra = 0;
      wc.hInstance = hInstance;
      wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
      wc.hCursor = LoadCursor(NULL, IDC_ARROW);
      wc.hbrBackground = (HBRUSH)( COLOR_MENU+1 ); //GetStockObject(WHITE_BRU SH);
      wc.lpszMenuName =NULL;
      wc.lpszClassName = "CommDvc";
      RegisterClass(&wc);
      return TRUE;
}
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
      char sMsg[80];
  char crlf[3]={13, 10, 0};
      hInst = hInstance;
      hAccTable = LoadAccelerators(hInst, "HelpexAcc");
      hWnd = CreateWindow(
            "PRNDRV16",
            "TMB Print Driver, Siemens ISB 2004",
            WS_OVERLAPPEDWINDOW,
            100, //CW_USEDEFAULT,
            100, //CW_USEDEFAULT,
            350, //CW_USEDEFAULT,
            500, //CW_USEDEFAULT,
            NULL,
            NULL,
            hInstance,
            NULL
            );
      if (!hWnd)
            return (FALSE);
      ShowWindow(hWnd, nCmdShow);
      UpdateWindow(hWnd);
      hCommDvc = CreateWindow(
            "CommDvc",
            "Siemens Device Control",
            WS_OVERLAPPEDWINDOW,
            10,  //CW_USEDEFAULT,
            10,  //CW_USEDEFAULT,
            300, //CW_USEDEFAULT,
            350, //CW_USEDEFAULT,
            NULL,
            NULL,
            hInstance,
            NULL
            );
      if (!hCommDvc)
            return (FALSE);
      ShowWindow(hCommDvc, nCmdShow);
      UpdateWindow(hCommDvc);
      fnLoadSetting();
      gGlobalEnd = 0;
      gGlobalOverwrite = 0;
      gIdleState = 0;
      if ((gSelectedPort == 1) | (gSelectedPort == 2))
      {
           if(!OpenPrinter(gSelectedP ort))
           {
                 ExitSystem();
           }
           else
           {
                 if(gSelectedPort==1)
                 {
                      SetMenuState(1, CM_COM1, TRUE);
                      SetMenuState(1, CM_COM2, FALSE);
                 }
                 else if(gSelectedPort==2)
                 {
                      SetMenuState(1, CM_COM1, FALSE);
                      SetMenuState(1, CM_COM2, TRUE);
                 }
           }
      }
      else
      {
            sprintf(sMsg, "COM%d is invalid. Default to COM1 port.", gSelectedPort);
            MessageBox(hWnd, sMsg, "DEFAULT", MB_OK);
            if(!OpenPrinter(gSelectedP ort))
                 ExitSystem();
            else
            {
                 if(gSelectedPort==1)
                      SetMenuState(1, CM_COM1, TRUE);
                 else
                      SetMenuState(1, CM_COM2, TRUE);
            }
      }
      if(strcmp("tmh5k2", gSelectedPrinter)==0)
      {
                 load_epson_tmh5k2();
                 SetMenuState(2, CM_EPSON, TRUE);
                 SetMenuState(2, CM_ND70, FALSE);
                 OutputScreen (hwndEdit, "COMMAND-> EPSON tmh5000ii Command Set Loaded");
      }
      else if(strcmp("nd70", gSelectedPrinter)==0)
      {
                 load_sni_nd70();
                 SetMenuState(2, CM_ND70, TRUE);
                 SetMenuState(2, CM_EPSON, FALSE);
                 OutputScreen (hwndEdit, "COMMAND-> Siemens Nixdorf nd70 Command Set Loaded");
      }
      else
      {
                 load_epson_tmh5k2();
                 strcpy(gSelectedPrinter, "tmh5k2");
                 SetMenuState(2, CM_EPSON, TRUE);
                 SetMenuState(2, CM_ND70, FALSE);
                 OutputScreen (hwndEdit, "COMMAND-> EPSON tmh5000ii Command Set Loaded");
      }
      OutputScreen (hwndEdit, "COMMAND-> Init Printer");
      strcpy(gsPollFile, "C:\\tmp\\devpoll");
      strcpy(gsDataFile, "C:\\tmp\\devcon");
      return (TRUE);
}
#pragma warn -eff
LRESULT CALLBACK _export MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
      DLGPROC lpProcAbout;
      DWORD  dwHelpContextId;
      //HDC hDC;
      PAINTSTRUCT ps;
      //TIMERPROC fnTimer;
      switch (message) {
            case WM_CREATE:
                 hwndEdit = CreateWindow(
                            "EDIT",   // predefined class
                            NULL,    // no window title
                            WS_CHILD | WS_VISIBLE | WS_BORDER | WS_HSCROLL | WS_VSCROLL |
                                 ES_LEFT | ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL |
                                 ES_WANTRETURN,
                            0, 0, 0, 0, // set size in WM_SIZE message
                            hWnd,    // parent window
                            (HMENU) GetMenu(hWnd),  // edit control ID
                            (HINSTANCE) hInst, // associate it with the application instance
                            NULL);
                 hWndBtn = CreateWindow(
                            "BUTTON",   // predefined class
                            "Reset Printer",    // no window title
                            WS_CHILD | WS_VISIBLE | WS_BORDER,
                            240, 410, 100, 30, // set size in WM_SIZE message
                            hWnd,    // parent window
                            (HMENU) CMD_RESET, //GetMenu(hWnd),  // edit control ID
                            (HINSTANCE) hInst, // associate it with the application instance
                            NULL);
                 SetTimer(hWnd, TIMER_ID, 2000, NULL);
                 break;
            case WM_QUIT:
                 ExitSystem();
                 break;
            case WM_TIMER:
                 if(wParam==TIMER_ID && !gBool)
                      OutputPoll();                 Â
                 break;
            case WM_SETFOCUS:
                      SetFocus(hwndEdit);
                      break;
            case WM_SIZE:
                      // Make the edit control the size of the window's
                      // client area.
                      MoveWindow(hwndEdit,
                            0, 0,      // starting x- and y-coordinates
                            LOWORD(lParam), // width of client area
                            HIWORD(lParam)-50, // height of client area
                            TRUE);
                      MoveWindow(hWndBtn,
                            LOWORD(lParam) - 110,      // starting x- and y-coordinates
                            HIWORD(lParam) - 35,
                            100, // width of client area
                            30, // height of client area
                            TRUE);
                      break;
            case WM_COMMAND:
                 switch (GET_WM_COMMAND_ID(wParam, lParam))
                 {
                      case CMD_RESET:
                            MessageBox(hWnd, "Reset Printer", "OK", MB_OK);
                            gGlobalOverwrite = 100;
                            break;
                      case CM_TSTCUT:
                            printer_PrintLineFeed();
                            printer_PrintLineFeed();
                            printer_PrintLineFeed();
                            printer_PrintLineFeed();
                            printer_PrintLineFeed();
                            printer_PrintReceiptHalfCu t();
                            OutputScreen (hwndEdit, "DATA-> Receipt Cut");
                            break;
                      case CM_TSTLOGO:
                            printer_PrintReceiptLogo() ;
                            OutputScreen (hwndEdit, "DATA-> Receipt Cut");
                            break;
                      case CM_TSTPRN:
                            OnMenuTestPrint();
                            break;
                      case CM_TSTDSP:
                            printer_ClearDisplay();
                            printer_PrintDisplay("---- Laporan Sign On J/Wang ----ID J/Wang: 4417J01  ");
                            break;
                      case CM_COM1:
                            SetMenuState(1, CM_COM1, FALSE);
                            SetMenuState(1, CM_COM2, FALSE);
                            if(OpenPrinter(1))
                            {
                                 InitPrinter();
                                 SetMenuState(1, CM_COM1, TRUE);
                                 gSelectedPort = 1;
                                 OutputScreen (hwndEdit, "COMMAND-> COM Port 1 Selected");
                            }
                            else
                            {
                                 OutputScreen (hwndEdit, "COMMAND-> COM Port 1 Open Failed");
                            }
                            break;
                      case CM_COM2:
                            SetMenuState(1, CM_COM1, FALSE);
                            SetMenuState(1, CM_COM2, FALSE);
                            if(OpenPrinter(2))
                            {
                                 InitPrinter();
                                 SetMenuState(1, CM_COM2, TRUE);
                                 gSelectedPort = 2;
                                 OutputScreen (hwndEdit, "COMMAND-> COM Port 2 Selected");
                            }
                            else
                            {
                                 OutputScreen (hwndEdit, "COMMAND-> COM Port 2 Open Failed");
                            }
                            break;
                      case CM_EPSON:
                            SetMenuState(2, CM_EPSON, TRUE);
                            SetMenuState(2, CM_ND70, FALSE);
                            load_epson_tmh5k2();
                            InitPrinter();
                            strcpy(gSelectedPrinter, "tmh5k2");
                            OutputScreen (hwndEdit, "COMMAND-> EPSON tmh5000ii Command Set Loaded");
                            break;
                      case CM_ND70:
                            SetMenuState(2, CM_EPSON, FALSE);
                            SetMenuState(2, CM_ND70, TRUE);
                            load_epson_tmh5k2();
                            InitPrinter();
                            strcpy(gSelectedPrinter, "nd70");
                            OutputScreen (hwndEdit, "COMMAND-> Siemens Nixdorf nd70 Command Set Loaded");
                            break;
                      case CM_ABOUT:
                            lpProcAbout = (DLGPROC)MakeProcInstance( (FARPROC)A bout, hInst);
                            DialogBox(hInst, "AboutBox", hWnd, lpProcAbout);
                            FreeProcInstance((FARPROC) lpProcAbou t);
                            break;
                      case CM_DVC:
                            SetMenuState(0, CM_DVC, TRUE);
                            ShowWindow(hCommDvc, SW_SHOW | SW_RESTORE);
                            UpdateWindow(hCommDvc);
                            break;
                      case CM_EXIT:
                            ExitSystem();
                            break;
                      default:
                            return (DefWindowProc(hWnd, message, wParam, lParam));
                 }
                 break;
            case WM_DESTROY:
                  KillTimer(hWnd, TIMER_ID);
                  WinHelp(hWnd,szHelpFileNam e,HELP_QUI T,0L);
      if(hComm >= 0)CloseComm(hComm);
                  PostQuitMessage(0);
      break;
            default:
      return (DefWindowProc(hWnd, message, wParam, lParam));
  }
      return 0L;
}
#pragma warn .eff
#pragma argsused
BOOL FAR PASCAL _export About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
  switch (message) {
            case WM_INITDIALOG:
                  return (TRUE);
    case WM_COMMAND:
                 if (GET_WM_COMMAND_ID(wParam, lParam) == IDOK) {
        EndDialog(hDlg, TRUE);
        return (TRUE);
      }
                  break;
            case WM_DESTROY:
                 DestroyWindow(hDlg);
                 break;
      }
      return (FALSE);
}
BOOL FAR PASCAL _export DeviceComm(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
      switch (message) {
            //case WM_INITDIALOG:
            //       hCommDvc = hDlg;
            //   return (TRUE);
            case WM_CREATE:
                      hComm = -1;
                      hwndEditDvc = CreateWindow(
                            "EDIT",   // predefined class
                            NULL,    // no window title
                            WS_CHILD | WS_VISIBLE | WS_BORDER | WS_HSCROLL | WS_VSCROLL |
                                 ES_LEFT | ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL |
                                 ES_WANTRETURN,
                            0, 0, 0, 0, // set size in WM_SIZE message
                            hDlg,    // parent window
                            (HMENU) GetMenu(hWnd),  // edit control ID
                            (HINSTANCE) hInst, // associate it with the application instance
                            NULL);
                      hWndBtnDvc = CreateWindow(
                            "BUTTON",   // predefined class
                            "OpenCOMM",    // no window title
                            WS_CHILD | WS_VISIBLE | WS_BORDER,
                            180, 270, 100, 30, // set size in WM_SIZE message
                            hDlg,    // parent window
                            (HMENU) CMD_OPENPORT, //GetMenu(hWnd),  // edit control ID
                            (HINSTANCE) hInst, // associate it with the application instance
                            NULL);
                      break;
            case WM_COMMAND:
                 if (GET_WM_COMMAND_ID(wParam, lParam) == CMD_OPENPORT)
                 {
                      if(hComm >=0)
                            ClosePrinter();
                      else
                            OpenPrinter(gSelectedPort) ;
                 }
                 break;
            case WM_SIZE:
                      // Make the edit control the size of the window's
                      // client area.
                      MoveWindow(hwndEditDvc,
                            0, 0,      // starting x- and y-coordinates
                            LOWORD(lParam), // width of client area
                            HIWORD(lParam)-50, // height of client area
                            TRUE);
                      MoveWindow(hWndBtnDvc,
                            LOWORD(lParam) - 110,      // starting x- and y-coordinates
                            HIWORD(lParam) - 35,
                            100, // width of client area
                            30, // height of client area
                            TRUE);
                      break;
            case WM_SETFOCUS:
                      SetFocus(hWndBtnDvc);
                      break;
            case WM_DESTROY:
                 //DestroyWindow(hDlg);
                 ShowWindow(hDlg, SW_SHOW);
                 break;
            default:
                  return (DefWindowProc(hDlg, message, wParam, lParam));
      }
      return (FALSE);
}
void SetMenuState(int nPos, UINT nMenuID, BOOL fOwnerDraw)
{
      HMENU hMenu;
      //BOOL fOwnerDraw;
      hMenu = GetSubMenu(GetMenu(hWnd), nPos);
      //fOwnerDraw = GetMenuState(hMenu, nMenuID, MF_BYCOMMAND) & MF_CHECKED;
      CheckMenuItem(hMenu, nMenuID, MF_BYCOMMAND | (fOwnerDraw ? MF_CHECKED : MF_UNCHECKED));
}
void fnLoadSetting()
{
      WORD wReturn;
      int nRet;
      char sINI[25];
      char szBuf[25];
      //char sMsg[80];
      wReturn = GetWindowsDirectory((LPSTR )sINI, sizeof(sINI));
      strcat(sINI, "\\tmshell.ini");
      nRet = GetPrivateProfileString("T MB Printer", "PRT", "tmh5k2",
                                                             szBuf, sizeof(szBuf), sINI);
      if(nRet == 0)
           MessageBox(hWnd, "Application Start Failed, Parameters:TMB Printer->PRT Referential Error!!", "ERROR", MB_ICONSTOP);
      else
           strcpy(gSelectedPrinter, szBuf);
      nRet = GetPrivateProfileString("T MB Printer", "COM", "1",
                                                             szBuf, sizeof(szBuf), sINI);
      if(nRet == 0)
           MessageBox(hWnd, "Application Start Failed, Parameters:TMB Printer->COM Referential Error!!", "ERROR", MB_ICONSTOP);
      else
           gSelectedPort = atoi(szBuf);
}
void ExitSystem()
{
      if(MessageBox(0, "Are you sure you want to quit the system ?", "QUIT", MB_YESNO)==IDYES)
      {
           //KillTimer(hWnd, TIMER_ID);
           DestroyWindow(hWnd);
      }
}
void OutputScreen(HWND handle, char sMsg[])
{
      static int entry;
      static int entry2;
      char *szBuff=NULL;
      char crlf[3]={13, 10, 0};
      int length;
      int ret=0;
      if(handle==hwndEditDvc)
      {
           entry++;
           if(entry>10)
           {
                 entry=0;
                 //strcpy(szBuff, "");
                 SendMessage(handle,WM_SETT EXT, 0, (LPARAM)"");
           }
      }
      length = SendMessage(handle, WM_GETTEXTLENGTH, 0, 0L);
      if(length > 0)// && length < 1024)
      {
           ret = (length) + strlen(sMsg) + 10;
           szBuff = (char *)GlobalAlloc(GPTR, ret);
           if(szBuff==NULL)
           {
                 SendMessage(handle,WM_SETT EXT, 0, sMsg);
           }
           else
           {
                 ret = SendMessage(handle, WM_GETTEXT, ret, (LPARAM)szBuff);
                 strcat(szBuff, sMsg);
                 strcat(szBuff, crlf);
                 SendMessage(handle,WM_SETT EXT, 0, (LPARAM)szBuff);
           }
           GlobalFree((HGLOBAL)szBuff );
      }
      else
      {
           SendMessage(handle,WM_SETT EXT, 0, (LPARAM)sMsg);
      }
      UpdateWindow(handle);
}
void OnMenuTestPrint()
{
      FILE *pFile;
      char tmp[100]={0};
      printer_Select();
      printer_PrintReceipt();
      printer_PrintReceiptLogo() ;
      printer_Print("123456789x1 23456789x1 23456789x1 23456789x1 2");
      printer_PrintLineFeed();
      printer_Print("abcdefghijk lmnopqrstu vwxyz");
      printer_PrintLineFeed();
      printer_Print("!@#$%^&*()_ +~`-=[]{}\ |;:',<.>/? ");
      printer_PrintLineFeed();
      printer_Print("ABCDEFGHIJK LMNOPQRSTU VWXYZ");
      printer_PrintLineFeed();
      printer_PrintLineFeed();
      printer_PrintLineFeed();
      printer_PrintLineFeed();
      printer_PrintLineFeed();
      printer_PrintReceiptHalfCu t();
 Â
}
//void CALLBACK OutputPoll(HWND hWnd, UINT msg, UINT timerID, DWORD dwTime)
void OutputPoll()
{
      int iState=0;
      char sPollData[80]={0};
      char sReadData[2640]={0};
      char sCommand[12];
      char sTemp[2640]={0};
      char sTemp3[2640]={0};
      char sTemp2[2640]={0};
      char sData[2650];
      char sFunction[80]={0};
      char sCutForm[80]={0};
      char sCutFormDtl[80]={0};
      int iLength=0;
      int iDataLockRetry=0;
      int iLoopData=0;
      char sMsg[80]={0};
      int bLoop=0;
      int iNCol=0;
      iState = 100;
      iDataLockRetry = 0;
      bLoop = 1;
      //MessageBox(hWnd, "Processing","OK", MB_OK);
      gBool = TRUE;
      while(bLoop==1)
      {
           bLoop = 0;
           if(iState==100)
           {
                 gIdleState = 1;
                 iState = 600;
                 if(file_check(gsPollFile) > 0)
                 {
                      if(file_poll_lock(gsPollFi le) == 0)
                      {
                            //sPollData = file_read(file_poll);
                            file_read(file_poll, sPollData);
                            if(strcmp(sPollData,"WRITE =1")==0)
                            {
                                 gIdleState = 0;
                                 iState = 200;
                            }
                      }
                 }
           }// state = 100
           if(iState==200)
           {
                 if (file_data_lock(gsDataFile ) == 0)
                 {
                      iDataLockRetry = 0;
                      iState = 300;
                 }
                 else
                      iDataLockRetry++;
                 if (iDataLockRetry >= 10)
                 {
                      iDataLockRetry = 0;
                      iState = 600;
                 }
           }// state = 200
           if(iState==300)
           {
                 //sReadData = file_read(file_data);
                 file_read(file_data, sReadData);
                 if(strlen(sReadData) != 0)
                 {
                       if(strcmp(sReadData, "EOF") == 0)
                             iState = 500;
                       else
                       {
                             iState = 400;
                             bLoop = 1;
         strcpy(sData, "");
                       }
                       //MessageBox(hWnd, sReadData, "OK", MB_OK);
                 }
                 else
                      iState = 300;
           }//state = 300
           if(iState==400)
           {
                 iState = 300;
                 if(strncmp(sReadData, "CUTFORM_DTL", 11) == 0)
                 {
                      strcpy(sCommand, "CUTFORM_DTL");
                      Mid(sReadData, 13, 0, sData);
                      Trim(sData);
                      strcpy(sCutFormDtl, sData);
                 }
                 else if(strncmp(sReadData, "LENGTH_COL", 10) == 0)
                 {
                      strcpy(sCommand, "LENGTH_COL");
                      Mid(sReadData, 12, 0, sData);
                      Trim(sData);
                      iNCol = atoi(sData);
                      //if(iNCol == 0)
                      //{
                      //      MessageBox(hWnd, "Problem with atoi(LENGTH_COL).", "ERR", MB_OK);
                      //      sprintf(sMsg, "READ=>%s,DATA=>%s,ATOI=>% d", sReadData, sData, iNCol);
                      //      MessageBox(hWnd, sMsg, "ERR", MB_OK);
                      //      iNCol = atoi(sData);
                      //}
                 }
                 else if(strncmp(sReadData, "CUTFORM", 7) == 0)
                 {
                      strcpy(sCommand, "CUTFORM");
                      Mid(sReadData, 9, 0, sData);
                      Trim(sData);
                      strcpy(sCutForm, sData);
                 }
                 else if(strncmp(sReadData, "COMMAND", 7) == 0)
                 {
                      strcpy(sCommand, "COMMAND");
                      Mid(sReadData, 9, 0, sData);
                      Trim(sData);
                      strcpy(sFunction, sData);
                      iLength = 0;
                      iNCol = 0;
                      strcpy(sCutForm, "");
                      strcpy(sCutFormDtl, "");
                 }
                 else if(strncmp(sReadData, "LENGTH", 6) == 0)
                 {
                      strcpy(sCommand, "LENGTH");
                      Mid(sReadData, 8, 0, sData);
                      Trim(sData);
                      iLength = atoi(sData);
                      //if(iLength == 0)
                      //{
                      //      MessageBox(hWnd, "Problem with atoi(LENGTH).", "ERR", MB_OK);
                      //      sprintf(sMsg, "READ=>%s,DATA=>%s,ATOI=>% d", sReadData, sData, iLength);
                      //      MessageBox(hWnd, sMsg, "ERR", MB_OK);
                      //      iLength = atoi(sData);
                      //}
                 }
                 else if(strncmp(sReadData, "DATA", 4) == 0)
                 {
                      strcpy(sCommand, "DATA");
                      Mid(sReadData, 6, 0, sData);
                      //Trim(sData);
      if(strncmp(sFunction, "print", 5) == 0)
                      {
                            iState = 1000;
                            printer_Select();
                      }
                      else if(strncmp(sFunction, "aprint", 6) == 0)
                      {
                            iState = 2000;
                            printer_Select();
                      }
                      else if(strncmp(sFunction, "ejectdoc", 8) == 0)
                      {
                            iState = 3000;
                            printer_Select();
                      }
                      else if(strncmp(sFunction, "insertdoc", 9) == 0)
                      {
                            iState = 4000;
                            printer_Select();
                      }
                      else if(strncmp(sFunction, "display", 7) == 0)
                      {
                            iState = 5000;
                            printer_Select();
                      }
                      else if(strncmp(sFunction, "loadlogo", 9) == 0)
                      {
                            iState = 6000;
                            printer_Select();
                      }
                      else if(strncmp(sFunction, "printlogo", 9) == 0)
                      {
                            iState = 7000;
                            printer_Select();
                      }
                      sprintf(sMsg, "%s=%d=%d=%d", sFunction, iLength, iNCol, iState);
                      OutputScreen(hwndEdit, sMsg);
                 }
                 else
                 {
                      strcpy(sCommand, "");
                      strcpy(sData, "");
                      strcpy(sReadData, "");
                 }
           }// state = 400
           if(iState==500)
           {
                 iState = 600;
                 if(file_truncate(&file_dat a, gsDataFile) != 0)
                      iState = 500;
                 if(file_truncate(&file_pol l, gsPollFile) != 0)
                      iState = 500;
           } //state = 500
           if(iState==600)
           {
                 if (file_data_close(file_data ) == 0)
                      iState = 700;
           }// state = 600
           if(iState==700)
           {
                 if (file_poll_close(file_poll ) == 0)
                      iState = 100;
           } //state = 700
           if(iState==1000) // command print
           {
                 sprintf(sMsg, "COMMAND->%s", sFunction);
                 OutputScreen(hwndEdit, sMsg);
                 if(strncmp(sCutFormDtl, "reccut", 6) ==0)
                      printer_PrintReceipt();
                 else if(strncmp(sCutFormDtl, "rec", 3) ==0)
                      printer_PrintReceipt();
     else if(strncmp(sCutFormDtl, "joucut", 6) ==0)
                      printer_PrintJournal();
                 else if(strncmp(sCutFormDtl, "jou", 3) ==0)
                      printer_PrintJournal();
                 else if(strncmp(sCutFormDtl, "doccut", 6) ==0)
                      printer_PrintDoc();
                 else if(strncmp(sCutFormDtl, "doc", 3) ==0)
                      printer_PrintDoc();
                 iLoopData = 1;
                 //iLength = strlen(sData);
                 while((iLoopData < iLength) && (iNCol > 0))
                 {
                      strcpy(sTemp,"");
                      //sTemp = Mid(sData, iLoopData, iNCol);
                      Mid(sData, iLoopData, iNCol, sTemp);
                      strcpy(sTemp3, sTemp);
                      Trim(sTemp3);
                      Mid(sCutFormDtl, 1, 3, sTemp2);
                      if (strlen(sTemp3) > 0 || strcmp(sTemp2, "doc")==0)
                      {
                            printer_Print(sTemp);
                            printer_PrintLineFeed();
                            printer_PrintCR();
                            sprintf(sMsg, "DATA->%s", sTemp);
                            OutputScreen(hwndEdit, sMsg);
                            if(strncmp(sTemp,"AKHIR LAPORAN", 13)==0 && strncmp(sCutFormDtl,"jou", 3)==0)
                                  strcpy(sCutFormDtl,"joucut ");
                      }
                      iLoopData = iLoopData + iNCol;
                 }
                 iState = 2500;
           } //state = 1000
           if(iState==2000)  // command aprint
           {
                 sprintf(sMsg, "COMMAND->%s", sFunction);
                 OutputScreen(hwndEdit, sMsg);
                 if(strncmp(sCutFormDtl,"re ccut", 6)==0)
                      printer_PrintReceipt();
                 else if(strncmp(sCutFormDtl,"re c", 3)==0)
                      printer_PrintReceipt();
                 else if(strncmp(sCutFormDtl,"jo ucut", 6)==0)
                      printer_PrintJournal();
                 else if(strncmp(sCutFormDtl,"jo u", 3)==0)
                      printer_PrintJournal();
                 else if(strncmp(sCutFormDtl,"do ccut", 6)==0)
                      printer_PrintDoc();
                 else if(strncmp(sCutFormDtl,"do c", 3)==0)
                      printer_PrintDoc();
                 iLoopData = 1;
                 //iLength = strlen(sData);
                 while((iLoopData < iLength) && (iNCol > 0))
                 {
                      //sTemp=0;
                      //sTemp = Mid(sData, iLoopData, iNCol);
                      Mid(sData, iLoopData, iNCol, sTemp);
                      strcpy(sTemp3, sTemp);
                      Trim(sTemp3);
                      Mid(sCutFormDtl, 1, 3, sTemp2);
                      if (strlen(sTemp3) > 0 || strcmp(sTemp2, "doc")==0)
                      {
                            printer_Print(sTemp);
                            printer_PrintLineFeed();
                            printer_PrintCR();
                            sprintf(sMsg, "DATA->%s", sTemp);
                            OutputScreen(hwndEdit, sMsg);
                            if(strncmp(sTemp,"AKHIR LAPORAN", 13)==0 && strncmp(sCutFormDtl,"jou", 3)==0)
                                  strcpy(sCutFormDtl,"joucut ");
                      }
                      iLoopData = iLoopData + iNCol;
                 }
                 iState = 2500;
           } //state = 2000
           if(iState==2500)  //cut receipt
           {
                 iState = 300;
                 if(strncmp(sCutFormDtl,"do ccut", 6)==0)
                 {
                      iLoopData = 1;
                      iState = 3000;
                 }
                 if(strcmp(sCutFormDtl,"rec cut")==0)
                 {
                      printer_PrintLineFeed();
                      printer_PrintLineFeed();
                      printer_PrintLineFeed();
                      printer_PrintLineFeed();
                      printer_PrintLineFeed();
                      printer_PrintReceiptHalfCu t();
                      OutputScreen(hwndEdit, "DATA->Receipt Cut");
                 }
                 if(strncmp(sCutFormDtl,"jo ucut", 6)==0 && strcmp(gSelectedPrinter,"n d70")!=0)
                 {
                      printer_PrintLineFeed();
                      printer_PrintLineFeed();
                      printer_PrintLineFeed();
                      printer_PrintLineFeed();
                      printer_PrintLineFeed();
                      printer_PrintReceiptHalfCu t();
                      OutputScreen(hwndEdit, "DATA->Journal Cut(EPSON)");
                 }
           } //state = 2500
           if(iState==3000) //command ejectdoc
           {
                 sprintf(sMsg, "DATA->%s", sFunction);
                 OutputScreen(hwndEdit, sMsg);
                 printer_EjectDoc();
                 iState = 300;
           }// state = 3000
           if(iState==4000) //command insertdoc
           {
                 sprintf(sMsg, "DATA->%s", sFunction);
                 OutputScreen(hwndEdit, sMsg);
                 if(strcmp(gSelectedPrinter ,"tmh5k2") ==0)
                 {
                      printer_PrintDoc();
                      printer_InsertDoc();
                 }
                 else
                 {
                      printer_InsertDoc();
                 }
                 iState = 300;
           }// state = 4000
           if(iState==5000) //command display
           {
                 sprintf(sMsg, "DATA->%s", sFunction);
                 OutputScreen(hwndEdit, sMsg);
                 printer_ClearDisplay();
                 printer_PrintDisplay(sData );
                 Mid(sData, 1, 20, sTemp2);
                 sprintf(sMsg, "DATA->%s", sTemp2);
                 OutputScreen(hwndEdit, sMsg);
                 Mid(sData, 21, 20, sTemp2);
                 sprintf(sMsg, "DATA->%s", sTemp2);
                 OutputScreen(hwndEdit, sMsg);
                 iState = 300;
           }// state = 5000
           if(iState==6000) //command load logo
           {
                 sprintf(sMsg, "DATA->%s", sFunction);
                 OutputScreen(hwndEdit, sMsg);
                 printer_Select();
                 printer_PrintReceipt();
                 //load_logo(sData);
                 //sprintf(sMsg, "DATA->%s", sData);
                 //OutputScreen(hwndEdit, sMsg);
                 iState = 300;
           } //satet = 6000
           if(iState==7000) //command print logo
           {
                 sprintf(sMsg, "DATA->%s", sFunction);
                 OutputScreen(hwndEdit, sMsg);
                 printer_PrintReceiptLogo() ;
                 OutputScreen(hwndEdit, "DATA->Receipt Logo");
                 iState = 300;
           }// state = 7000
           if(iState==8000) //command N/A
           {
                 sprintf(sMsg, "DATA->%s", sFunction);
                 OutputScreen(hwndEdit, sMsg);
                 iState = 300;
           } // state =8000
           if(iState==9000 || gGlobalOverwrite == 100) //command init printer
           {
                 OutputScreen(hwndEdit, "DATA->Force Init");
                 InitPrinter();
                 gGlobalOverwrite = 0;
                 iState = 500;
                 bLoop = 1;
           } // state =9000
      }// end while bLoop
      //MessageBox(hWnd, "OOOO", "OK", MB_OK);
}
int file_check(char *pfile)
{
      int handle;
      int l;
      //char sMsg[100];
      handle = open(pfile, O_RDONLY);
      l = filelength(handle);
      close(handle);
      return l;
}
int file_poll_lock(char *pfile)
{
      int tmp;
      FILE *fileNum;
      tmp = 0;
      fileNum = fopen(pfile, "r");
      if(fileNum != NULL)
      {
           tmp = 0;
           file_poll = fileNum;
      }
      else
           tmp=2;
      return tmp;
}
int file_poll_close(FILE *pfile)
{
      fclose(pfile);
      return 0;
}
int file_data_lock(char *pfile)
{
      int tmp;
      FILE *fileNum;
      tmp = 0;
      fileNum = fopen(pfile, "r");
      if(fileNum != NULL)
      {
           tmp = 0;
           file_data = fileNum;
      }
      else
           tmp=2;
      return tmp;
}
int file_data_close(FILE *pfile)
{
      fclose(pfile);
      return 0;
}
int file_truncate(FILE **pfile, char * pfilename)
{
      int tmp;
      FILE *fileNum;
      fclose(*pfile);
      fileNum = fopen(pfilename, "w");
      if(fileNum != NULL)
      {
           tmp = 0;
           *pfile = fileNum;
      }
      else
           tmp=2;
      return tmp;
}
int file_read(FILE *pfile, char buff[])
{
      if(pfile==NULL)
      {
           strcpy(buff,"EOF");
           return 0;
      }
      if(feof(pfile))
           strcpy(buff,"EOF");
      else
           fgets(buff, 2650, pfile);
      return 0;//buff;
}
int Mid(char *sSource, int nStartIdx, int nLength, char tmp[])
{
      //char tmp[1000];
      int nEnd=0;
      int i=0;
      int x=0;
      int l=0;
      strcpy(tmp, "");
      l = strlen(sSource);
      if(strlen(sSource<=0))
      {
           strcpy(tmp, "");
           return 0;
      }
      if(nStartIdx > 0) nStartIdx--;
      if(nLength==0)
           nEnd = l;
      else if(nLength > strlen(sSource))
           nEnd = l;
      else
           nEnd = nLength;
      x = nEnd - nStartIdx + 1;
      for(i=0;i<x;i++)
      {
           tmp[i] = sSource[i+nStartIdx];
      }
      tmp[i]=0;
      return 0;
}
void Trim(char pData[])
{
      char tmp[80]={0};
      int c=0;
      int i=0;
      // trim the white space
      while(pData[c]!=NULL)
      {
           if(pData[c] != ' ' && pData[c] != '\n')
           {
                 if(i<80)
                 {
                      tmp[i]=pData[c];
                      i++;
                 }
           }
           c++;
      }
      tmp[i]=NULL;
      strcpy(pData, tmp);
}
BOOL COMMAvailable(int port)
{
      return TRUE;
}
char *ReadCOMMInput()
{
      char sMsg[80]={0};
      int ret;
      if(hComm < 0)
           strcpy(sMsg, "");
      else
           ret = ReadComm(hComm, sMsg, 1024);
      return sMsg;
}
BOOL OpenPrinter(int nCOM)
{
      int err;
      char setting[30];
      char com[10];
      DCB dcb;
      BOOL bRet;
      if(hComm >= 0)return TRUE;
      bRet = TRUE;
      sprintf(com, "COM%d", nCOM);
      hComm = OpenComm(com, 1024, 512);
      if(hComm < 0)
  {
           MessageBox(hCommDvc, "Invalid COM port", "OK", MB_OK);
           bRet =FALSE;
           return bRet;
      }
      if(strcmp(gSelectedPrinter , "tmh5k2")==0)
           sprintf(setting, "COM%d:%d,%c,%d,%d",nCOM,9 600,'n',8, 1);
      if(strcmp(gSelectedPrinter , "nd70")==0)
           sprintf(setting, "COM%d:%d,%c,%d,%d",nCOM,9 600,'o',8, 1);
      else
           sprintf(setting, "COM%d:%d,%c,%d,%d",nCOM,9 600,'n',8, 1);
      err = BuildCommDCB(setting, &dcb);
      if(err<0)
      {
           MessageBox(hCommDvc, "Error BuildDCB", "OK", MB_OK);
           bRet =FALSE;
   return bRet;
      }
      dcb.fRtsDisable=0;
      dcb.fDtrDisable=0;
      err = SetCommState(&dcb);
      if(err<0)
      {
           MessageBox(hCommDvc, "Error SetCommState", "OK", MB_OK);
           bRet =FALSE;
      }
      else
      {
           SendMessage(hWndBtnDvc, WM_SETTEXT, 0, (LPARAM)"CloseCOMM");
      }
      return bRet;
}
void ClosePrinter()
{
      if(hComm < 0)return;
      CloseComm(hComm);
  hComm = -1;
      SendMessage(hWndBtnDvc, WM_SETTEXT, 0, (LPARAM)"OpenCOMM");
}
void cmdCOMStatus()
{
      char setting[12]={0};
      char sMsg[30]={0};
      if(strcmp(gSelectedPrinter , "nd70") == 0)
           strcpy(setting, "9600,O,8,1");
      else
           strcpy(setting, "9600,N,8,1");
      if(hComm < 0)
      {
           OutputScreen(hwndEditDvc, "Close COM Port.");
           sprintf(sMsg, "Setting -> %s", setting);
           OutputScreen(hwndEditDvc, sMsg);
      }
}
void SendMsg(char *pMsg)
{
      char *input;
      char sMsg[80]={0};
      int i=0;
      for(i=0;i<2000;i++)
      {
        ;
      }
      cmdCOMStatus();
      if(hComm <= 0)
      {
           WriteComm(hComm, pMsg, strlen(pMsg));
           input = ReadCOMMInput();
           sprintf(sMsg, "Status : [%s].", input);
           OutputScreen(hwndEditDvc, sMsg);
      }
      else
           OutputScreen(hwndEditDvc, "Status : COM Port NOT Opened.");
}
void InitPrinter()
{
      OutputScreen(hwndEditDvc, "COMMAND-> Init printer");
      SendMsg(CmdInit);
      printer_PrintDisplay ("                     ");
}
void load_epson_tmh5k2()
{
      char sSelectPrt[10]={0};
      char sSelectPrtDoc[10]={0};
      CmdPrinter[0]=0x1B;CmdPrin ter[1]=0x3 D;CmdPrint er[2]=0x01 ;CmdPrinte r[3]=0;
      sSelectPrtDoc[0]=0x1B;sSel ectPrtDoc[ 1]=0x0C;sS electPrtDo c[2]=0;sSe lectPrtDoc [3]=0x1B;
      sSelectPrtDoc[4]=0x63;sSel ectPrtDoc[ 5]=0x30;sS electPrtDo c[6]=0x04; sSelectPrt Doc[7]=0x1 B;
      sSelectPrtDoc[8]=0x61;sSel ectPrtDoc[ 9]=0x02;sS electPrtDo c[10]=0;
 Print_LineFeed[0]=0x0A;Pri nt_LineFee d[1]=0;
 Print_CR[0]=0x0D;Print_CR[ 1]=0;
 Print_HomeCursor[0]=0x1B;P rint_HomeC ursor[1]=0 x3C;Print_ HomeCursor [2]=0;
 CmdInit[0]=0x10;CmdInit[1] =0x14;CmdI nit[2]=0x0 8;CmdInit[ 3]=0x01;Cm dInit[4]=0 x03;CmdIni t[5]=0x20;
 CmdInit[6]=0x01;CmdInit[7] =0x06;CmdI nit[8]=0x0 2;CmdInit[ 9]=0x08;Cm dInit[10]= 0x10;CmdIn it[11]=0x0 2;
 CmdInit[12]=0x1B;CmdInit[1 3]=0x40;Cm dInit[14]= 0;
 CmdDisplay[0]=0x1B;CmdDisp lay[1]=0x3 D;CmdDispl ay[2]=0x02 ;CmdDispla y[3]=0;
 CmdDoc[0]=0x1B;CmdDoc[1]=0 x0C;CmdDoc [2]=0;CmdD oc[3]=0x1B ;CmdDoc[4] =0x61;CmdD oc[5]=0x02 ;
 CmdDoc[6]=0x1B;CmdDoc[7]=0 x63;CmdDoc [8]=0x30;C mdDoc[9]=0 x04;CmdDoc [10]=0;
 CmdDoc_Eject[0]=0x0C;CmdDo c_Eject[1] =0;
 CmdDoc_Insert[0]=0x1B;CmdD oc_Insert[ 1]=0x19;Cm dDoc_Inser t[2]=0;
 CmdDoc_Release[0]=0x1B;Cmd Doc_Releas e[1]=0x71; CmdDoc_Rel ease[2]=0;
 CmdDoc_Feed[0]=0x1B;CmdDoc _Feed[1]=0 x58;CmdDoc _Feed[2]=0 x32;CmdDoc _Feed[3]=0 x00;CmdDoc _Feed[4]=0 ;
 strcpy(CmdReceipt, CmdPrinter);
 CmdReceipt[3]=0x1B;CmdRece ipt[4]=0x6 1;CmdRecei pt[5]=0x01 ;CmdReceip t[6]=0;
 CmdReceipt_HalfCut[0]=0x1B ;CmdReceip t_HalfCut[ 1]='=';Cmd Receipt_Ha lfCut[2]=0 x01;CmdRec eipt_HalfC ut[3]=0x1D ;
 CmdReceipt_HalfCut[4]=0x56 ;CmdReceip t_HalfCut[ 5]=0x00;Cm dReceipt_H alfCut[6]= 0;
 CmdReceipt_FullCut[0]=0x1B ;CmdReceip t_FullCut[ 1]='=';Cmd Receipt_Fu llCut[2]=0 x01;CmdRec eipt_FullC ut[3]=0x1D ;
 CmdReceipt_FullCut[4]=0x56 ;CmdReceip t_FullCut[ 5]=0x01;Cm dReceipt_F ullCut[6]= 0;
 CmdReceipt_LogoPrint[0]=0x 1D;CmdRece ipt_LogoPr int[1]='/' ;CmdReceip t_LogoPrin t[2]=0x03; CmdReceipt _LogoPrint [3]=0x0A;
 CmdReceipt_LogoPrint[4]=0;
 Receipt_LogoLoad_Start[0]= 0x1B;Recei pt_LogoLoa d_Start[1] =0x26;Rece ipt_LogoLo ad_Start[2 ]=0x03;
 Receipt_LogoLoad_Start[3]= 0x00;Recei pt_LogoLoa d_Start[4] =0x00;Rece ipt_LogoLo ad_Start[5 ]=0x01;
 Receipt_LogoLoad_Start[6]= 0x01;Recei pt_LogoLoa d_Start[7] =0;
 Receipt_LogoLoad_Data[0]=0 x1B;Receip t_LogoLoad _Data[1]=0 x26;Receip t_LogoLoad _Data[2]=0 x03;
 Receipt_LogoLoad_Data[3]=0 x01;Receip t_LogoLoad _Data[4]=0 x00;Receip t_LogoLoad _Data[5]=0 x8C;
 Receipt_LogoLoad_Data[6]=0 ;
 Receipt_LogoLoad_End[0]=0x 1B;Receipt _LogoLoad_ End[1]=0x2 6;Receipt_ LogoLoad_E nd[2]=0x03 ;
 Receipt_LogoLoad_End[3]=0x FF;Receipt _LogoLoad_ End[4]=0x0 0;Receipt_ LogoLoad_E nd[5]=0x00 ;
 Receipt_LogoLoad_End[6]=0;
 strcpy(CmdJournal, CmdReceipt);
 ClosePrinter();
 OpenPrinter(gSelectedPort) ;
 InitPrinter();
}
void load_sni_nd70()
{
      char sSelectPrt[10]={0};
      char sSelectPrtDoc[10]={0};
      CmdPrinter[0]=0x1B;CmdPrin ter[1]=0x5 8;CmdPrint er[2]=0x31 ;CmdPrinte r[3]=0x01; CmdPrinter [4]=0;
      strcpy(sSelectPrtDoc, CmdPrinter);
      sSelectPrtDoc[4]=27;sSelec tPrtDoc[5] =99;sSelec tPrtDoc[6] =48;sSelec tPrtDoc[7] =8;
      sSelectPrtDoc[8]=0;
 Print_LineFeed[0]=0x0A;Pri nt_LineFee d[1]=0;
 Print_CR[0]=0x0D;Print_CR[ 1]=0;
 Print_HomeCursor[0]=27;Pri nt_HomeCur sor[1]=60; Print_Home Cursor[2]= 0;
 CmdInit[0]=0x10;CmdInit[1] =0x02;CmdI nit[2]=0x1 B;CmdInit[ 3]=0x40;Cm dInit[4]=2 7;CmdInit[ 5]=33;
 CmdInit[6]=03;CmdInit[7]=0 ;
 CmdDisplay[0]=27;CmdDispla y[1]=8;Cmd Display[2] =49;CmdDis play[3]=2; CmdDisplay [4]=0;
 strcpy(CmdDoc, CmdPrinter);
 CmdDoc[4]=27;CmdDoc[5]=99;
 CmdDoc[6]=48;CmdDoc[7]=4;C mdDoc[8]=0 ;
 CmdDoc_Eject[0]=12;CmdDoc_ Eject[1]=0 ;
 CmdDoc_Insert[0]=27;CmdDoc _Insert[1] =25;CmdDoc _Insert[2] =0;
 CmdDoc_Release[0]=27;CmdDo c_Release[ 1]=113;Cmd Doc_Releas e[2]=0;
 CmdDoc_Feed[0]=27;CmdDoc_F eed[1]=88; CmdDoc_Fee d[2]=50;Cm dDoc_Feed[ 3]=0;
 strcpy(CmdReceipt, CmdPrinter);
 CmdReceipt[4]=27;CmdReceip t[5]=99;Cm dReceipt[6 ]=48;CmdRe ceipt[7]=2 ;CmdReceip t[8]=0;
 CmdReceipt_HalfCut[0]=27;C mdReceipt_ HalfCut[1] =109;CmdRe ceipt_Half Cut[2]=0;
 CmdReceipt_FullCut[0]=27;C mdReceipt_ FullCut[1] =105;CmdRe ceipt_Full Cut[2]=0;
 CmdReceipt_LogoPrint[0]=27 ;CmdReceip t_LogoPrin t[1]=111;C mdReceipt_ LogoPrint[ 2]=0;
 Receipt_LogoLoad_Start[0]= 0x1B;Recei pt_LogoLoa d_Start[1] =0x26;Rece ipt_LogoLo ad_Start[2 ]=0x03;
 Receipt_LogoLoad_Start[3]= 0x00;Recei pt_LogoLoa d_Start[4] =0x00;Rece ipt_LogoLo ad_Start[5 ]=0x01;
 Receipt_LogoLoad_Start[6]= 0x01;Recei pt_LogoLoa d_Start[7] =0;
 Receipt_LogoLoad_Data[0]=0 x1B;Receip t_LogoLoad _Data[1]=0 x26;Receip t_LogoLoad _Data[2]=0 x03;
 Receipt_LogoLoad_Data[3]=0 x01;Receip t_LogoLoad _Data[4]=0 x00;Receip t_LogoLoad _Data[5]=0 x8C;
 Receipt_LogoLoad_Data[6]=0 ;
 Receipt_LogoLoad_End[0]=0x 1B;Receipt _LogoLoad_ End[1]=0x2 6;Receipt_ LogoLoad_E nd[2]=0x03 ;
 Receipt_LogoLoad_End[3]=0x FF;Receipt _LogoLoad_ End[4]=0x0 0;Receipt_ LogoLoad_E nd[5]=0x00 ;
 Receipt_LogoLoad_End[6]=0;
 strcpy(CmdJournal, CmdPrinter);
 CmdJournal[4]=27;CmdJourna l[5]=99;Cm dJournal[6 ]=48;CmdJo urnal[7]=1 ;CmdJourna l[8]=0;
 ClosePrinter();
 OpenPrinter(gSelectedPort) ;
 InitPrinter();
}
void printer_PrintDisplay(char pMsg[])
{
      char sMsg[80];
      OutputScreen(hwndEditDvc, "COMMAND-> Print Display");
      SendMsg(CmdDisplay);
      if(strcmp(gSelectedPrinter ,"nd70") == 0)
      {
           //sMsg = Mid(pMsg, 1, 20);
           Mid(pMsg, 1, 20, sMsg);
           strcpy(sMsg, Print_CR);
           strcpy(sMsg, Print_LineFeed);
           SendMsg(sMsg);
           Mid(pMsg, 21, 20, sMsg);
           SendMsg(sMsg);
      }
      else
      {
           //sMsg = Mid(pMsg, 1, 40);
           Mid(pMsg, 1, 40, sMsg);
           SendMsg(sMsg);
      }
}
void printer_PrintLineFeed()
{
      OutputScreen(hwndEditDvc, "COMMAND-> LineFeed");
      SendMsg(Print_LineFeed);
}
void printer_PrintReceipt()
{
      OutputScreen(hwndEditDvc, "COMMAND-> Select Peripheral Receipt Station");
  SendMsg(CmdReceipt);
}
void printer_PrintReceiptHalfCu t()
{
      char msg[80];
      OutputScreen(hwndEditDvc, "COMMAND-> Receipt 1/2 Cut");
      if(strcmp(gSelectedPrinter ,"nd70") == 0)
      {
           strcpy(msg, CmdReceipt);
           strcat(msg, CmdReceipt_HalfCut);
           SendMsg(msg);
      }
      else
           SendMsg(CmdReceipt_HalfCut );
}
void printer_PrintReceiptFullCu t()
{
      char msg[80];
      OutputScreen(hwndEditDvc, "COMMAND-> Receipt Full Cut");
      strcpy(msg, CmdReceipt);
      strcat(msg, CmdReceipt_FullCut);
      SendMsg(msg);
}
void printer_PrintReceiptLogo()
{
      char msg[80];
      OutputScreen(hwndEditDvc, "COMMAND-> Receipt Print Logo");
  strcpy(msg, CmdReceipt);
      strcat(msg, CmdReceipt_LogoPrint);
      SendMsg(msg);
}
void printer_ClearDisplay()
{
      char msg[80];
      OutputScreen(hwndEditDvc, "COMMAND-> Clear Display");
      SendMsg(CmdDisplay);
      if(strcmp(gSelectedPrinter ,"nd70") == 0)
      {
           strcpy(msg, Print_LineFeed);
           strcat(msg, Print_LineFeed);
           strcat(msg, Print_CR);
           SendMsg(msg);
      }
      else
      {
           strcpy(msg, Print_CR);
           strcat(msg, Print_LineFeed);
           strcat(msg, Print_LineFeed);
           SendMsg(msg);
      }
}
void printer_Print(char pMsg[])
{
      OutputScreen(hwndEditDvc, "COMMAND-> Print");
      //MessageBox(hWnd, pMsg, "PRT", MB_OK);
      SendMsg(pMsg);
}
void printer_Select()
{
      OutputScreen(hwndEditDvc, "COMMAND-> Printer Peripheral Select");
      SendMsg(CmdPrinter);
}
void printer_EjectDoc()
{
      OutputScreen(hwndEditDvc, "COMMAND-> Eject Doc");
      SendMsg(CmdDoc_Eject);
}
void printer_InsertDoc()
{
      OutputScreen(hwndEditDvc, "COMMAND-> Insert Doc");
      SendMsg(CmdDoc_Insert);
}
void printer_ReleaseDoc()
{
      OutputScreen(hwndEditDvc, "COMMAND-> Release Doc");
      SendMsg(CmdDoc_Release);
}
void printer_FeedDoc()
{
      OutputScreen(hwndEditDvc, "COMMAND-> Feed Doc");
      SendMsg(CmdDoc_Feed);
}
void printer_PrintDoc()
{
      OutputScreen(hwndEditDvc, "COMMAND-> Select Peripheral Document Station");
      SendMsg(CmdDoc);
}
void printer_PrintJournal()
{
      OutputScreen(hwndEditDvc, "COMMAND-> Print Journal");
      SendMsg(CmdJournal);
}
void printer_PrintCR()
{
      OutputScreen(hwndEditDvc, "COMMAND-> Carriage Return");
      SendMsg(Print_CR);
}
void load_logo(char *pData)
{
      int iLines=0;
      int iCtr1=0;
      int iLastCtr=0;
      int iTrack=0;
      int iBoolean=0;
  char tmp[80]={0};
      iLogoData = (int)strlen(pData) / iDataPerTrack / 8;
      iLogoData--;
      if(iLogoData <=0 || iLogoData > 80)
      {
           MessageBox(hWnd, "Error in defining Logo Data.", "Logo Error", MB_ICONSTOP);
   return;
      }
      iLastCtr = 1;
      iTrack = 0;
      iLines = 0;
      for(iCtr1=1; iCtr1<=strlen(pData); iCtr1++)
      {
           Mid(pData, iCtr1, 1, tmp);
           if(strcmp(tmp, " ")==0)
                 iBoolean = 0;
           else
           {
                 iBoolean = 0;
                 switch(iTrack)
                 {
                      case 0:
                            iBoolean = 0x80;
                            break;
                      case 1:
                            iBoolean = 0x40;
                            break;
                      case 2:
                            iBoolean = 0x20;
                            break;
                      case 3:
                            iBoolean = 0x10;
                            break;
                      case 4:
                            iBoolean = 0x08;
                            break;
                      case 5:
                            iBoolean = 0x04;
                            break;
                      case 6:
                            iBoolean = 0x02;
                            break;
                      case 7:
                            iBoolean = 0x01;
                            break;
                 }
                 sLogoData[iLines][iLastCtr ] = sLogoData[iLines][iLastCtr ] | iBoolean;
                 iLastCtr++;
                 if((iLastCtr % (iDataPerTrack+1))==0)
                 {
                      iLastCtr = 1;
                      iTrack++;
                      if(iTrack > 7)
                      {
                            iTrack = 0;
                            iLines++;
                            if (iLines > iLogoData)
                                 goto q;
                      }
                 }
           }
      }
      q:
      for(iCtr1=0; iCtr1<=iDataPerTrack; iCtr1++)
      {
           strcpy(tmp, "");
           for(iTrack=1; iTrack<=iDataPerTrack; iTrack++)
           {
                 strcat(tmp, (char)sLogoData[iCtr1][iTr ack]);
           }
      }
      if(strcmp(gSelectedPrinter , "nd70") == 0)
           decode_nd70();
      else
           decode_tmh5k2();
}
void decode_nd70()
{
      int iCtr=0;
      int iCtr2=0;
      int iTrack=0;
      int l_iLogoTrack=0;
      char l_sLogoData[80]={0};
      char tmp[80]={0};
      if(iLogoData <= 0) return;
      SendMsg(Receipt_LogoLoad_S tart);
      iCtr2 = 2;
      for(iCtr=0; iCtr<=iLogoData; iCtr++)
      {
           strcpy(l_sLogoData, "");
           strcpy(tmp, "");
           for(l_iLogoTrack=1; l_iLogoTrack<=strlen(Recei pt_LogoLoa d_Data);l_ iLogoTrack ++)
           {
                 if(l_iLogoTrack==4)
                      strcat(l_sLogoData, (char)(iCtr + 1));
                 else
                 {
                      Mid(Receipt_LogoLoad_Data, l_iLogoTrack, 1, tmp);
                      strcat(l_sLogoData, tmp);
                 }
           }
           SendMsg(l_sLogoData);
           for(iTrack=1; iTrack <= iDataPerTrack; iTrack++)
           {
                 strcat(l_sLogoData, (char)sLogoData[iCtr][iTra ck]);
                 SendMsg((char)sLogoData[iC tr][iTrack ]);
     iCtr2++;
           }
      }
      strcpy(l_sLogoData, "");
  for(l_iLogoTrack=1; l_iLogoTrack<=strlen(Recei pt_LogoLoa d_Data);l_ iLogoTrack ++)
      {
        if(l_iLogoTrack==4)
                 strcat(l_sLogoData, (char)(6));
           else
           {
                 Mid(Receipt_LogoLoad_Data, l_iLogoTrack, 1, tmp);
                 strcat(l_sLogoData, tmp);
           }
      }
      SendMsg(l_sLogoData);
  for(iTrack=1; iTrack <= iDataPerTrack; iTrack++)
      {
            strcat(l_sLogoData, (char)(0));
    SendMsg((char)0);
      }
      SendMsg(Receipt_LogoLoad_E nd);
}
void decode_tmh5k2()
{
      int iCtr=0;
      int iCtr2=0;
      int iTrack=0;
      char tmp[80]={0};
      if(iLogoData <= 0) return;
      strcpy(tmp, (char)0x1D);
      strcat(tmp, "*");
      strcpy(tmp, (char)18);
      strcpy(tmp, (char)5);
      SendMsg(tmp);
      iCtr2 = 0;
      for(iCtr=1; iCtr<=iDataPerTrack; iCtr++)
      {
           for(iTrack=0; iTrack <= iLogoData; iTrack++);
           {
                 SendMsg((char)sLogoData[iT rack][iCtr ]);
                 iCtr2++;
           }
      }
      iCtr = 18 * 5 * 8;
      if(iCtr2 < iCtr)
      {
           for(iTrack=iCtr2; iTrack<=iCtr; iTrack++)
           {
                 SendMsg((char)0);
           }
      }
      strcpy(tmp, (char)0x1B);
      strcat(tmp, "U");
      SendMsg(tmp);
}
++++++++++++++++++++++++++ ++++++++++ ++++
This is the input source file.
++++++++++++++++++++++++++ ++++++++++ ++++
COMMAND=print Â
LENGTH=63 Â Â
LENGTH_COL=32 Â Â
CUTFORM=nd70 Â
CUTFORM_DTL=rec Â
DATA====================== ========== = Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â
COMMAND=print Â
LENGTH=50 Â Â
LENGTH_COL=32 Â Â
CUTFORM=nd70 Â
CUTFORM_DTL=rec Â
DATA=RECOVERY Â : BERMULA Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â
COMMAND=print Â
LENGTH=63 Â Â
LENGTH_COL=32 Â Â
CUTFORM=nd70 Â
CUTFORM_DTL=rec Â
DATA=Trkh: 02/03/2004, Masa: 13:29:21 Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â
COMMAND=print Â
LENGTH=63 Â Â
LENGTH_COL=32 Â Â
CUTFORM=nd70 Â
CUTFORM_DTL=rec Â
DATA====================== ========== = Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â
COMMAND=print Â
LENGTH=63 Â Â
LENGTH_COL=32 Â Â
CUTFORM=nd70 Â
CUTFORM_DTL=rec Â
DATA=Transaksi : Â Â Â Â Â Â 00246155 Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â
COMMAND=print Â
LENGTH=63 Â Â
LENGTH_COL=32 Â Â
CUTFORM=nd70 Â
CUTFORM_DTL=rec Â
DATA====================== ========== = Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â
COMMAND=print Â
LENGTH=50 Â Â
LENGTH_COL=32 Â Â
CUTFORM=nd70 Â
CUTFORM_DTL=rec Â
DATA=RECOVERY Â : SELESAI Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â
COMMAND=print Â
LENGTH=63 Â Â
LENGTH_COL=32 Â Â
CUTFORM=nd70 Â
CUTFORM_DTL=rec Â
DATA=Trkh: 02/03/2004, Masa: 13:29:24 Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â
COMMAND=print Â
LENGTH=63 Â Â
LENGTH_COL=32 Â Â
CUTFORM=nd70 Â
CUTFORM_DTL=rec Â
DATA====================== ========== = Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â
COMMAND=print Â
LENGTH=61 Â Â
LENGTH_COL=32 Â Â
CUTFORM=nd70 Â
CUTFORM_DTL=reccut Â
DATA=********************* ********** * Â Â Â Â Â Â Â Â Â Â Â Â Â Â
COMMAND=print Â
LENGTH=220 Â
LENGTH_COL=32 Â Â
CUTFORM=nd70 Â
CUTFORM_DTL=reccut Â
DATA=---- Laporan Sign On J/Wang ----ID J/Wang: 4417J01 Â P/K: 02 Â Â W.Pendahuluan: RM Â Â Â Â Â 0.00 Trkh: 02/03/2004, Masa: 13:30:20================== ========== ==== Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â
COMMAND=printlogo Â
LENGTH=25 Â Â
LENGTH_COL=140 Â
CUTFORM=nd70 Â
CUTFORM_DTL=rec Â
LOGO_PRINT Â Â Â Â Â Â Â Â Â Â
COMMAND=aprint Â
LENGTH=1033 Â
LENGTH_COL=32 Â Â
CUTFORM=nd70 Â
CUTFORM_DTL=reccut Â
DATA=    Welcome Friend To        ABC Comm Limited      -------------------------- ------Nomb or Transaksi :    0024615500459089 KADFON RM 5.00     039 90392              5.00   1  RM     5.00         ----------------Jumlah Item   RM     5.00 00459090 KADFON RM 20.00     039 90394              20.00   2  RM     40.00         ----------------Jumlah Item   RM     40.00         ----------------Jumlah Kutipan  RM     45.00 Jumlah Cukai   RM     0.00 Jumlah (Diskaun)RM     0.00         ----------------Jum.Perlu Bayar RM     45.00         ================Bayaran:             TUNAI      RM     45.00 -------------------------- ------    Sila Datang Lagi          TERIMA KASIH      ========================== ======1417 02 4417J01 02032004 13:30:55                                                                    Â
++++++++++++++++++++++++++ ++++++++++ ++++
Hope somebody can assist me on this code debugging.
Thanks.
Expected output
++++++++++++++++++++++++++
RECOVERY Â : BERMULA Â Â Â Â Â Â
Trkh: 02/03/2004, Masa: 13:29:21
==========================
Transaksi : Â Â Â Â Â Â 00246155
==========================
RECOVERY Â : SELESAI Â Â Â Â Â Â
Trkh: 02/03/2004, Masa: 13:29:24
==========================
**************************
---- Laporan Sign On J/Wang ----
ID J/Wang: 4417J01 Â P/K: 02 Â Â
W.Pendahuluan: RM Â Â Â Â Â 0.00
Trkh: 02/03/2004, Masa: 13:30:20
==========================
   Welcome Friend To    Â
   ABC Comm Limited     Â
--------------------------
Nombor Transaksi : Â Â Â 00246155
00459089 KADFON RM 5.00 Â Â Â Â
039 90392 Â Â Â Â Â Â Â Â Â Â Â
  5.00   1  RM     5.00
        ----------------
Jumlah Item   RM     5.00
00459090 KADFON RM 20.00 Â Â Â Â
039 90394 Â Â Â Â Â Â Â Â Â Â Â
  20.00   2  RM     40.00
        ----------------
Jumlah Item   RM     40.00
        ----------------
Jumlah Kutipan  RM     45.00
Jumlah Cukai   RM     0.00
Jumlah (Diskaun)RM Â Â Â Â 0.00
        ----------------
Jum.Perlu Bayar RM Â Â Â Â 45.00
        ================
Bayaran: Â Â Â Â Â Â Â Â Â Â Â Â
TUNAI Â Â Â Â Â RM Â Â Â Â 45.00
--------------------------
    Sila Datang Lagi    Â
     TERIMA KASIH     Â
==========================
141702 4417J01 02032004 13:30:55
++++++++++++++++++++++++++
But the output happen to be like this, which is not correct
++++++++++++++++++++++++++
==========================
RECOVERY Â : BERMULA Â Â Â Â Â Â Â
Trkh: 02/03/2004, Masa: 13:29:21
==========================
Transaksi : Â Â Â Â Â Â 00246155
==========================
RECOVERY Â : SELESAI Â Â Â Â Â Â Â
Trkh: 02/03/2004, Masa: 13:29:24
==========================
**************************
---- Laporan Sign On J/Wang ----I
   Welcome Friend To     Â
   Welcome Friend To     Â
++++++++++++++++++++++++++
This is my code.
++++++++++++++++++++++++++
#define  STRICT
#include <windows.h>
#include <windowsx.h>
#include <string.h>
#include <stdio.h>
#include <io.h>
#include <fcntl.h>
#pragma hdrstop
#include "helpex.h"
#include "helpids.h"
#pragma argsused
int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
                                  LPSTR lpCmdLine, int nCmdShow)
{
      MSG msg;
      if (!hPrevInstance)
            if (!InitApplication(hInstanc
            return (FALSE);
      if (!InitInstance(hInstance, nCmdShow))
            return (FALSE);
      while (GetMessage(&msg, NULL, 0, 0)) {
           /* Only translate message if it is not an accelerator message */
           if (!TranslateAccelerator(hWn
                 TranslateMessage(&msg);
                 DispatchMessage(&msg);
           }
      }
      return (msg.wParam);
}
BOOL InitApplication(HINSTANCE hInstance)
{
      WNDCLASS wc;
      wc.style = 0;
      wc.lpfnWndProc = MainWndProc;
      wc.cbClsExtra = 0;
      wc.cbWndExtra = 0;
      wc.hInstance = hInstance;
      wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
      wc.hCursor = LoadCursor(NULL, IDC_ARROW);
      wc.hbrBackground = (HBRUSH)( COLOR_MENU+1 ); //GetStockObject(WHITE_BRU
      wc.lpszMenuName ="MainMenu";
      wc.lpszClassName = "PRNDRV16";
      RegisterClass(&wc);
      wc.style = 0;
      wc.lpfnWndProc = DeviceComm;
      wc.cbClsExtra = 0;
      wc.cbWndExtra = 0;
      wc.hInstance = hInstance;
      wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
      wc.hCursor = LoadCursor(NULL, IDC_ARROW);
      wc.hbrBackground = (HBRUSH)( COLOR_MENU+1 ); //GetStockObject(WHITE_BRU
      wc.lpszMenuName =NULL;
      wc.lpszClassName = "CommDvc";
      RegisterClass(&wc);
      return TRUE;
}
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
      char sMsg[80];
  char crlf[3]={13, 10, 0};
      hInst = hInstance;
      hAccTable = LoadAccelerators(hInst, "HelpexAcc");
      hWnd = CreateWindow(
            "PRNDRV16",
            "TMB Print Driver, Siemens ISB 2004",
            WS_OVERLAPPEDWINDOW,
            100, //CW_USEDEFAULT,
            100, //CW_USEDEFAULT,
            350, //CW_USEDEFAULT,
            500, //CW_USEDEFAULT,
            NULL,
            NULL,
            hInstance,
            NULL
            );
      if (!hWnd)
            return (FALSE);
      ShowWindow(hWnd, nCmdShow);
      UpdateWindow(hWnd);
      hCommDvc = CreateWindow(
            "CommDvc",
            "Siemens Device Control",
            WS_OVERLAPPEDWINDOW,
            10,  //CW_USEDEFAULT,
            10,  //CW_USEDEFAULT,
            300, //CW_USEDEFAULT,
            350, //CW_USEDEFAULT,
            NULL,
            NULL,
            hInstance,
            NULL
            );
      if (!hCommDvc)
            return (FALSE);
      ShowWindow(hCommDvc, nCmdShow);
      UpdateWindow(hCommDvc);
      fnLoadSetting();
      gGlobalEnd = 0;
      gGlobalOverwrite = 0;
      gIdleState = 0;
      if ((gSelectedPort == 1) | (gSelectedPort == 2))
      {
           if(!OpenPrinter(gSelectedP
           {
                 ExitSystem();
           }
           else
           {
                 if(gSelectedPort==1)
                 {
                      SetMenuState(1, CM_COM1, TRUE);
                      SetMenuState(1, CM_COM2, FALSE);
                 }
                 else if(gSelectedPort==2)
                 {
                      SetMenuState(1, CM_COM1, FALSE);
                      SetMenuState(1, CM_COM2, TRUE);
                 }
           }
      }
      else
      {
            sprintf(sMsg, "COM%d is invalid. Default to COM1 port.", gSelectedPort);
            MessageBox(hWnd, sMsg, "DEFAULT", MB_OK);
            if(!OpenPrinter(gSelectedP
                 ExitSystem();
            else
            {
                 if(gSelectedPort==1)
                      SetMenuState(1, CM_COM1, TRUE);
                 else
                      SetMenuState(1, CM_COM2, TRUE);
            }
      }
      if(strcmp("tmh5k2", gSelectedPrinter)==0)
      {
                 load_epson_tmh5k2();
                 SetMenuState(2, CM_EPSON, TRUE);
                 SetMenuState(2, CM_ND70, FALSE);
                 OutputScreen (hwndEdit, "COMMAND-> EPSON tmh5000ii Command Set Loaded");
      }
      else if(strcmp("nd70", gSelectedPrinter)==0)
      {
                 load_sni_nd70();
                 SetMenuState(2, CM_ND70, TRUE);
                 SetMenuState(2, CM_EPSON, FALSE);
                 OutputScreen (hwndEdit, "COMMAND-> Siemens Nixdorf nd70 Command Set Loaded");
      }
      else
      {
                 load_epson_tmh5k2();
                 strcpy(gSelectedPrinter, "tmh5k2");
                 SetMenuState(2, CM_EPSON, TRUE);
                 SetMenuState(2, CM_ND70, FALSE);
                 OutputScreen (hwndEdit, "COMMAND-> EPSON tmh5000ii Command Set Loaded");
      }
      OutputScreen (hwndEdit, "COMMAND-> Init Printer");
      strcpy(gsPollFile, "C:\\tmp\\devpoll");
      strcpy(gsDataFile, "C:\\tmp\\devcon");
      return (TRUE);
}
#pragma warn -eff
LRESULT CALLBACK _export MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
      DLGPROC lpProcAbout;
      DWORD  dwHelpContextId;
      //HDC hDC;
      PAINTSTRUCT ps;
      //TIMERPROC fnTimer;
      switch (message) {
            case WM_CREATE:
                 hwndEdit = CreateWindow(
                            "EDIT",   // predefined class
                            NULL,    // no window title
                            WS_CHILD | WS_VISIBLE | WS_BORDER | WS_HSCROLL | WS_VSCROLL |
                                 ES_LEFT | ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL |
                                 ES_WANTRETURN,
                            0, 0, 0, 0, // set size in WM_SIZE message
                            hWnd,    // parent window
                            (HMENU) GetMenu(hWnd),  // edit control ID
                            (HINSTANCE) hInst, // associate it with the application instance
                            NULL);
                 hWndBtn = CreateWindow(
                            "BUTTON",   // predefined class
                            "Reset Printer",    // no window title
                            WS_CHILD | WS_VISIBLE | WS_BORDER,
                            240, 410, 100, 30, // set size in WM_SIZE message
                            hWnd,    // parent window
                            (HMENU) CMD_RESET, //GetMenu(hWnd),  // edit control ID
                            (HINSTANCE) hInst, // associate it with the application instance
                            NULL);
                 SetTimer(hWnd, TIMER_ID, 2000, NULL);
                 break;
            case WM_QUIT:
                 ExitSystem();
                 break;
            case WM_TIMER:
                 if(wParam==TIMER_ID && !gBool)
                      OutputPoll();                 Â
                 break;
            case WM_SETFOCUS:
                      SetFocus(hwndEdit);
                      break;
            case WM_SIZE:
                      // Make the edit control the size of the window's
                      // client area.
                      MoveWindow(hwndEdit,
                            0, 0,      // starting x- and y-coordinates
                            LOWORD(lParam), // width of client area
                            HIWORD(lParam)-50, // height of client area
                            TRUE);
                      MoveWindow(hWndBtn,
                            LOWORD(lParam) - 110,      // starting x- and y-coordinates
                            HIWORD(lParam) - 35,
                            100, // width of client area
                            30, // height of client area
                            TRUE);
                      break;
            case WM_COMMAND:
                 switch (GET_WM_COMMAND_ID(wParam,
                 {
                      case CMD_RESET:
                            MessageBox(hWnd, "Reset Printer", "OK", MB_OK);
                            gGlobalOverwrite = 100;
                            break;
                      case CM_TSTCUT:
                            printer_PrintLineFeed();
                            printer_PrintLineFeed();
                            printer_PrintLineFeed();
                            printer_PrintLineFeed();
                            printer_PrintLineFeed();
                            printer_PrintReceiptHalfCu
                            OutputScreen (hwndEdit, "DATA-> Receipt Cut");
                            break;
                      case CM_TSTLOGO:
                            printer_PrintReceiptLogo()
                            OutputScreen (hwndEdit, "DATA-> Receipt Cut");
                            break;
                      case CM_TSTPRN:
                            OnMenuTestPrint();
                            break;
                      case CM_TSTDSP:
                            printer_ClearDisplay();
                            printer_PrintDisplay("----
                            break;
                      case CM_COM1:
                            SetMenuState(1, CM_COM1, FALSE);
                            SetMenuState(1, CM_COM2, FALSE);
                            if(OpenPrinter(1))
                            {
                                 InitPrinter();
                                 SetMenuState(1, CM_COM1, TRUE);
                                 gSelectedPort = 1;
                                 OutputScreen (hwndEdit, "COMMAND-> COM Port 1 Selected");
                            }
                            else
                            {
                                 OutputScreen (hwndEdit, "COMMAND-> COM Port 1 Open Failed");
                            }
                            break;
                      case CM_COM2:
                            SetMenuState(1, CM_COM1, FALSE);
                            SetMenuState(1, CM_COM2, FALSE);
                            if(OpenPrinter(2))
                            {
                                 InitPrinter();
                                 SetMenuState(1, CM_COM2, TRUE);
                                 gSelectedPort = 2;
                                 OutputScreen (hwndEdit, "COMMAND-> COM Port 2 Selected");
                            }
                            else
                            {
                                 OutputScreen (hwndEdit, "COMMAND-> COM Port 2 Open Failed");
                            }
                            break;
                      case CM_EPSON:
                            SetMenuState(2, CM_EPSON, TRUE);
                            SetMenuState(2, CM_ND70, FALSE);
                            load_epson_tmh5k2();
                            InitPrinter();
                            strcpy(gSelectedPrinter, "tmh5k2");
                            OutputScreen (hwndEdit, "COMMAND-> EPSON tmh5000ii Command Set Loaded");
                            break;
                      case CM_ND70:
                            SetMenuState(2, CM_EPSON, FALSE);
                            SetMenuState(2, CM_ND70, TRUE);
                            load_epson_tmh5k2();
                            InitPrinter();
                            strcpy(gSelectedPrinter, "nd70");
                            OutputScreen (hwndEdit, "COMMAND-> Siemens Nixdorf nd70 Command Set Loaded");
                            break;
                      case CM_ABOUT:
                            lpProcAbout = (DLGPROC)MakeProcInstance(
                            DialogBox(hInst, "AboutBox", hWnd, lpProcAbout);
                            FreeProcInstance((FARPROC)
                            break;
                      case CM_DVC:
                            SetMenuState(0, CM_DVC, TRUE);
                            ShowWindow(hCommDvc, SW_SHOW | SW_RESTORE);
                            UpdateWindow(hCommDvc);
                            break;
                      case CM_EXIT:
                            ExitSystem();
                            break;
                      default:
                            return (DefWindowProc(hWnd, message, wParam, lParam));
                 }
                 break;
            case WM_DESTROY:
                  KillTimer(hWnd, TIMER_ID);
                  WinHelp(hWnd,szHelpFileNam
      if(hComm >= 0)CloseComm(hComm);
                  PostQuitMessage(0);
      break;
            default:
      return (DefWindowProc(hWnd, message, wParam, lParam));
  }
      return 0L;
}
#pragma warn .eff
#pragma argsused
BOOL FAR PASCAL _export About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
  switch (message) {
            case WM_INITDIALOG:
                  return (TRUE);
    case WM_COMMAND:
                 if (GET_WM_COMMAND_ID(wParam,
        EndDialog(hDlg, TRUE);
        return (TRUE);
      }
                  break;
            case WM_DESTROY:
                 DestroyWindow(hDlg);
                 break;
      }
      return (FALSE);
}
BOOL FAR PASCAL _export DeviceComm(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
      switch (message) {
            //case WM_INITDIALOG:
            //       hCommDvc = hDlg;
            //   return (TRUE);
            case WM_CREATE:
                      hComm = -1;
                      hwndEditDvc = CreateWindow(
                            "EDIT",   // predefined class
                            NULL,    // no window title
                            WS_CHILD | WS_VISIBLE | WS_BORDER | WS_HSCROLL | WS_VSCROLL |
                                 ES_LEFT | ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL |
                                 ES_WANTRETURN,
                            0, 0, 0, 0, // set size in WM_SIZE message
                            hDlg,    // parent window
                            (HMENU) GetMenu(hWnd),  // edit control ID
                            (HINSTANCE) hInst, // associate it with the application instance
                            NULL);
                      hWndBtnDvc = CreateWindow(
                            "BUTTON",   // predefined class
                            "OpenCOMM",    // no window title
                            WS_CHILD | WS_VISIBLE | WS_BORDER,
                            180, 270, 100, 30, // set size in WM_SIZE message
                            hDlg,    // parent window
                            (HMENU) CMD_OPENPORT, //GetMenu(hWnd),  // edit control ID
                            (HINSTANCE) hInst, // associate it with the application instance
                            NULL);
                      break;
            case WM_COMMAND:
                 if (GET_WM_COMMAND_ID(wParam,
                 {
                      if(hComm >=0)
                            ClosePrinter();
                      else
                            OpenPrinter(gSelectedPort)
                 }
                 break;
            case WM_SIZE:
                      // Make the edit control the size of the window's
                      // client area.
                      MoveWindow(hwndEditDvc,
                            0, 0,      // starting x- and y-coordinates
                            LOWORD(lParam), // width of client area
                            HIWORD(lParam)-50, // height of client area
                            TRUE);
                      MoveWindow(hWndBtnDvc,
                            LOWORD(lParam) - 110,      // starting x- and y-coordinates
                            HIWORD(lParam) - 35,
                            100, // width of client area
                            30, // height of client area
                            TRUE);
                      break;
            case WM_SETFOCUS:
                      SetFocus(hWndBtnDvc);
                      break;
            case WM_DESTROY:
                 //DestroyWindow(hDlg);
                 ShowWindow(hDlg, SW_SHOW);
                 break;
            default:
                  return (DefWindowProc(hDlg, message, wParam, lParam));
      }
      return (FALSE);
}
void SetMenuState(int nPos, UINT nMenuID, BOOL fOwnerDraw)
{
      HMENU hMenu;
      //BOOL fOwnerDraw;
      hMenu = GetSubMenu(GetMenu(hWnd), nPos);
      //fOwnerDraw = GetMenuState(hMenu, nMenuID, MF_BYCOMMAND) & MF_CHECKED;
      CheckMenuItem(hMenu, nMenuID, MF_BYCOMMAND | (fOwnerDraw ? MF_CHECKED : MF_UNCHECKED));
}
void fnLoadSetting()
{
      WORD wReturn;
      int nRet;
      char sINI[25];
      char szBuf[25];
      //char sMsg[80];
      wReturn = GetWindowsDirectory((LPSTR
      strcat(sINI, "\\tmshell.ini");
      nRet = GetPrivateProfileString("T
                                                             szBuf, sizeof(szBuf), sINI);
      if(nRet == 0)
           MessageBox(hWnd, "Application Start Failed, Parameters:TMB Printer->PRT Referential Error!!", "ERROR", MB_ICONSTOP);
      else
           strcpy(gSelectedPrinter, szBuf);
      nRet = GetPrivateProfileString("T
                                                             szBuf, sizeof(szBuf), sINI);
      if(nRet == 0)
           MessageBox(hWnd, "Application Start Failed, Parameters:TMB Printer->COM Referential Error!!", "ERROR", MB_ICONSTOP);
      else
           gSelectedPort = atoi(szBuf);
}
void ExitSystem()
{
      if(MessageBox(0, "Are you sure you want to quit the system ?", "QUIT", MB_YESNO)==IDYES)
      {
           //KillTimer(hWnd, TIMER_ID);
           DestroyWindow(hWnd);
      }
}
void OutputScreen(HWND handle, char sMsg[])
{
      static int entry;
      static int entry2;
      char *szBuff=NULL;
      char crlf[3]={13, 10, 0};
      int length;
      int ret=0;
      if(handle==hwndEditDvc)
      {
           entry++;
           if(entry>10)
           {
                 entry=0;
                 //strcpy(szBuff, "");
                 SendMessage(handle,WM_SETT
           }
      }
      length = SendMessage(handle, WM_GETTEXTLENGTH, 0, 0L);
      if(length > 0)// && length < 1024)
      {
           ret = (length) + strlen(sMsg) + 10;
           szBuff = (char *)GlobalAlloc(GPTR, ret);
           if(szBuff==NULL)
           {
                 SendMessage(handle,WM_SETT
           }
           else
           {
                 ret = SendMessage(handle, WM_GETTEXT, ret, (LPARAM)szBuff);
                 strcat(szBuff, sMsg);
                 strcat(szBuff, crlf);
                 SendMessage(handle,WM_SETT
           }
           GlobalFree((HGLOBAL)szBuff
      }
      else
      {
           SendMessage(handle,WM_SETT
      }
      UpdateWindow(handle);
}
void OnMenuTestPrint()
{
      FILE *pFile;
      char tmp[100]={0};
      printer_Select();
      printer_PrintReceipt();
      printer_PrintReceiptLogo()
      printer_Print("123456789x1
      printer_PrintLineFeed();
      printer_Print("abcdefghijk
      printer_PrintLineFeed();
      printer_Print("!@#$%^&*()_
      printer_PrintLineFeed();
      printer_Print("ABCDEFGHIJK
      printer_PrintLineFeed();
      printer_PrintLineFeed();
      printer_PrintLineFeed();
      printer_PrintLineFeed();
      printer_PrintLineFeed();
      printer_PrintReceiptHalfCu
 Â
}
//void CALLBACK OutputPoll(HWND hWnd, UINT msg, UINT timerID, DWORD dwTime)
void OutputPoll()
{
      int iState=0;
      char sPollData[80]={0};
      char sReadData[2640]={0};
      char sCommand[12];
      char sTemp[2640]={0};
      char sTemp3[2640]={0};
      char sTemp2[2640]={0};
      char sData[2650];
      char sFunction[80]={0};
      char sCutForm[80]={0};
      char sCutFormDtl[80]={0};
      int iLength=0;
      int iDataLockRetry=0;
      int iLoopData=0;
      char sMsg[80]={0};
      int bLoop=0;
      int iNCol=0;
      iState = 100;
      iDataLockRetry = 0;
      bLoop = 1;
      //MessageBox(hWnd, "Processing","OK", MB_OK);
      gBool = TRUE;
      while(bLoop==1)
      {
           bLoop = 0;
           if(iState==100)
           {
                 gIdleState = 1;
                 iState = 600;
                 if(file_check(gsPollFile) > 0)
                 {
                      if(file_poll_lock(gsPollFi
                      {
                            //sPollData = file_read(file_poll);
                            file_read(file_poll, sPollData);
                            if(strcmp(sPollData,"WRITE
                            {
                                 gIdleState = 0;
                                 iState = 200;
                            }
                      }
                 }
           }// state = 100
           if(iState==200)
           {
                 if (file_data_lock(gsDataFile
                 {
                      iDataLockRetry = 0;
                      iState = 300;
                 }
                 else
                      iDataLockRetry++;
                 if (iDataLockRetry >= 10)
                 {
                      iDataLockRetry = 0;
                      iState = 600;
                 }
           }// state = 200
           if(iState==300)
           {
                 //sReadData = file_read(file_data);
                 file_read(file_data, sReadData);
                 if(strlen(sReadData) != 0)
                 {
                       if(strcmp(sReadData, "EOF") == 0)
                             iState = 500;
                       else
                       {
                             iState = 400;
                             bLoop = 1;
         strcpy(sData, "");
                       }
                       //MessageBox(hWnd, sReadData, "OK", MB_OK);
                 }
                 else
                      iState = 300;
           }//state = 300
           if(iState==400)
           {
                 iState = 300;
                 if(strncmp(sReadData, "CUTFORM_DTL", 11) == 0)
                 {
                      strcpy(sCommand, "CUTFORM_DTL");
                      Mid(sReadData, 13, 0, sData);
                      Trim(sData);
                      strcpy(sCutFormDtl, sData);
                 }
                 else if(strncmp(sReadData, "LENGTH_COL", 10) == 0)
                 {
                      strcpy(sCommand, "LENGTH_COL");
                      Mid(sReadData, 12, 0, sData);
                      Trim(sData);
                      iNCol = atoi(sData);
                      //if(iNCol == 0)
                      //{
                      //      MessageBox(hWnd, "Problem with atoi(LENGTH_COL).", "ERR", MB_OK);
                      //      sprintf(sMsg, "READ=>%s,DATA=>%s,ATOI=>%
                      //      MessageBox(hWnd, sMsg, "ERR", MB_OK);
                      //      iNCol = atoi(sData);
                      //}
                 }
                 else if(strncmp(sReadData, "CUTFORM", 7) == 0)
                 {
                      strcpy(sCommand, "CUTFORM");
                      Mid(sReadData, 9, 0, sData);
                      Trim(sData);
                      strcpy(sCutForm, sData);
                 }
                 else if(strncmp(sReadData, "COMMAND", 7) == 0)
                 {
                      strcpy(sCommand, "COMMAND");
                      Mid(sReadData, 9, 0, sData);
                      Trim(sData);
                      strcpy(sFunction, sData);
                      iLength = 0;
                      iNCol = 0;
                      strcpy(sCutForm, "");
                      strcpy(sCutFormDtl, "");
                 }
                 else if(strncmp(sReadData, "LENGTH", 6) == 0)
                 {
                      strcpy(sCommand, "LENGTH");
                      Mid(sReadData, 8, 0, sData);
                      Trim(sData);
                      iLength = atoi(sData);
                      //if(iLength == 0)
                      //{
                      //      MessageBox(hWnd, "Problem with atoi(LENGTH).", "ERR", MB_OK);
                      //      sprintf(sMsg, "READ=>%s,DATA=>%s,ATOI=>%
                      //      MessageBox(hWnd, sMsg, "ERR", MB_OK);
                      //      iLength = atoi(sData);
                      //}
                 }
                 else if(strncmp(sReadData, "DATA", 4) == 0)
                 {
                      strcpy(sCommand, "DATA");
                      Mid(sReadData, 6, 0, sData);
                      //Trim(sData);
      if(strncmp(sFunction, "print", 5) == 0)
                      {
                            iState = 1000;
                            printer_Select();
                      }
                      else if(strncmp(sFunction, "aprint", 6) == 0)
                      {
                            iState = 2000;
                            printer_Select();
                      }
                      else if(strncmp(sFunction, "ejectdoc", 8) == 0)
                      {
                            iState = 3000;
                            printer_Select();
                      }
                      else if(strncmp(sFunction, "insertdoc", 9) == 0)
                      {
                            iState = 4000;
                            printer_Select();
                      }
                      else if(strncmp(sFunction, "display", 7) == 0)
                      {
                            iState = 5000;
                            printer_Select();
                      }
                      else if(strncmp(sFunction, "loadlogo", 9) == 0)
                      {
                            iState = 6000;
                            printer_Select();
                      }
                      else if(strncmp(sFunction, "printlogo", 9) == 0)
                      {
                            iState = 7000;
                            printer_Select();
                      }
                      sprintf(sMsg, "%s=%d=%d=%d", sFunction, iLength, iNCol, iState);
                      OutputScreen(hwndEdit, sMsg);
                 }
                 else
                 {
                      strcpy(sCommand, "");
                      strcpy(sData, "");
                      strcpy(sReadData, "");
                 }
           }// state = 400
           if(iState==500)
           {
                 iState = 600;
                 if(file_truncate(&file_dat
                      iState = 500;
                 if(file_truncate(&file_pol
                      iState = 500;
           } //state = 500
           if(iState==600)
           {
                 if (file_data_close(file_data
                      iState = 700;
           }// state = 600
           if(iState==700)
           {
                 if (file_poll_close(file_poll
                      iState = 100;
           } //state = 700
           if(iState==1000) // command print
           {
                 sprintf(sMsg, "COMMAND->%s", sFunction);
                 OutputScreen(hwndEdit, sMsg);
                 if(strncmp(sCutFormDtl, "reccut", 6) ==0)
                      printer_PrintReceipt();
                 else if(strncmp(sCutFormDtl, "rec", 3) ==0)
                      printer_PrintReceipt();
     else if(strncmp(sCutFormDtl, "joucut", 6) ==0)
                      printer_PrintJournal();
                 else if(strncmp(sCutFormDtl, "jou", 3) ==0)
                      printer_PrintJournal();
                 else if(strncmp(sCutFormDtl, "doccut", 6) ==0)
                      printer_PrintDoc();
                 else if(strncmp(sCutFormDtl, "doc", 3) ==0)
                      printer_PrintDoc();
                 iLoopData = 1;
                 //iLength = strlen(sData);
                 while((iLoopData < iLength) && (iNCol > 0))
                 {
                      strcpy(sTemp,"");
                      //sTemp = Mid(sData, iLoopData, iNCol);
                      Mid(sData, iLoopData, iNCol, sTemp);
                      strcpy(sTemp3, sTemp);
                      Trim(sTemp3);
                      Mid(sCutFormDtl, 1, 3, sTemp2);
                      if (strlen(sTemp3) > 0 || strcmp(sTemp2, "doc")==0)
                      {
                            printer_Print(sTemp);
                            printer_PrintLineFeed();
                            printer_PrintCR();
                            sprintf(sMsg, "DATA->%s", sTemp);
                            OutputScreen(hwndEdit, sMsg);
                            if(strncmp(sTemp,"AKHIR LAPORAN", 13)==0 && strncmp(sCutFormDtl,"jou",
                                  strcpy(sCutFormDtl,"joucut
                      }
                      iLoopData = iLoopData + iNCol;
                 }
                 iState = 2500;
           } //state = 1000
           if(iState==2000)  // command aprint
           {
                 sprintf(sMsg, "COMMAND->%s", sFunction);
                 OutputScreen(hwndEdit, sMsg);
                 if(strncmp(sCutFormDtl,"re
                      printer_PrintReceipt();
                 else if(strncmp(sCutFormDtl,"re
                      printer_PrintReceipt();
                 else if(strncmp(sCutFormDtl,"jo
                      printer_PrintJournal();
                 else if(strncmp(sCutFormDtl,"jo
                      printer_PrintJournal();
                 else if(strncmp(sCutFormDtl,"do
                      printer_PrintDoc();
                 else if(strncmp(sCutFormDtl,"do
                      printer_PrintDoc();
                 iLoopData = 1;
                 //iLength = strlen(sData);
                 while((iLoopData < iLength) && (iNCol > 0))
                 {
                      //sTemp=0;
                      //sTemp = Mid(sData, iLoopData, iNCol);
                      Mid(sData, iLoopData, iNCol, sTemp);
                      strcpy(sTemp3, sTemp);
                      Trim(sTemp3);
                      Mid(sCutFormDtl, 1, 3, sTemp2);
                      if (strlen(sTemp3) > 0 || strcmp(sTemp2, "doc")==0)
                      {
                            printer_Print(sTemp);
                            printer_PrintLineFeed();
                            printer_PrintCR();
                            sprintf(sMsg, "DATA->%s", sTemp);
                            OutputScreen(hwndEdit, sMsg);
                            if(strncmp(sTemp,"AKHIR LAPORAN", 13)==0 && strncmp(sCutFormDtl,"jou",
                                  strcpy(sCutFormDtl,"joucut
                      }
                      iLoopData = iLoopData + iNCol;
                 }
                 iState = 2500;
           } //state = 2000
           if(iState==2500)  //cut receipt
           {
                 iState = 300;
                 if(strncmp(sCutFormDtl,"do
                 {
                      iLoopData = 1;
                      iState = 3000;
                 }
                 if(strcmp(sCutFormDtl,"rec
                 {
                      printer_PrintLineFeed();
                      printer_PrintLineFeed();
                      printer_PrintLineFeed();
                      printer_PrintLineFeed();
                      printer_PrintLineFeed();
                      printer_PrintReceiptHalfCu
                      OutputScreen(hwndEdit, "DATA->Receipt Cut");
                 }
                 if(strncmp(sCutFormDtl,"jo
                 {
                      printer_PrintLineFeed();
                      printer_PrintLineFeed();
                      printer_PrintLineFeed();
                      printer_PrintLineFeed();
                      printer_PrintLineFeed();
                      printer_PrintReceiptHalfCu
                      OutputScreen(hwndEdit, "DATA->Journal Cut(EPSON)");
                 }
           } //state = 2500
           if(iState==3000) //command ejectdoc
           {
                 sprintf(sMsg, "DATA->%s", sFunction);
                 OutputScreen(hwndEdit, sMsg);
                 printer_EjectDoc();
                 iState = 300;
           }// state = 3000
           if(iState==4000) //command insertdoc
           {
                 sprintf(sMsg, "DATA->%s", sFunction);
                 OutputScreen(hwndEdit, sMsg);
                 if(strcmp(gSelectedPrinter
                 {
                      printer_PrintDoc();
                      printer_InsertDoc();
                 }
                 else
                 {
                      printer_InsertDoc();
                 }
                 iState = 300;
           }// state = 4000
           if(iState==5000) //command display
           {
                 sprintf(sMsg, "DATA->%s", sFunction);
                 OutputScreen(hwndEdit, sMsg);
                 printer_ClearDisplay();
                 printer_PrintDisplay(sData
                 Mid(sData, 1, 20, sTemp2);
                 sprintf(sMsg, "DATA->%s", sTemp2);
                 OutputScreen(hwndEdit, sMsg);
                 Mid(sData, 21, 20, sTemp2);
                 sprintf(sMsg, "DATA->%s", sTemp2);
                 OutputScreen(hwndEdit, sMsg);
                 iState = 300;
           }// state = 5000
           if(iState==6000) //command load logo
           {
                 sprintf(sMsg, "DATA->%s", sFunction);
                 OutputScreen(hwndEdit, sMsg);
                 printer_Select();
                 printer_PrintReceipt();
                 //load_logo(sData);
                 //sprintf(sMsg, "DATA->%s", sData);
                 //OutputScreen(hwndEdit, sMsg);
                 iState = 300;
           } //satet = 6000
           if(iState==7000) //command print logo
           {
                 sprintf(sMsg, "DATA->%s", sFunction);
                 OutputScreen(hwndEdit, sMsg);
                 printer_PrintReceiptLogo()
                 OutputScreen(hwndEdit, "DATA->Receipt Logo");
                 iState = 300;
           }// state = 7000
           if(iState==8000) //command N/A
           {
                 sprintf(sMsg, "DATA->%s", sFunction);
                 OutputScreen(hwndEdit, sMsg);
                 iState = 300;
           } // state =8000
           if(iState==9000 || gGlobalOverwrite == 100) //command init printer
           {
                 OutputScreen(hwndEdit, "DATA->Force Init");
                 InitPrinter();
                 gGlobalOverwrite = 0;
                 iState = 500;
                 bLoop = 1;
           } // state =9000
      }// end while bLoop
      //MessageBox(hWnd, "OOOO", "OK", MB_OK);
}
int file_check(char *pfile)
{
      int handle;
      int l;
      //char sMsg[100];
      handle = open(pfile, O_RDONLY);
      l = filelength(handle);
      close(handle);
      return l;
}
int file_poll_lock(char *pfile)
{
      int tmp;
      FILE *fileNum;
      tmp = 0;
      fileNum = fopen(pfile, "r");
      if(fileNum != NULL)
      {
           tmp = 0;
           file_poll = fileNum;
      }
      else
           tmp=2;
      return tmp;
}
int file_poll_close(FILE *pfile)
{
      fclose(pfile);
      return 0;
}
int file_data_lock(char *pfile)
{
      int tmp;
      FILE *fileNum;
      tmp = 0;
      fileNum = fopen(pfile, "r");
      if(fileNum != NULL)
      {
           tmp = 0;
           file_data = fileNum;
      }
      else
           tmp=2;
      return tmp;
}
int file_data_close(FILE *pfile)
{
      fclose(pfile);
      return 0;
}
int file_truncate(FILE **pfile, char * pfilename)
{
      int tmp;
      FILE *fileNum;
      fclose(*pfile);
      fileNum = fopen(pfilename, "w");
      if(fileNum != NULL)
      {
           tmp = 0;
           *pfile = fileNum;
      }
      else
           tmp=2;
      return tmp;
}
int file_read(FILE *pfile, char buff[])
{
      if(pfile==NULL)
      {
           strcpy(buff,"EOF");
           return 0;
      }
      if(feof(pfile))
           strcpy(buff,"EOF");
      else
           fgets(buff, 2650, pfile);
      return 0;//buff;
}
int Mid(char *sSource, int nStartIdx, int nLength, char tmp[])
{
      //char tmp[1000];
      int nEnd=0;
      int i=0;
      int x=0;
      int l=0;
      strcpy(tmp, "");
      l = strlen(sSource);
      if(strlen(sSource<=0))
      {
           strcpy(tmp, "");
           return 0;
      }
      if(nStartIdx > 0) nStartIdx--;
      if(nLength==0)
           nEnd = l;
      else if(nLength > strlen(sSource))
           nEnd = l;
      else
           nEnd = nLength;
      x = nEnd - nStartIdx + 1;
      for(i=0;i<x;i++)
      {
           tmp[i] = sSource[i+nStartIdx];
      }
      tmp[i]=0;
      return 0;
}
void Trim(char pData[])
{
      char tmp[80]={0};
      int c=0;
      int i=0;
      // trim the white space
      while(pData[c]!=NULL)
      {
           if(pData[c] != ' ' && pData[c] != '\n')
           {
                 if(i<80)
                 {
                      tmp[i]=pData[c];
                      i++;
                 }
           }
           c++;
      }
      tmp[i]=NULL;
      strcpy(pData, tmp);
}
BOOL COMMAvailable(int port)
{
      return TRUE;
}
char *ReadCOMMInput()
{
      char sMsg[80]={0};
      int ret;
      if(hComm < 0)
           strcpy(sMsg, "");
      else
           ret = ReadComm(hComm, sMsg, 1024);
      return sMsg;
}
BOOL OpenPrinter(int nCOM)
{
      int err;
      char setting[30];
      char com[10];
      DCB dcb;
      BOOL bRet;
      if(hComm >= 0)return TRUE;
      bRet = TRUE;
      sprintf(com, "COM%d", nCOM);
      hComm = OpenComm(com, 1024, 512);
      if(hComm < 0)
  {
           MessageBox(hCommDvc, "Invalid COM port", "OK", MB_OK);
           bRet =FALSE;
           return bRet;
      }
      if(strcmp(gSelectedPrinter
           sprintf(setting, "COM%d:%d,%c,%d,%d",nCOM,9
      if(strcmp(gSelectedPrinter
           sprintf(setting, "COM%d:%d,%c,%d,%d",nCOM,9
      else
           sprintf(setting, "COM%d:%d,%c,%d,%d",nCOM,9
      err = BuildCommDCB(setting, &dcb);
      if(err<0)
      {
           MessageBox(hCommDvc, "Error BuildDCB", "OK", MB_OK);
           bRet =FALSE;
   return bRet;
      }
      dcb.fRtsDisable=0;
      dcb.fDtrDisable=0;
      err = SetCommState(&dcb);
      if(err<0)
      {
           MessageBox(hCommDvc, "Error SetCommState", "OK", MB_OK);
           bRet =FALSE;
      }
      else
      {
           SendMessage(hWndBtnDvc, WM_SETTEXT, 0, (LPARAM)"CloseCOMM");
      }
      return bRet;
}
void ClosePrinter()
{
      if(hComm < 0)return;
      CloseComm(hComm);
  hComm = -1;
      SendMessage(hWndBtnDvc, WM_SETTEXT, 0, (LPARAM)"OpenCOMM");
}
void cmdCOMStatus()
{
      char setting[12]={0};
      char sMsg[30]={0};
      if(strcmp(gSelectedPrinter
           strcpy(setting, "9600,O,8,1");
      else
           strcpy(setting, "9600,N,8,1");
      if(hComm < 0)
      {
           OutputScreen(hwndEditDvc, "Close COM Port.");
           sprintf(sMsg, "Setting -> %s", setting);
           OutputScreen(hwndEditDvc, sMsg);
      }
}
void SendMsg(char *pMsg)
{
      char *input;
      char sMsg[80]={0};
      int i=0;
      for(i=0;i<2000;i++)
      {
        ;
      }
      cmdCOMStatus();
      if(hComm <= 0)
      {
           WriteComm(hComm, pMsg, strlen(pMsg));
           input = ReadCOMMInput();
           sprintf(sMsg, "Status : [%s].", input);
           OutputScreen(hwndEditDvc, sMsg);
      }
      else
           OutputScreen(hwndEditDvc, "Status : COM Port NOT Opened.");
}
void InitPrinter()
{
      OutputScreen(hwndEditDvc, "COMMAND-> Init printer");
      SendMsg(CmdInit);
      printer_PrintDisplay ("                     ");
}
void load_epson_tmh5k2()
{
      char sSelectPrt[10]={0};
      char sSelectPrtDoc[10]={0};
      CmdPrinter[0]=0x1B;CmdPrin
      sSelectPrtDoc[0]=0x1B;sSel
      sSelectPrtDoc[4]=0x63;sSel
      sSelectPrtDoc[8]=0x61;sSel
 Print_LineFeed[0]=0x0A;Pri
 Print_CR[0]=0x0D;Print_CR[
 Print_HomeCursor[0]=0x1B;P
 CmdInit[0]=0x10;CmdInit[1]
 CmdInit[6]=0x01;CmdInit[7]
 CmdInit[12]=0x1B;CmdInit[1
 CmdDisplay[0]=0x1B;CmdDisp
 CmdDoc[0]=0x1B;CmdDoc[1]=0
 CmdDoc[6]=0x1B;CmdDoc[7]=0
 CmdDoc_Eject[0]=0x0C;CmdDo
 CmdDoc_Insert[0]=0x1B;CmdD
 CmdDoc_Release[0]=0x1B;Cmd
 CmdDoc_Feed[0]=0x1B;CmdDoc
 strcpy(CmdReceipt, CmdPrinter);
 CmdReceipt[3]=0x1B;CmdRece
 CmdReceipt_HalfCut[0]=0x1B
 CmdReceipt_HalfCut[4]=0x56
 CmdReceipt_FullCut[0]=0x1B
 CmdReceipt_FullCut[4]=0x56
 CmdReceipt_LogoPrint[0]=0x
 CmdReceipt_LogoPrint[4]=0;
 Receipt_LogoLoad_Start[0]=
 Receipt_LogoLoad_Start[3]=
 Receipt_LogoLoad_Start[6]=
 Receipt_LogoLoad_Data[0]=0
 Receipt_LogoLoad_Data[3]=0
 Receipt_LogoLoad_Data[6]=0
 Receipt_LogoLoad_End[0]=0x
 Receipt_LogoLoad_End[3]=0x
 Receipt_LogoLoad_End[6]=0;
 strcpy(CmdJournal, CmdReceipt);
 ClosePrinter();
 OpenPrinter(gSelectedPort)
 InitPrinter();
}
void load_sni_nd70()
{
      char sSelectPrt[10]={0};
      char sSelectPrtDoc[10]={0};
      CmdPrinter[0]=0x1B;CmdPrin
      strcpy(sSelectPrtDoc, CmdPrinter);
      sSelectPrtDoc[4]=27;sSelec
      sSelectPrtDoc[8]=0;
 Print_LineFeed[0]=0x0A;Pri
 Print_CR[0]=0x0D;Print_CR[
 Print_HomeCursor[0]=27;Pri
 CmdInit[0]=0x10;CmdInit[1]
 CmdInit[6]=03;CmdInit[7]=0
 CmdDisplay[0]=27;CmdDispla
 strcpy(CmdDoc, CmdPrinter);
 CmdDoc[4]=27;CmdDoc[5]=99;
 CmdDoc[6]=48;CmdDoc[7]=4;C
 CmdDoc_Eject[0]=12;CmdDoc_
 CmdDoc_Insert[0]=27;CmdDoc
 CmdDoc_Release[0]=27;CmdDo
 CmdDoc_Feed[0]=27;CmdDoc_F
 strcpy(CmdReceipt, CmdPrinter);
 CmdReceipt[4]=27;CmdReceip
 CmdReceipt_HalfCut[0]=27;C
 CmdReceipt_FullCut[0]=27;C
 CmdReceipt_LogoPrint[0]=27
 Receipt_LogoLoad_Start[0]=
 Receipt_LogoLoad_Start[3]=
 Receipt_LogoLoad_Start[6]=
 Receipt_LogoLoad_Data[0]=0
 Receipt_LogoLoad_Data[3]=0
 Receipt_LogoLoad_Data[6]=0
 Receipt_LogoLoad_End[0]=0x
 Receipt_LogoLoad_End[3]=0x
 Receipt_LogoLoad_End[6]=0;
 strcpy(CmdJournal, CmdPrinter);
 CmdJournal[4]=27;CmdJourna
 ClosePrinter();
 OpenPrinter(gSelectedPort)
 InitPrinter();
}
void printer_PrintDisplay(char pMsg[])
{
      char sMsg[80];
      OutputScreen(hwndEditDvc, "COMMAND-> Print Display");
      SendMsg(CmdDisplay);
      if(strcmp(gSelectedPrinter
      {
           //sMsg = Mid(pMsg, 1, 20);
           Mid(pMsg, 1, 20, sMsg);
           strcpy(sMsg, Print_CR);
           strcpy(sMsg, Print_LineFeed);
           SendMsg(sMsg);
           Mid(pMsg, 21, 20, sMsg);
           SendMsg(sMsg);
      }
      else
      {
           //sMsg = Mid(pMsg, 1, 40);
           Mid(pMsg, 1, 40, sMsg);
           SendMsg(sMsg);
      }
}
void printer_PrintLineFeed()
{
      OutputScreen(hwndEditDvc, "COMMAND-> LineFeed");
      SendMsg(Print_LineFeed);
}
void printer_PrintReceipt()
{
      OutputScreen(hwndEditDvc, "COMMAND-> Select Peripheral Receipt Station");
  SendMsg(CmdReceipt);
}
void printer_PrintReceiptHalfCu
{
      char msg[80];
      OutputScreen(hwndEditDvc, "COMMAND-> Receipt 1/2 Cut");
      if(strcmp(gSelectedPrinter
      {
           strcpy(msg, CmdReceipt);
           strcat(msg, CmdReceipt_HalfCut);
           SendMsg(msg);
      }
      else
           SendMsg(CmdReceipt_HalfCut
}
void printer_PrintReceiptFullCu
{
      char msg[80];
      OutputScreen(hwndEditDvc, "COMMAND-> Receipt Full Cut");
      strcpy(msg, CmdReceipt);
      strcat(msg, CmdReceipt_FullCut);
      SendMsg(msg);
}
void printer_PrintReceiptLogo()
{
      char msg[80];
      OutputScreen(hwndEditDvc, "COMMAND-> Receipt Print Logo");
  strcpy(msg, CmdReceipt);
      strcat(msg, CmdReceipt_LogoPrint);
      SendMsg(msg);
}
void printer_ClearDisplay()
{
      char msg[80];
      OutputScreen(hwndEditDvc, "COMMAND-> Clear Display");
      SendMsg(CmdDisplay);
      if(strcmp(gSelectedPrinter
      {
           strcpy(msg, Print_LineFeed);
           strcat(msg, Print_LineFeed);
           strcat(msg, Print_CR);
           SendMsg(msg);
      }
      else
      {
           strcpy(msg, Print_CR);
           strcat(msg, Print_LineFeed);
           strcat(msg, Print_LineFeed);
           SendMsg(msg);
      }
}
void printer_Print(char pMsg[])
{
      OutputScreen(hwndEditDvc, "COMMAND-> Print");
      //MessageBox(hWnd, pMsg, "PRT", MB_OK);
      SendMsg(pMsg);
}
void printer_Select()
{
      OutputScreen(hwndEditDvc, "COMMAND-> Printer Peripheral Select");
      SendMsg(CmdPrinter);
}
void printer_EjectDoc()
{
      OutputScreen(hwndEditDvc, "COMMAND-> Eject Doc");
      SendMsg(CmdDoc_Eject);
}
void printer_InsertDoc()
{
      OutputScreen(hwndEditDvc, "COMMAND-> Insert Doc");
      SendMsg(CmdDoc_Insert);
}
void printer_ReleaseDoc()
{
      OutputScreen(hwndEditDvc, "COMMAND-> Release Doc");
      SendMsg(CmdDoc_Release);
}
void printer_FeedDoc()
{
      OutputScreen(hwndEditDvc, "COMMAND-> Feed Doc");
      SendMsg(CmdDoc_Feed);
}
void printer_PrintDoc()
{
      OutputScreen(hwndEditDvc, "COMMAND-> Select Peripheral Document Station");
      SendMsg(CmdDoc);
}
void printer_PrintJournal()
{
      OutputScreen(hwndEditDvc, "COMMAND-> Print Journal");
      SendMsg(CmdJournal);
}
void printer_PrintCR()
{
      OutputScreen(hwndEditDvc, "COMMAND-> Carriage Return");
      SendMsg(Print_CR);
}
void load_logo(char *pData)
{
      int iLines=0;
      int iCtr1=0;
      int iLastCtr=0;
      int iTrack=0;
      int iBoolean=0;
  char tmp[80]={0};
      iLogoData = (int)strlen(pData) / iDataPerTrack / 8;
      iLogoData--;
      if(iLogoData <=0 || iLogoData > 80)
      {
           MessageBox(hWnd, "Error in defining Logo Data.", "Logo Error", MB_ICONSTOP);
   return;
      }
      iLastCtr = 1;
      iTrack = 0;
      iLines = 0;
      for(iCtr1=1; iCtr1<=strlen(pData); iCtr1++)
      {
           Mid(pData, iCtr1, 1, tmp);
           if(strcmp(tmp, " ")==0)
                 iBoolean = 0;
           else
           {
                 iBoolean = 0;
                 switch(iTrack)
                 {
                      case 0:
                            iBoolean = 0x80;
                            break;
                      case 1:
                            iBoolean = 0x40;
                            break;
                      case 2:
                            iBoolean = 0x20;
                            break;
                      case 3:
                            iBoolean = 0x10;
                            break;
                      case 4:
                            iBoolean = 0x08;
                            break;
                      case 5:
                            iBoolean = 0x04;
                            break;
                      case 6:
                            iBoolean = 0x02;
                            break;
                      case 7:
                            iBoolean = 0x01;
                            break;
                 }
                 sLogoData[iLines][iLastCtr
                 iLastCtr++;
                 if((iLastCtr % (iDataPerTrack+1))==0)
                 {
                      iLastCtr = 1;
                      iTrack++;
                      if(iTrack > 7)
                      {
                            iTrack = 0;
                            iLines++;
                            if (iLines > iLogoData)
                                 goto q;
                      }
                 }
           }
      }
      q:
      for(iCtr1=0; iCtr1<=iDataPerTrack; iCtr1++)
      {
           strcpy(tmp, "");
           for(iTrack=1; iTrack<=iDataPerTrack; iTrack++)
           {
                 strcat(tmp, (char)sLogoData[iCtr1][iTr
           }
      }
      if(strcmp(gSelectedPrinter
           decode_nd70();
      else
           decode_tmh5k2();
}
void decode_nd70()
{
      int iCtr=0;
      int iCtr2=0;
      int iTrack=0;
      int l_iLogoTrack=0;
      char l_sLogoData[80]={0};
      char tmp[80]={0};
      if(iLogoData <= 0) return;
      SendMsg(Receipt_LogoLoad_S
      iCtr2 = 2;
      for(iCtr=0; iCtr<=iLogoData; iCtr++)
      {
           strcpy(l_sLogoData, "");
           strcpy(tmp, "");
           for(l_iLogoTrack=1; l_iLogoTrack<=strlen(Recei
           {
                 if(l_iLogoTrack==4)
                      strcat(l_sLogoData, (char)(iCtr + 1));
                 else
                 {
                      Mid(Receipt_LogoLoad_Data,
                      strcat(l_sLogoData, tmp);
                 }
           }
           SendMsg(l_sLogoData);
           for(iTrack=1; iTrack <= iDataPerTrack; iTrack++)
           {
                 strcat(l_sLogoData, (char)sLogoData[iCtr][iTra
                 SendMsg((char)sLogoData[iC
     iCtr2++;
           }
      }
      strcpy(l_sLogoData, "");
  for(l_iLogoTrack=1; l_iLogoTrack<=strlen(Recei
      {
        if(l_iLogoTrack==4)
                 strcat(l_sLogoData, (char)(6));
           else
           {
                 Mid(Receipt_LogoLoad_Data,
                 strcat(l_sLogoData, tmp);
           }
      }
      SendMsg(l_sLogoData);
  for(iTrack=1; iTrack <= iDataPerTrack; iTrack++)
      {
            strcat(l_sLogoData, (char)(0));
    SendMsg((char)0);
      }
      SendMsg(Receipt_LogoLoad_E
}
void decode_tmh5k2()
{
      int iCtr=0;
      int iCtr2=0;
      int iTrack=0;
      char tmp[80]={0};
      if(iLogoData <= 0) return;
      strcpy(tmp, (char)0x1D);
      strcat(tmp, "*");
      strcpy(tmp, (char)18);
      strcpy(tmp, (char)5);
      SendMsg(tmp);
      iCtr2 = 0;
      for(iCtr=1; iCtr<=iDataPerTrack; iCtr++)
      {
           for(iTrack=0; iTrack <= iLogoData; iTrack++);
           {
                 SendMsg((char)sLogoData[iT
                 iCtr2++;
           }
      }
      iCtr = 18 * 5 * 8;
      if(iCtr2 < iCtr)
      {
           for(iTrack=iCtr2; iTrack<=iCtr; iTrack++)
           {
                 SendMsg((char)0);
           }
      }
      strcpy(tmp, (char)0x1B);
      strcat(tmp, "U");
      SendMsg(tmp);
}
++++++++++++++++++++++++++
This is the input source file.
++++++++++++++++++++++++++
COMMAND=print Â
LENGTH=63 Â Â
LENGTH_COL=32 Â Â
CUTFORM=nd70 Â
CUTFORM_DTL=rec Â
DATA======================
COMMAND=print Â
LENGTH=50 Â Â
LENGTH_COL=32 Â Â
CUTFORM=nd70 Â
CUTFORM_DTL=rec Â
DATA=RECOVERY Â : BERMULA Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â
COMMAND=print Â
LENGTH=63 Â Â
LENGTH_COL=32 Â Â
CUTFORM=nd70 Â
CUTFORM_DTL=rec Â
DATA=Trkh: 02/03/2004, Masa: 13:29:21 Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â
COMMAND=print Â
LENGTH=63 Â Â
LENGTH_COL=32 Â Â
CUTFORM=nd70 Â
CUTFORM_DTL=rec Â
DATA======================
COMMAND=print Â
LENGTH=63 Â Â
LENGTH_COL=32 Â Â
CUTFORM=nd70 Â
CUTFORM_DTL=rec Â
DATA=Transaksi : Â Â Â Â Â Â 00246155 Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â
COMMAND=print Â
LENGTH=63 Â Â
LENGTH_COL=32 Â Â
CUTFORM=nd70 Â
CUTFORM_DTL=rec Â
DATA======================
COMMAND=print Â
LENGTH=50 Â Â
LENGTH_COL=32 Â Â
CUTFORM=nd70 Â
CUTFORM_DTL=rec Â
DATA=RECOVERY Â : SELESAI Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â
COMMAND=print Â
LENGTH=63 Â Â
LENGTH_COL=32 Â Â
CUTFORM=nd70 Â
CUTFORM_DTL=rec Â
DATA=Trkh: 02/03/2004, Masa: 13:29:24 Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â
COMMAND=print Â
LENGTH=63 Â Â
LENGTH_COL=32 Â Â
CUTFORM=nd70 Â
CUTFORM_DTL=rec Â
DATA======================
COMMAND=print Â
LENGTH=61 Â Â
LENGTH_COL=32 Â Â
CUTFORM=nd70 Â
CUTFORM_DTL=reccut Â
DATA=*********************
COMMAND=print Â
LENGTH=220 Â
LENGTH_COL=32 Â Â
CUTFORM=nd70 Â
CUTFORM_DTL=reccut Â
DATA=---- Laporan Sign On J/Wang ----ID J/Wang: 4417J01 Â P/K: 02 Â Â W.Pendahuluan: RM Â Â Â Â Â 0.00 Trkh: 02/03/2004, Masa: 13:30:20==================
COMMAND=printlogo Â
LENGTH=25 Â Â
LENGTH_COL=140 Â
CUTFORM=nd70 Â
CUTFORM_DTL=rec Â
LOGO_PRINT Â Â Â Â Â Â Â Â Â Â
COMMAND=aprint Â
LENGTH=1033 Â
LENGTH_COL=32 Â Â
CUTFORM=nd70 Â
CUTFORM_DTL=reccut Â
DATA=    Welcome Friend To        ABC Comm Limited      --------------------------
++++++++++++++++++++++++++
Hope somebody can assist me on this code debugging.
Thanks.
lol good luck finding someone to debug that for 150 points. Make it a lot more and someone might =)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi itsmeandnobodyelse.
Thanks for the help on code debugging. Will try to execute on my machine later.
I have another version of mine which runs OK but the problems are :-
1. It will truncate some printing if I run the program (without debugging mode) but if I run the program by putting several breakpoints in debugging mode, it will print all the output successfully.
It seems like if I put 'PAUSE' in some places, it prints good. I suspect the problem lies at WriteComm API that I used. It seems that the process of writing data to com port is to fast to handle by the printer and that makes the printer unable to catch the data and print correctly.
Well, I do need experts opinion on this matter.
Thanks for the help on code debugging. Will try to execute on my machine later.
I have another version of mine which runs OK but the problems are :-
1. It will truncate some printing if I run the program (without debugging mode) but if I run the program by putting several breakpoints in debugging mode, it will print all the output successfully.
It seems like if I put 'PAUSE' in some places, it prints good. I suspect the problem lies at WriteComm API that I used. It seems that the process of writing data to com port is to fast to handle by the printer and that makes the printer unable to catch the data and print correctly.
Well, I do need experts opinion on this matter.