CreateDC fails The Printer Name is invalid

Hi all
if I use a printer on a home network, then CreateDC fails. If I use a printer on the local machine then CreateDC works

m_DC = ::CreateDC(L"WINSPOOL", DevInfo->dmDeviceName, NULL, DevInfo);

I get a list of the printer names from
::EnumPrinters(PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS, NULL, 5, Buffer, Needed, &Needed, &TotalPrinters)

from the names, the ones on the home network are preceeded with: \\KIM-PC\\
which I do understand that is the path. What do I need to change to allow the home network printers to work??

Hmm, kinda hard to figure it out.
This might be one problem.
From msdn
If Level is 2 or 5,Name is a pointer to a null-terminated string that specifies
 the name of a server whose printers are to be enumerated. If this string is 
NULL, then the function enumerates the printers installed on the local 
. I observe that you pass NULL for the name, so in this case the network printers might not be listed.
Also have you tried to output the dm_DeviceName, or what is returned from the EnumPrinters
Last edited on
thank you for the reply.
The problem isn't enumprinters, it does supply the printer name, even if Name = NULL

msdn:When Name is NULL, setting Flags to PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS enumerates printers that are installed on the local machine. These printers include those that are physically attached to the local machine as well as remote printers to which it has a network connection.

the problem is in the lpszDevice is not accepted from the enumeration. I guess I'll need to figure another way to get the DC
oops! Ok figured it out.

A zero-terminated character array that specifies the "friendly" name of the printer or display; for example, "PCL/HP LaserJet" in the case of PCL/HP LaserJet. This string is unique among device drivers. Note that this name may be truncated to fit in the dmDeviceName array.

I maded a call to DocumentProperties with the my DEVMODE, the name was truncated, this is why it fails, I simply save the name and do not use the DEVMODE->dmDevicName, as it is truncated, do to length, and is then incorrect
Good catch :)
Topic archived. No new replies allowed.