// JP opened flex table

Click to See Complete Forum and Search --> : How to Send Control Data to Printer with GDI driver


WinZ
May 15th, 2008, 12:00 PM
Hi everybody,

This is my first post on codeguru and I hope I'll do it fine...

I'm currently trying to send configuration data to my printer through the interface DLL of my GDI printer driver.
The configuration data are for example :
- an order to eject a card (No response from printer)
- consulting the configuration of my printer (need to get response).

So I need to be able to read and write printer.

Fir the moment, I just perform write to the printer and my problem is that after each command, I get a popup from spooler that inform user that the page had been sent to printer...

Here are my 2 tries :


HANDLE hPrinter = 0;
PRINTER_DEFAULTS PrinterDef = { NULL, NULL, PRINTER_ACCESS_USE };
BOOL bStatus = FALSE;
DOC_INFO_1 DocInfo;
DWORD dwBytesWritten = 0L;
DWORD dwJob = 0L;
UCHAR TestBuff[4] = {0x30,0x31,0x32,0x33};

bStatus = OpenPrinter(pNgeeNPrivate->pPrinterName, &hPrinter, &PrinterDef);

if (bStatus)
{
// Fill in the structure with info about this "document."
DocInfo.pDocName = (LPTSTR)_T("My Document");
DocInfo.pOutputFile = NULL;
DocInfo.pDatatype = (LPTSTR)_T("RAW");

// Inform the spooler the document is beginning.
dwJob = StartDocPrinter( hPrinter, 1, (LPBYTE)&DocInfo);
if (dwJob > 0) {
// Start a page.
bStatus = StartPagePrinter( hPrinter );
if (bStatus) {
// Send the data to the printer.
bStatus = WritePrinter( hPrinter, TestBuff, 4, &dwBytesWritten);
EndPagePrinter (hPrinter);
}
// Inform the spooler that the document is ending.
EndDocPrinter( hPrinter );
}
// Close the printer handle.
ClosePrinter( hPrinter );
}



HANDLE m_hCom;
DWORD iBytesWritten;
UCHAR TestBuff[4] = {0x30,0x31,0x32,0x33};


m_hCom = CreateFile(_T("USB001"),
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
0,
NULL);

WriteFile(m_hCom, TestBuff,4,&iBytesWritten,NULL);


CloseHandle(m_hCom);


In both case, I get the popup...

Do someone know how to send data to printer that will not be interpreted as a page print ?

Il also need to read response from my printer and I'm really not sure it will work with those methods...

Thanks a lot for your attention,

WinZ

//JP added flex table