< prev index next >

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

Print this page

        

*** 247,257 **** 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]; --- 247,257 ---- jstring utf_str; jclass clazz = env->FindClass("java/lang/String"); if (clazz == NULL) { return NULL; } ! jobjectArray nameArray = 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 *) --- 268,285 ---- 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 **** --- 297,312 ---- throw; } delete [] pPrinterEnum; delete [] pNetworkPrinterLoc; + + if (nameArray != NULL) { return nameArray; + } else { + return env->NewObjectArray(0, clazz, NULL); + } CATCH_BAD_ALLOC_RET(NULL); } JNIEXPORT jfloatArray JNICALL
< prev index next >