Add the GetPrinterDC Function

You need to add a function to your C-language source file to support the printing operation. The GetPrinterDC function retrieves the device= field from the [windows] section of the WIN.INI file, divides the entry into its separate components, then creates a printer device context using the device name and printer port given in the entry. Add the following statements to the C-language source file:

HANDLE GetPrinterDC()

{

char pPrintInfo[80];

LPSTR lpTemp;

LPSTR lpPrintType;

LPSTR lpPrintDriver;

LPSTR lpPrintPort;

if(!GetProfileString(“windows”, “device”,

(LPSTR) “”, pPrintInfo, 80))

return(NULL);

lpTemp = lpPrintType = pPrintInfo;

lpPrintDriver = lpPrintPort = 0;

while(*lpTemp) {

if(*lpTemp == ',') {

*lpTemp++ = 0;

while(*lpTemp == ' ')

lpTemp = AnsiNext(lpTemp);

if(!lpPrintDriver)

lpPrintDriver = lpTemp;

else {

lpPrintPort = lpTemp;

break;

}

}

else

lpTemp = AnsiNext(lpTemp);

}

return(CreateDC(lpPrintDriver, lpPrintType, lpPrintPort, (LPSTR) NULL));

}

To separate the device= field into its three components, the AnsiNext function advances through the field one character at a time.