Hi,
am working on unidrv printer driver.
I have implemented writeprinter function in the rendering plug-in of the Unidrv printer driver , by opening a file and capturing the out put data given by the Unidrv driver into a .txt file.

Now can any one tell me how can i send this captured data from this .txt file to the print spooler , in order to print the out put data?
I have tried using the DrvWriteSpoolbuf function , but its not working.....
may be because am not using it properly..or for some other reason....

So can any one who knows this ..plzz help me....as how do i use this function...
If you provide me an example ..that would be of great help to me..

thanks in advance..

Recommended Answers

All 2 Replies

Can't you just print the .txt file from My Computer? Or are you wanting to do this automatically?

Note that you have to CLOSE the file you are capturing before any other process is allowed to use it. If the file is still open (whether or not it is receiving text), nothing else can use it. It is not yet a bona-fide .txt file until all of the file headers are completed when you close the file.

Those "ghost files" you see in gray type in the My Computer display when you have an editor open are unclosed files being created.

If the same process is doing both the file creation and the printing, you have to do the equivalent of "rewinding the tape after recording it, so you can play it back." The file position pointer is at the end of the file when you are writing information.

Close the file in write mode, then open it again in read mode. This resets the file position pointer to the beginning.

Hi,
thanks for your reply.....
let me explain you what actually am trying to do.
writeprinter() function in a rendering plug-in of a Unidrv printer driver if implemented , enables us to capture the out put data generated by the Unidrv printer driver.
So am trying to implement this function there by capturing the data the driver is giving out. So , for this i have written a function which opens a file captures the driver data .But to my surprise am not able to get any data ,but NULL is being captured.
You can see my implementation as below..

HRESULT __stdcall
COemUni2::
WritePrinter(
PDEVOBJ pdevobj,
PVOID pBuf,
DWORD cbBuffer,
PDWORD pcbWritten
)
{

BOOL bResult;


bResult = GetDriverOutput(pdevobj, pBuf, cbBuffer, pcbWritten);

if(bResult)
{
return S_OK;
}
return S_FALSE;
}


BOOL GetDriverOutput(PDEVOBJ pdevobj, PVOID pBuf, DWORD cbBuffer, PDWORD
pcbWritten) {

FILE *fp1;
char* sFile;

sFile = "E:\\result.txt";


HANDLE hFile1 = CreateFile((LPCTSTR)sFile, GENERIC_WRITE |
GENERIC_READ,
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL,
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL, NULL);

if( (fp1 = fopen( sFile, "w" )) == NULL ){
return FALSE;
}

fprintf(fp1, "%s", pBuf);


fclose(fp1);

CloseHandle(hFile1);

return TRUE;
}

This is what i implemented. I dont know why NULL is being captured ....
Now my objective is to capture the correct out put data generated by Unidrv driver and also i should send this data what ever captured ,to the print spooler for printing and this should be done automatically by my function .
So please throw some light , by giving me some idea on how do i do this and please let me know where exactly am going wrong.
Thanks in advance for your time and help.

Please let me know if you still want any more details from my side.
Thanks,

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.