Click to See Complete Forum and Search --> : Help with Escape PASSTHROUGH


Tan Pham
May 20th, 1999, 12:32 AM
I'm using the Escape function with PASSTHROUGH to send datas to a matrix printer. The datas are sent correctly but the return value of the Escape function is always SP_ERROR. GetLastError() --> 87. (The parameter is incorrect). Any wrong with the following code ?



BOOL PrintIt()
{

CDC dc;
DOCINFO di;

CString sName;
CString msg;
int iEsc = PASSTHROUGH;


typedef struct {
WORD Size;
char Data[512];
} PASSTHROUGHSTRUCT;
PASSTHROUGHSTRUCT MyPassThroughStruct;

::ZeroMemory(&di, sizeof (DOCINFO));

dc.CreateDC(NULL, "MyDotMatrixPrinter", NULL, NULL);

sName.Format("MyDoc");
di.cbSize = sizeof (DOCINFO);
di.lpszDocName = sName;
di.lpszOutput=NULL;


dc.StartDoc(&di);

//dc.StartPage();

if (!dc.Escape(QUERYESCSUPPORT, sizeof(int), (LPSTR)&iEsc, NULL))
{
... // PassThrough not supported
}



MyPassThroughStruct.Size=5;
sprintf(MyPassThroughStruct.Data,"\x1b@\x1bR\000");
MyPassThroughStruct.Data[4]='\000';
if(dc.Escape(PASSTHROUGH,0,(char *) &MyPassThroughStruct,NULL)<0)
{
msg.Format("GetLastError: %d",GetLastError());
MessageBox(msg);
// Output: GetLastError: 87 (The paramater is incorrect)
}

//dc.EndPage();

dc.EndDoc();


dc.DeleteDC();

return TRUE;
}




BTW, there are no StartPage() and EndPage() in my function since if I put StartPage() and EndPage() properly, the output to the printer is messed up. Any ideas why it's like that?

Eugene N
July 22nd, 1999, 09:29 AM
I think you can try this:


...
dc.Escape(PASSTHROUGH,5,"\x1b@\x1bR\000", NULL );
...




May be it help you. No other errors I found.

Eugene.