Showing posts from February, 2007

Adding a printer in VB.NET

I took some time for me before I found out that API AddPrinter can be used to add printer whose driver is already installed. All I wanted to do was to add a Printer if its not present and the driver was built-in Windows XP itself. First I finished adding the printer in VC++ using MFC Application then I wanted to add it using VB.NET either using Declare Function or DllImport by wrapping it in a dll. Then i had to google for a long time when i last arrived at a code that really worked !!! Module Printer_Module 'declare the API in VB Private Declare Function AddPrinter Lib "winspool.drv" Alias "AddPrinterW" _ (ByVal pName As IntPtr, ByVal Level As Int32, _ &#60MarshalAs(UnmanagedType.LPStruct)&#62 ByVal pPrinter As PRINTER_INFO_2) As Int32 ' 'still dont know why PRINTER_INFO_2 is Class instead of a Structure &#60StructLayout(LayoutKind.Sequential)&#62 _ Pu