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..

10 Years
Discussion Span
Last Post by rahul18

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.


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
PDEVOBJ pdevobj,
DWORD cbBuffer,
PDWORD pcbWritten

BOOL bResult;

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

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 |

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

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



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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.