#include < WINDOWS.H > >#include < winspool.h > >#define DllExport __declspec( dllexport ) >DllExport DWORD PrinterStatus(LPTSTR lpPrinter); > >DllExport DWORD PrinterStatus(LPTSTR lpPrinter) >{ DWORD is an unsigned type (unsigned long). C++ will accept -1 as initial value, but, if you want to initialize it correctly, it should be MAXDWORD. Probably you have a warning on this line. BTW, why don't you initialize it to 0? > DWORD iResult = -1; This should be: LPBYTE hGlobal = NULL; > HGLOBAL hGlobal = NULL; iHandle will be the output value from OpenPrinter. The param is declared as LPHANDLE (so, a pointer) because it is an output value. So, it should be declared here: HANDLE iHandle = NULL; > LPHANDLE iHandle = 0; > DWORD level = 2, numbytes = 0, dSize; > PRINTER_INFO_2 *prninfo = NULL; The call should be: if SUCCEEDED(OpenPrinter(lpPrinter, &iHandle, 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 */ A little better: hGlobal = new BYTE[numbytes]; > hGlobal = GlobalAlloc(GHND, numbytes); > if (hGlobal != NULL) > { I think it would be better: prninfo = (PRINTER_INFO_2 *)hGlobal; > prninfo = (PRINTER_INFO_2 *)GlobalLock(hGlobal); > /* Call GetPrinter */ prninfo cannot be NULL > if (prninfo != NULL) > { > dSize = sizeof(prninfo); This should be: GetPrinter(iHandle, level, hGlobal, numbytes, &numbytes); > GetPrinter(iHandle, level, (LPBYTE)prninfo, dSize, &numbytes); > /* Set the return value */ > iResult = prninfo->Status; > /* Free the memory */ I don't think you need to lock/unlock the buffer. > GlobalUnlock(hGlobal); > } > /* Release it */ If you used new BYTE[] to allocate memory, then: delete [] hGlobal; > 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.