none
Wrong printer name given by ActivePrinter RRS feed

  • Question

  • Hello to everybody,
    I'm developing a VB.NET 3.5 library with COM interface that is used by a VBA application to print documents over a network printer. The VBA application passes a word document to the application in this way:

     

    Public Function InitPrint(ByRef strAppName As String, ByRef objDoc As Microsoft.Office.Interop.Word.Document) As Short Implements IInit.InitPrint

    ...

       Dim printerName as string = objDoc.Application.ActivePrinter

    ...

       lngReturn = OpenPrinter(printerName, lngPrinter, pDef)
       GetPrinterW(printerName, .... )

    ...

    End Function

     

    As you can see, I read the objDoc.Application.ActivePrinter name and ask windows for properties of that printer using GetPrinterW API call. What it happens is that in my PC (W7 + W2010) this works, while it does not in my customer PC, which is a Vista + W2007. Specifically, in his environment the printer named "SOMEPRINTER" is given as "SOMEPRINTER ON NExx", so the procedure fails.

    Now, can someone tell me why in some environments ActivePrinter gives the same name of the OS printer, while in other cases not? Is the office different version? Is the operative system version? Or something else?

    Also, is there a workaround to this?

    Thanks, Fabrizio

     

     

    Friday, November 11, 2011 4:00 PM

Answers

  • Hello to everybody,

    turned out that all versions of Word, apart the version 2010, change the printer name to add the printer port. So, I simply check for the printer name prior to pass it to the GetPrinterW function, and remove the annoying " on NExx:" when I find a ':' character. It seems to work nicely.

     

    Fabrizio

    • Marked as answer by Dragoncino Tuesday, November 15, 2011 12:39 PM
    Tuesday, November 15, 2011 12:39 PM