#include "Winspool.h"
#include <io.h>
BOOL Img2Printer(char* filePath, char* prnName)
{
HANDLE prnHandle;
DOC_INFO_1 di;
DWORD cWritten, len;
BOOL retCode;
FILE *fp;
char *buff;
fp = fopen( filePath, "rb" );
if( !fp ) return 0;
len = _filelength( fileno(fp) );
buff = new char[len];
fread( buff, len, 1, fp );
fclose( fp );
if( !::OpenPrinter( prnName, &prnHandle, 0 ) )
{
delete buff;
return 0;
}
di.pDocName = "My Image File";
di.pOutputFile = 0;
di.pDatatype = "RAW";
if( !::StartDocPrinter( prnHandle, 1, (LPBYTE)&di ) )
return 0;
retCode = ::WritePrinter( prnHandle, buff, len, &cWritten );
::EndDocPrinter( prnHandle );
ClosePrinter( prnHandle );
delete buff;
return retCode;
}
|