--- old/src/java.desktop/windows/native/libawt/windows/WPrinterJob.cpp 2018-06-22 14:28:11.035347400 +0530 +++ new/src/java.desktop/windows/native/libawt/windows/WPrinterJob.cpp 2018-06-22 14:28:08.620348600 +0530 @@ -232,6 +232,77 @@ } } +JNIEXPORT jobjectArray JNICALL +Java_sun_print_PrintServiceLookupProvider_getRemotePrintersNames(JNIEnv *env, + jobject peer) +{ + TRY; + + int remotePrintersCount = 0; + DWORD cbNeeded = 0; + DWORD cReturned = 0; + LPBYTE pPrinterEnum = NULL; + LPBYTE pNetworkPrinterLoc = NULL; + + jstring utf_str; + jclass clazz = env->FindClass("java/lang/String"); + if (clazz == NULL) { + return NULL; + } + jobjectArray nameArray; + + try { + ::EnumPrinters(PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS, + NULL, 4, NULL, 0, &cbNeeded, &cReturned); + pPrinterEnum = new BYTE[cbNeeded]; + pNetworkPrinterLoc = new BYTE[cbNeeded/sizeof(PRINTER_INFO_4)]; + ::EnumPrinters(PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS, + NULL, 4, pPrinterEnum, cbNeeded, &cbNeeded, + &cReturned); + + if (cReturned > 0) { + for (DWORD i = 0; i < cReturned; i++) { + PRINTER_INFO_4 *info4 = (PRINTER_INFO_4 *) (pPrinterEnum + i * sizeof(PRINTER_INFO_4)); + + // PRINTER_ATTRIBUTE_NETWORK = 0x00000010 + // Store the network printers indexes + if (info4->Attributes & 0x00000010) { + pNetworkPrinterLoc[remotePrintersCount++] = i; + } + } + + // Allocate space only for the network type printers + nameArray = env->NewObjectArray(remotePrintersCount, clazz, NULL); + if (nameArray == NULL) { + throw std::bad_alloc(); + } + } else { + nameArray = NULL; + } + + // Loop thro' network printers list only + for (int i = 0; i < remotePrintersCount; i++) { + PRINTER_INFO_4 *info4 = (PRINTER_INFO_4 *) + (pPrinterEnum + pNetworkPrinterLoc[i] * sizeof(PRINTER_INFO_4)); + utf_str = JNU_NewStringPlatform(env, info4->pPrinterName); + if (utf_str == NULL) { + throw std::bad_alloc(); + } + env->SetObjectArrayElement(nameArray, i, utf_str); + env->DeleteLocalRef(utf_str); + } + } catch (std::bad_alloc&) { + delete [] pPrinterEnum; + delete [] pNetworkPrinterLoc; + throw; + } + + delete [] pPrinterEnum; + delete [] pNetworkPrinterLoc; + return nameArray; + + CATCH_BAD_ALLOC_RET(NULL); +} JNIEXPORT jfloatArray JNICALL Java_sun_print_Win32PrintService_getMediaPrintableArea(JNIEnv *env,