Article ID: 185252
Article Last Modified on 11/21/2006
11988 INFO: Windows File I/O vs. C Run-time File I/O
#include <windows.h>
#include <stdio.h>
int main()
{
OFSTRUCT ofin, ofout;
int nBytesWritten = 0;
int cbRead;
BYTE *pBuf;
HFILE hPrintFile;
HFILE hReadFile;
/* Allocate a buffer for file I/O. */
hReadFile = OpenFile("a:\\Test1.pcl", &ofin, OF_READ);
hPrinter = OpenFile("LPT1", &ofout, OF_WRITE);
/* Explicitly set the output stream to raw mode. */
_asm
{
mov bx,hPrinter
mov dx,20h
mov ax,4401h
int 21h
}
pBuf = (PBYTE) LocalAlloc(LMEM_FIXED, 2048);
/* Copy the input file to the printer. */
do
{
cbRead = _lread(hReadFile, pBuf, 2048);
nBytesWritten = _lwrite(hPrinter, pBuf, cbRead);
} while (cbRead != 0);
/* Free the buffer and close the streams. */
LocalFree((HLOCAL) pBuf);
_lclose(hReadFile);
_lclose(hPrinter);
return(0);
}
Keywords: kb16bitonly kbapi kbbug kbkernbase kbpending KB185252