Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
GetPrinter and SetPrinter
Message
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Miscellaneous
Thread ID:
00293000
Message ID:
00293022
Views:
27
>Hello. I find myself in need of using GetPrinter and SetPrinter API's. The reason I need to access this, is when a printer runs out of paper, the printers on the network automatically go to 'Use Printer Offline' until the user changes the setting. Due to the nature of my app(POS), I'd like to do this programatically. I know this can be done with GetPrinter(to determine if a printer is currently working offline), and SetPrinter(to actually change it). However, I can't convert the C++ instructions into VFP code very well(this has hindered my use of many APIs). I have the MSDN Library documentation on it, so if someone could show me how to convert this into VFP use of the API and possibly sample code for this application of it, I'd be much obliged. Thank you.
>
>P.S. Our application runs on WIN98 only. I mention this only because Technet tells me this function won't work on NT(setting the work-offline part of it).

Hi Derek,

I wrote a DLL to try to do this. Unfortunately, I wasn't able to get the status from the printer. The value you're seeking is contained in the Status member of a PRINTER_INO_2 structure. Unfortunately, I was never able to retrieve a value other than 0 (which really isn't a valid result). Perhaps, if you tried to get the value immediately after sending a report to the printer, you might get a valid result (I haven't tried that). Below is the C++ source code (Note: in order for the below to compile correctly the source must be saved with a C, not CPP, extension).
DllExport DWORD PrinterStatus(LPTSTR lpPrinter)
{
	DWORD iResult = 1;
	HGLOBAL hGlobal = NULL;
	HANDLE iHandle = NULL;
	DWORD level = 2, numbytes = 0;
	PRINTER_INFO_2 *prninfo = NULL;
	if SUCCEEDED(OpenPrinter(lpPrinter, &iHandle, NULL))
	{
		/* Get the necessary size of the structure */
		GetPrinter(iHandle, level, 0, 0, &numbytes);
		if (numbytes > 0)
		{
			/* Allocate memory for the structure */
			hGlobal = GlobalAlloc(GHND, numbytes);
			if (hGlobal != NULL)
			{
				prninfo = (PRINTER_INFO_2 *)GlobalLock(hGlobal);
				/* Call GetPrinter */
				if (prninfo != NULL)
				{
					GetPrinter(iHandle, level, (LPBYTE)prninfo, numbytes, &numbytes);
					/* Set the return value */
					iResult = prninfo->Status;
					/* Free the memory */
					GlobalUnlock(hGlobal);
				}
				/* Release it */
				GlobalFree(hGlobal);
			}
		}
		/* Close the printer */
		ClosePrinter(iHandle);
	}
	return iResult;
}
hth,
George

Ubi caritas et amor, deus ibi est
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform