Index: win/tkWinGDI.c
==================================================================
--- win/tkWinGDI.c
+++ win/tkWinGDI.c
@@ -3633,18 +3633,25 @@
 	    printDC = CreateDCW(L"WINSPOOL", printerName, NULL, localDevmode);
 	} else {
 	    localDevmode = NULL;
 	}
     } else {
+	unsigned int errorcode = CommDlgExtendedError();
 	/*
 	 * The user cancelled, or there was an error
 	 * The code on the Tcl side checks if the variable
 	 * ::tk::print::printer_name is defined to determine
 	 * that a valid selection was made.
 	 * So we better unset this here, unconditionally.
 	 */
 	Tcl_UnsetVar(interp, "::tk::print::printer_name", 0);
+	if (errorcode != 0) {
+	    Tcl_SetObjResult(interp, Tcl_ObjPrintf("print failed: error %04x",
+		errorcode));
+	    Tcl_SetErrorCode(interp, "TK", "PRINT", "DIALOG", (char *)NULL);
+	    return TCL_ERROR;
+	}
 	return TCL_OK;
     }
 
     if (pd.hDevMode != NULL) {
 	GlobalFree(pd.hDevMode);
@@ -3653,17 +3660,17 @@
     /*
      * Store print properties in variables so they can be accessed from
      * script level.
      */
     if (localPrinterName != NULL) {
-#define PRNAME_MAX_LEN 100
-	char prname[PRNAME_MAX_LEN];
+	char *prname;
 	int size_needed = WideCharToMultiByte(CP_UTF8, 0, localPrinterName,
 		-1, NULL, 0, NULL, NULL);
+	prname = (char *)ckalloc(size_needed);
+
 	WideCharToMultiByte(CP_UTF8, 0, localPrinterName, -1, prname,
 		size_needed, NULL, NULL);
-
 	Tcl_SetVar2Ex(interp, "::tk::print::printer_name", NULL,
 		Tcl_NewStringObj(prname, size_needed - 1), 0);
 	Tcl_SetVar2Ex(interp, "::tk::print::copies", NULL,
 		Tcl_NewIntObj(copies), 0);
 	Tcl_SetVar2Ex(interp, "::tk::print::dpi_x", NULL,
@@ -3672,10 +3679,11 @@
 		Tcl_NewIntObj(dpi_y), 0);
 	Tcl_SetVar2Ex(interp, "::tk::print::paper_width", NULL,
 		Tcl_NewIntObj(paper_width), 0);
 	Tcl_SetVar2Ex(interp, "::tk::print::paper_height", NULL,
 		Tcl_NewIntObj(paper_height), 0);
+	ckfree(prname);
     }
 
     return TCL_OK;
 }
 

