mirror of https://github.com/FreeRDP/FreeRDP
Merge pull request #3865 from DavBfr/unicode-printer-name
Bugfix: Wrong encoding method used for printer name
This commit is contained in:
commit
1833e4ba7d
|
@ -181,10 +181,9 @@ static void printer_win_free_printer(rdpPrinter* printer)
|
|||
}
|
||||
|
||||
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;
|
||||
wchar_t wname[256];
|
||||
DWORD needed;
|
||||
int status;
|
||||
PRINTER_INFO_2 *prninfo=NULL;
|
||||
|
@ -194,7 +193,12 @@ static rdpPrinter* printer_win_new_printer(rdpWinPrinterDriver* win_driver,
|
|||
return NULL;
|
||||
|
||||
win_printer->printer.id = win_driver->id_sequence++;
|
||||
win_printer->printer.name = _strdup(name);
|
||||
if (ConvertFromUnicode(CP_UTF8, 0, name, -1, &win_printer->printer.name, 0, NULL, NULL) < 1)
|
||||
{
|
||||
free(win_printer);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!win_printer->printer.name)
|
||||
{
|
||||
free(win_printer);
|
||||
|
@ -206,10 +210,20 @@ static rdpPrinter* printer_win_new_printer(rdpWinPrinterDriver* win_driver,
|
|||
win_printer->printer.FindPrintJob = printer_win_find_printjob;
|
||||
win_printer->printer.Free = printer_win_free_printer;
|
||||
|
||||
swprintf(wname, 256, L"%hs", name);
|
||||
OpenPrinter(wname, &(win_printer->hPrinter), NULL);
|
||||
if (!OpenPrinter(name, &(win_printer->hPrinter), NULL))
|
||||
{
|
||||
free(win_printer->printer.name);
|
||||
free(win_printer);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!GetPrinter(win_printer->hPrinter, 2, (LPBYTE) prninfo, 0, &needed))
|
||||
{
|
||||
free(win_printer->printer.name);
|
||||
free(win_printer);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
GetPrinter(win_printer->hPrinter, 2, (LPBYTE) prninfo, 0, &needed);
|
||||
prninfo = (PRINTER_INFO_2*) GlobalAlloc(GPTR,needed);
|
||||
if (!prninfo)
|
||||
{
|
||||
|
@ -217,7 +231,14 @@ static rdpPrinter* printer_win_new_printer(rdpWinPrinterDriver* win_driver,
|
|||
free(win_printer);
|
||||
return NULL;
|
||||
}
|
||||
GetPrinter(win_printer->hPrinter, 2, (LPBYTE) prninfo, needed, &needed);
|
||||
|
||||
if (!GetPrinter(win_printer->hPrinter, 2, (LPBYTE) prninfo, needed, &needed))
|
||||
{
|
||||
GlobalFree(prninfo);
|
||||
free(win_printer->printer.name);
|
||||
free(win_printer);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (drivername)
|
||||
status = ConvertFromUnicode(CP_UTF8, 0, drivername, -1, &win_printer->printer.driver, 0, NULL, NULL);
|
||||
|
@ -239,8 +260,6 @@ static rdpPrinter** printer_win_enum_printers(rdpPrinterDriver* driver)
|
|||
rdpPrinter** printers;
|
||||
int num_printers;
|
||||
int i;
|
||||
char pname[1000];
|
||||
size_t charsConverted;
|
||||
PRINTER_INFO_2* prninfo = NULL;
|
||||
DWORD needed, returned;
|
||||
|
||||
|
@ -270,9 +289,8 @@ static rdpPrinter** printer_win_enum_printers(rdpPrinterDriver* driver)
|
|||
|
||||
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,
|
||||
pname, prninfo[i].pDriverName, 0);
|
||||
prninfo[i].pPrinterName, prninfo[i].pDriverName, 0);
|
||||
}
|
||||
|
||||
GlobalFree(prninfo);
|
||||
|
|
Loading…
Reference in New Issue