AddPrinter() function hang and doesn't return anything.

I am using AddPrinter() function to add a local printer. My operating system is Windows 8. But it got stuck and doesn't return any value.

Here is my code snippet.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

// Define Printer information structure
PRINTER_INFO_2 pi;
BOOL Result = FALSE;
HANDLE pHd;
DWORD m_errorCode;
// Memory initialisation - pi structure to zero
memset(&pi,0,sizeof(PRINTER_INFO_2));
pi.pPrinterName ="MyPrinter";
// Select Driver Name
pi.pDriverName = "MyPrinter";
// Select Share Name
pi.pShareName ="MyPrinter";
// Select Server Name
pi.pServerName = NULL;
// Select Port Name
pi.pPortName ="COM3:";
pi.pSecurityDescriptor = NULL;
// Select Print Processor
pi.pPrintProcessor = L"winprint";
// Select Attributes
pi.Attributes=PRINTER_ATTRIBUTE_DEFAULT | PRINTER_ATTRIBUTE_DO_COMPLETE_FIRST;
// Set Priority
pi.Priority = 1;
// Call the function AddPrinter
pHd = AddPrinter(NULL,2,(LPBYTE)&pi);


I also used AddPrinterDriverEx() before AddPrinter() and it return successful.
But AddPrinter() hang and doesn't return anything.This code is running successfully in Windows 7 but got stuck in Windows 8.

Waiting for valuable reply.
Topic archived. No new replies allowed.