Microsoft KB Archive/126258

{|
 * width="100%"|

HOWTO: Determine the Type of Handle Retrieved from OpenPrinter

 * }

Q126258

-

The information in this article applies to:


 * Microsoft Win32 Application Programming Interface (API), used with:
 * Microsoft Windows NT Server versions 3.5, 3.51, 4.0
 * Microsoft Windows NT Workstation versions 3.5, 3.51, 4.0
 * Microsoft Windows 95

-

SUMMARY
OpenPrinter returns a valid handle when a printer name or a server name is passed to it. Sometimes you might need to determine if the returned handle is a handle to a printer, because some Win32 spooler functions only accept printer handles and will fail on server handles. The following code determines if a handle is a printer handle:

  BOOL IsPrinterHandle( HANDLE hPrinter) {

DWORD      cbNeeded; DWORD      Error; BOOL       bRet = TRUE;

if( !GetPrinter(hPrinter, 2, (LPBYTE)NULL, 0, &cbNeeded )) {          Error = GetLastError; bRet = FALSE;

if( Error == ERROR_INSUFFICIENT_BUFFER ) {

// Expect this for a valid printer handle. bRet = TRUE;

}

}      return bRet;

} Additional query words: kbDSupport kbdss kbGDI kbPrinting

Keywords : kbOSWinNT350 kbOSWinNT351 kbOSWinNT400 kbSDKWin32 kbOSWin95 kbDSupport

Issue type : kbhowto

Technology : kbAudDeveloper kbWin32sSearch kbWin32API