GetDefaultPrinter
C# Signature:
[DllImport("winspool.drv", CharSet = CharSet.Auto, SetLastError = true)]
public static extern bool GetDefaultPrinter(StringBuilder pszBuffer, ref int pcchBuffer);VB Signature:
Declare Function GetDefaultPrinter Lib "winspool.drv" Alias "GetDefaultPrinterA" _
(ByVal pszBuffer As System.Text.StringBuilder, ByRef pcchBuffer As Int32) As BooleanSample Code:
int pcchBuffer = 0;
if (GetDefaultPrinter(null, ref pcchBuffer))
{
return null;
}
int lastWin32Error = Marshal.GetLastWin32Error();
if (lastWin32Error == ERROR_INSUFFICIENT_BUFFER)
{
StringBuilder pszBuffer = new StringBuilder(pcchBuffer);
if (GetDefaultPrinter(pszBuffer, ref pcchBuffer))
{
return pszBuffer.ToString();
}
lastWin32Error = Marshal.GetLastWin32Error();
}
if (lastWin32Error == ERROR_FILE_NOT_FOUND)
{
return null;
}
throw new Win32Exception(Marshal.GetLastWin32Error());Sample Code:
Última actualización