Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Can any see what's wrong with the following?
Message
Information générale
Forum:
Visual C++
Catégorie:
Codage, syntaxe et commandes
Titre:
Can any see what's wrong with the following?
Divers
Thread ID:
00266137
Message ID:
00266137
Vues:
54
I'm trying to work my way through VC++, and I'm trying to write a DLL to wrap various and sundry calls to GetPrinter() to retrieve some of the printer values. First, here's the code
#include < WINDOWS.H >
#include < winspool.h >
#define DllExport __declspec( dllexport )
DllExport DWORD PrinterStatus(LPTSTR lpPrinter);

DllExport DWORD PrinterStatus(LPTSTR lpPrinter)
{
	DWORD iResult = -1;
	HGLOBAL hGlobal = NULL;
	LPHANDLE iHandle = 0;
	DWORD level = 2, numbytes = 0, dSize;
	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)
				{
                                        dSize = sizeof(prninfo);
					GetPrinter(iHandle, level, (LPBYTE)prninfo, dSize, &numbytes);
					/* Set the return value */
					iResult = prninfo->Status;
					/* Free the memory */
					GlobalUnlock(hGlobal);
				}
				/* Release it */
				GlobalFree(hGlobal);
			}
		}
		/* Close the printer */
		ClosePrinter(iHandle);
	}
	return iResult;
}
It compiles fine, but I'm not certain that it's working correctly. When I change the assignment of the return value to: iResult = prninfo->Attributes, it always returns 0. In playing around with calls to GetPrinter() using the PRINTER_INFO_2 structure in VFP, I get a value back that seems to be correct from the tests I've conducted. Note that I've omitted the DLLMain from the code above.

Anybody got any clues on what I might be doing wrong?

tia,
George

Ubi caritas et amor, deus ibi est
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform