Bugfix: Wrong encoding method used for printer name.

This commit is contained in:
David PHAM-VAN 2017-03-13 14:55:34 -07:00
parent a9c3b92036
commit 1296756be8

View File

@ -181,10 +181,9 @@ static void printer_win_free_printer(rdpPrinter* printer)
} }
static rdpPrinter* printer_win_new_printer(rdpWinPrinterDriver* win_driver, static rdpPrinter* printer_win_new_printer(rdpWinPrinterDriver* win_driver,
const char* name, const WCHAR* drivername, BOOL is_default) const WCHAR* name, const WCHAR* drivername, BOOL is_default)
{ {
rdpWinPrinter* win_printer; rdpWinPrinter* win_printer;
wchar_t wname[256];
DWORD needed; DWORD needed;
int status; int status;
PRINTER_INFO_2 *prninfo=NULL; PRINTER_INFO_2 *prninfo=NULL;
@ -194,7 +193,8 @@ static rdpPrinter* printer_win_new_printer(rdpWinPrinterDriver* win_driver,
return NULL; return NULL;
win_printer->printer.id = win_driver->id_sequence++; win_printer->printer.id = win_driver->id_sequence++;
win_printer->printer.name = _strdup(name); ConvertFromUnicode(CP_UTF8, 0, name, -1, &win_printer->printer.name, 0, NULL, NULL);
if (!win_printer->printer.name) if (!win_printer->printer.name)
{ {
free(win_printer); free(win_printer);
@ -206,8 +206,7 @@ static rdpPrinter* printer_win_new_printer(rdpWinPrinterDriver* win_driver,
win_printer->printer.FindPrintJob = printer_win_find_printjob; win_printer->printer.FindPrintJob = printer_win_find_printjob;
win_printer->printer.Free = printer_win_free_printer; win_printer->printer.Free = printer_win_free_printer;
swprintf(wname, 256, L"%hs", name); OpenPrinter(name, &(win_printer->hPrinter), NULL);
OpenPrinter(wname, &(win_printer->hPrinter), NULL);
GetPrinter(win_printer->hPrinter, 2, (LPBYTE) prninfo, 0, &needed); GetPrinter(win_printer->hPrinter, 2, (LPBYTE) prninfo, 0, &needed);
prninfo = (PRINTER_INFO_2*) GlobalAlloc(GPTR,needed); prninfo = (PRINTER_INFO_2*) GlobalAlloc(GPTR,needed);
@ -239,8 +238,7 @@ static rdpPrinter** printer_win_enum_printers(rdpPrinterDriver* driver)
rdpPrinter** printers; rdpPrinter** printers;
int num_printers; int num_printers;
int i; int i;
char pname[1000]; char* pname = NULL;
size_t charsConverted;
PRINTER_INFO_2* prninfo = NULL; PRINTER_INFO_2* prninfo = NULL;
DWORD needed, returned; DWORD needed, returned;
@ -270,9 +268,8 @@ static rdpPrinter** printer_win_enum_printers(rdpPrinterDriver* driver)
for (i = 0; i < (int) returned; i++) for (i = 0; i < (int) returned; i++)
{ {
wcstombs_s(&charsConverted, pname, 1000, prninfo[i].pPrinterName, _TRUNCATE);
printers[num_printers++] = printer_win_new_printer((rdpWinPrinterDriver*)driver, printers[num_printers++] = printer_win_new_printer((rdpWinPrinterDriver*)driver,
pname, prninfo[i].pDriverName, 0); prninfo[i].pPrinterName, prninfo[i].pDriverName, 0);
} }
GlobalFree(prninfo); GlobalFree(prninfo);