shimshon

hi all.

how can i get the name of the default printer, in c#




Re: Visual C# General how to get the name of the default printer

ShellShock

I think you will have to p/invoke to a Win32 API, e.g., GetDefaultPrinter:

[DllImport("winspool.drv", CharSet=CharSet.Auto, SetLastError=true)]
public static extern bool GetDefaultPrinter(StringBuilder pszBuffer, ref int size);

StringBuilder dp = new StringBuilder(256);
int size = dp.Capacity;
if (GetDefaultPrinter(dp, ref size)) {
Console.WriteLine(String.Format("Printer: {0}, name length {1}", dp.ToString().Trim(), size));
} else {
int rc = GetLastError();
Console.WriteLine(String.Format("Failed. Size: {0}, error: {1:X}", size, rc));
}

This code is from www.pinvoke.net.