< prev index next >

src/java.desktop/windows/native/libawt/windows/WPrinterJob.cpp

Print this page

        

*** 248,257 **** --- 248,258 ---- jclass clazz = env->FindClass("java/lang/String"); if (clazz == NULL) { return NULL; } jobjectArray nameArray; + jobjectArray emptyArray = env->NewObjectArray(0, clazz, NULL); try { ::EnumPrinters(PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS, NULL, 4, NULL, 0, &cbNeeded, &cReturned); pPrinterEnum = new BYTE[cbNeeded];
*** 268,284 **** if (info4->Attributes & PRINTER_ATTRIBUTE_NETWORK) { 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 *) --- 269,286 ---- if (info4->Attributes & PRINTER_ATTRIBUTE_NETWORK) { pNetworkPrinterLoc[remotePrintersCount++] = i; } } + // return remote printers only if the list contains it. + if (remotePrintersCount > 0) { // Allocate space only for the network type printers nameArray = env->NewObjectArray(remotePrintersCount, clazz, NULL); if (nameArray == NULL) { throw std::bad_alloc(); } ! } } // Loop thro' network printers list only for (int i = 0; i < remotePrintersCount; i++) { PRINTER_INFO_4 *info4 = (PRINTER_INFO_4 *)
*** 296,306 **** --- 298,313 ---- throw; } delete [] pPrinterEnum; delete [] pNetworkPrinterLoc; + + if (remotePrintersCount) { return nameArray; + } else { + return emptyArray; + } CATCH_BAD_ALLOC_RET(NULL); } JNIEXPORT jfloatArray JNICALL
< prev index next >