Skip to main content

[archive] Selecting Printers from MS Word

  • November 17, 2007
  • 16 replies
  • 0 views

[Migrated content. Thread originally posted on 16 November 2007]

Questions first:
1) If there is anything for the WINPRINT-PORT, it will be filled in automatically upon your call to WINPRINT-GET-CURRENT-INFO-EX. It is not to be set prior to this call.

2) No. using WINPRINT-SET-PRINTER-EX only affects the ACUCOBOL-GT runtime, it has no effect on Word.

What I would do, is to figure out what the difference is.
First, create a COBOL program that fetches all installed printers on the machine and write the names to a file.
Then write a cobol program that inquires ActivePrinter for its current presentation.
Please compare then, the name of the printer as returned from ActivePrinter and the corresponding value in the listing you generated. I have no idea what to expect, but evidently the problem is in the naming convention.

16 replies

[Migrated content. Thread originally posted on 16 November 2007]

Questions first:
1) If there is anything for the WINPRINT-PORT, it will be filled in automatically upon your call to WINPRINT-GET-CURRENT-INFO-EX. It is not to be set prior to this call.

2) No. using WINPRINT-SET-PRINTER-EX only affects the ACUCOBOL-GT runtime, it has no effect on Word.

What I would do, is to figure out what the difference is.
First, create a COBOL program that fetches all installed printers on the machine and write the names to a file.
Then write a cobol program that inquires ActivePrinter for its current presentation.
Please compare then, the name of the printer as returned from ActivePrinter and the corresponding value in the listing you generated. I have no idea what to expect, but evidently the problem is in the naming convention.
I'm generating MS Word documents directly from Acucobol-GT using Active-X.
Everything generates fine.

I want to actually have the file printed directly to a network printer.

I have a routine that "Captures" printers, and saves the results returned by the WIN$PRINTER USING WINPRINT-GET-CURRENT-INFO-EX ..... call. (In particular keeping the name returned WINPRINT-NAME.

So in my printing routine, I'm using the name, (from WINPRINT-NAME), as follows to have WORD select the correct printer:

MODIFY my-word-app-handle @ActivePrinter = WINPRINT-NAME.
MODIFY word-doc-handle @Printout().

On my own simple non-networked Windows system, this works just fine. It actually prints out on the selected printer.
When I install this on a networked system it returns a "System print Error".

1) Do I have to somehow establish the Printer Port as returned in the WINPRINT-PORT field of WINPRINT-SELECTION (as returned from WIN$PRINTER ?

2) Do I actually have to call WIN$PRINTER USING WINPRINT-SET-PRINTER-EX .... to select the printer ?

Anyone have ideas or experience with this ?

[Migrated content. Thread originally posted on 16 November 2007]

Questions first:
1) If there is anything for the WINPRINT-PORT, it will be filled in automatically upon your call to WINPRINT-GET-CURRENT-INFO-EX. It is not to be set prior to this call.

2) No. using WINPRINT-SET-PRINTER-EX only affects the ACUCOBOL-GT runtime, it has no effect on Word.

What I would do, is to figure out what the difference is.
First, create a COBOL program that fetches all installed printers on the machine and write the names to a file.
Then write a cobol program that inquires ActivePrinter for its current presentation.
Please compare then, the name of the printer as returned from ActivePrinter and the corresponding value in the listing you generated. I have no idea what to expect, but evidently the problem is in the naming convention.
I'm generating MS Word documents directly from Acucobol-GT using Active-X.
Everything generates fine.

I want to actually have the file printed directly to a network printer.

I have a routine that "Captures" printers, and saves the results returned by the WIN$PRINTER USING WINPRINT-GET-CURRENT-INFO-EX ..... call. (In particular keeping the name returned WINPRINT-NAME.

So in my printing routine, I'm using the name, (from WINPRINT-NAME), as follows to have WORD select the correct printer:

MODIFY my-word-app-handle @ActivePrinter = WINPRINT-NAME.
MODIFY word-doc-handle @Printout().

On my own simple non-networked Windows system, this works just fine. It actually prints out on the selected printer.
When I install this on a networked system it returns a "System print Error".

1) Do I have to somehow establish the Printer Port as returned in the WINPRINT-PORT field of WINPRINT-SELECTION (as returned from WIN$PRINTER ?

2) Do I actually have to call WIN$PRINTER USING WINPRINT-SET-PRINTER-EX .... to select the printer ?

Anyone have ideas or experience with this ?

[Migrated content. Thread originally posted on 16 November 2007]

Questions first:
1) If there is anything for the WINPRINT-PORT, it will be filled in automatically upon your call to WINPRINT-GET-CURRENT-INFO-EX. It is not to be set prior to this call.

2) No. using WINPRINT-SET-PRINTER-EX only affects the ACUCOBOL-GT runtime, it has no effect on Word.

What I would do, is to figure out what the difference is.
First, create a COBOL program that fetches all installed printers on the machine and write the names to a file.
Then write a cobol program that inquires ActivePrinter for its current presentation.
Please compare then, the name of the printer as returned from ActivePrinter and the corresponding value in the listing you generated. I have no idea what to expect, but evidently the problem is in the naming convention.
You probably already have done this, but you could also record a macro in Word that prints in that network situation and compare the VB code generated to the COBOL code you wrote.

[Migrated content. Thread originally posted on 16 November 2007]

Questions first:
1) If there is anything for the WINPRINT-PORT, it will be filled in automatically upon your call to WINPRINT-GET-CURRENT-INFO-EX. It is not to be set prior to this call.

2) No. using WINPRINT-SET-PRINTER-EX only affects the ACUCOBOL-GT runtime, it has no effect on Word.

What I would do, is to figure out what the difference is.
First, create a COBOL program that fetches all installed printers on the machine and write the names to a file.
Then write a cobol program that inquires ActivePrinter for its current presentation.
Please compare then, the name of the printer as returned from ActivePrinter and the corresponding value in the listing you generated. I have no idea what to expect, but evidently the problem is in the naming convention.
You probably already have done this, but you could also record a macro in Word that prints in that network situation and compare the VB code generated to the COBOL code you wrote.

[Migrated content. Thread originally posted on 16 November 2007]

Questions first:
1) If there is anything for the WINPRINT-PORT, it will be filled in automatically upon your call to WINPRINT-GET-CURRENT-INFO-EX. It is not to be set prior to this call.

2) No. using WINPRINT-SET-PRINTER-EX only affects the ACUCOBOL-GT runtime, it has no effect on Word.

What I would do, is to figure out what the difference is.
First, create a COBOL program that fetches all installed printers on the machine and write the names to a file.
Then write a cobol program that inquires ActivePrinter for its current presentation.
Please compare then, the name of the printer as returned from ActivePrinter and the corresponding value in the listing you generated. I have no idea what to expect, but evidently the problem is in the naming convention.
I do record macros from WORD or EXCEL to see what VB calls are made to perform whatever function I want to code into my AcuCOBOL routines.

Thanks for the suggestion.

Re 1st suggestion ....
I inserted a line immediately after the MODIFY, to see what gets set on the system that isn't networked:

MODIFY MY-WORD-APP-HANDLE @ActivePrinter = WIN-PRINTER-NAME
INQUIRE MY-WORD-APP-HANDLE @ActivePrinter IN WS-GET-NAME-SET

When WIN-PRINTER-NAME had a value "Canon MP780"
after execution, WS-GET-NAME-SET had a value "Canon MP780 on NE04:"

It would appear as if I need to somehow find out where NE04: came from
and append that to my WIN-PRINTER-NAME before the MODIFY ....

Anyone have any ideas ?

[Migrated content. Thread originally posted on 16 November 2007]

Questions first:
1) If there is anything for the WINPRINT-PORT, it will be filled in automatically upon your call to WINPRINT-GET-CURRENT-INFO-EX. It is not to be set prior to this call.

2) No. using WINPRINT-SET-PRINTER-EX only affects the ACUCOBOL-GT runtime, it has no effect on Word.

What I would do, is to figure out what the difference is.
First, create a COBOL program that fetches all installed printers on the machine and write the names to a file.
Then write a cobol program that inquires ActivePrinter for its current presentation.
Please compare then, the name of the printer as returned from ActivePrinter and the corresponding value in the listing you generated. I have no idea what to expect, but evidently the problem is in the naming convention.
I do record macros from WORD or EXCEL to see what VB calls are made to perform whatever function I want to code into my AcuCOBOL routines.

Thanks for the suggestion.

Re 1st suggestion ....
I inserted a line immediately after the MODIFY, to see what gets set on the system that isn't networked:

MODIFY MY-WORD-APP-HANDLE @ActivePrinter = WIN-PRINTER-NAME
INQUIRE MY-WORD-APP-HANDLE @ActivePrinter IN WS-GET-NAME-SET

When WIN-PRINTER-NAME had a value "Canon MP780"
after execution, WS-GET-NAME-SET had a value "Canon MP780 on NE04:"

It would appear as if I need to somehow find out where NE04: came from
and append that to my WIN-PRINTER-NAME before the MODIFY ....

Anyone have any ideas ?

[Migrated content. Thread originally posted on 16 November 2007]

Questions first:
1) If there is anything for the WINPRINT-PORT, it will be filled in automatically upon your call to WINPRINT-GET-CURRENT-INFO-EX. It is not to be set prior to this call.

2) No. using WINPRINT-SET-PRINTER-EX only affects the ACUCOBOL-GT runtime, it has no effect on Word.

What I would do, is to figure out what the difference is.
First, create a COBOL program that fetches all installed printers on the machine and write the names to a file.
Then write a cobol program that inquires ActivePrinter for its current presentation.
Please compare then, the name of the printer as returned from ActivePrinter and the corresponding value in the listing you generated. I have no idea what to expect, but evidently the problem is in the naming convention.
I do record macros from WORD or EXCEL to see what VB calls are made to perform whatever function I want to code into my AcuCOBOL routines.

Thanks for the suggestion.

Re 1st suggestion ....
I inserted a line immediately after the MODIFY, to see what gets set on the system that isn't networked:

MODIFY MY-WORD-APP-HANDLE @ActivePrinter = WIN-PRINTER-NAME
INQUIRE MY-WORD-APP-HANDLE @ActivePrinter IN WS-GET-NAME-SET

When WIN-PRINTER-NAME had a value "Canon MP780"
after execution, WS-GET-NAME-SET had a value "Canon MP780 on NE04:"

It would appear as if I need to somehow find out where NE04: came from
and append that to my WIN-PRINTER-NAME before the MODIFY ....

Anyone have any ideas ?

[Migrated content. Thread originally posted on 16 November 2007]

Questions first:
1) If there is anything for the WINPRINT-PORT, it will be filled in automatically upon your call to WINPRINT-GET-CURRENT-INFO-EX. It is not to be set prior to this call.

2) No. using WINPRINT-SET-PRINTER-EX only affects the ACUCOBOL-GT runtime, it has no effect on Word.

What I would do, is to figure out what the difference is.
First, create a COBOL program that fetches all installed printers on the machine and write the names to a file.
Then write a cobol program that inquires ActivePrinter for its current presentation.
Please compare then, the name of the printer as returned from ActivePrinter and the corresponding value in the listing you generated. I have no idea what to expect, but evidently the problem is in the naming convention.
If you read the registry under HKEY_LOCAL_MACHINE, and this hive:

software\\microsoft\\windows nt\\currentversion\\print\\providers\\LanMan Print Services\\Servers\\YourServerName

You will find a subkey with the name of your printer, for instance "Canon MP780"

Here you will find a value named "Port" this will contain the NExx: value assigned to this printer, if any. Then, using INSPECT REPLACING and STRING should help you create a Word compatible string.

This is however really odd of Microsoft. The NExx: id is something that was introduced with NT 4.0 to circumvent the problem that many applications back then would not be able to access a printer using a UNC path. I would however have expected Microsoft's own products to use the UNC path.
Oh well... Hope this helps.

[Migrated content. Thread originally posted on 16 November 2007]

Questions first:
1) If there is anything for the WINPRINT-PORT, it will be filled in automatically upon your call to WINPRINT-GET-CURRENT-INFO-EX. It is not to be set prior to this call.

2) No. using WINPRINT-SET-PRINTER-EX only affects the ACUCOBOL-GT runtime, it has no effect on Word.

What I would do, is to figure out what the difference is.
First, create a COBOL program that fetches all installed printers on the machine and write the names to a file.
Then write a cobol program that inquires ActivePrinter for its current presentation.
Please compare then, the name of the printer as returned from ActivePrinter and the corresponding value in the listing you generated. I have no idea what to expect, but evidently the problem is in the naming convention.
If you read the registry under HKEY_LOCAL_MACHINE, and this hive:

software\\microsoft\\windows nt\\currentversion\\print\\providers\\LanMan Print Services\\Servers\\YourServerName

You will find a subkey with the name of your printer, for instance "Canon MP780"

Here you will find a value named "Port" this will contain the NExx: value assigned to this printer, if any. Then, using INSPECT REPLACING and STRING should help you create a Word compatible string.

This is however really odd of Microsoft. The NExx: id is something that was introduced with NT 4.0 to circumvent the problem that many applications back then would not be able to access a printer using a UNC path. I would however have expected Microsoft's own products to use the UNC path.
Oh well... Hope this helps.

[Migrated content. Thread originally posted on 16 November 2007]

Questions first:
1) If there is anything for the WINPRINT-PORT, it will be filled in automatically upon your call to WINPRINT-GET-CURRENT-INFO-EX. It is not to be set prior to this call.

2) No. using WINPRINT-SET-PRINTER-EX only affects the ACUCOBOL-GT runtime, it has no effect on Word.

What I would do, is to figure out what the difference is.
First, create a COBOL program that fetches all installed printers on the machine and write the names to a file.
Then write a cobol program that inquires ActivePrinter for its current presentation.
Please compare then, the name of the printer as returned from ActivePrinter and the corresponding value in the listing you generated. I have no idea what to expect, but evidently the problem is in the naming convention.
Mind one thing though, as this is in the HKEY_LOCAL_MACHINE hive, you may run into access issues depending on the current security setting for the user.

[Migrated content. Thread originally posted on 16 November 2007]

Questions first:
1) If there is anything for the WINPRINT-PORT, it will be filled in automatically upon your call to WINPRINT-GET-CURRENT-INFO-EX. It is not to be set prior to this call.

2) No. using WINPRINT-SET-PRINTER-EX only affects the ACUCOBOL-GT runtime, it has no effect on Word.

What I would do, is to figure out what the difference is.
First, create a COBOL program that fetches all installed printers on the machine and write the names to a file.
Then write a cobol program that inquires ActivePrinter for its current presentation.
Please compare then, the name of the printer as returned from ActivePrinter and the corresponding value in the listing you generated. I have no idea what to expect, but evidently the problem is in the naming convention.
Mind one thing though, as this is in the HKEY_LOCAL_MACHINE hive, you may run into access issues depending on the current security setting for the user.

[Migrated content. Thread originally posted on 16 November 2007]

Questions first:
1) If there is anything for the WINPRINT-PORT, it will be filled in automatically upon your call to WINPRINT-GET-CURRENT-INFO-EX. It is not to be set prior to this call.

2) No. using WINPRINT-SET-PRINTER-EX only affects the ACUCOBOL-GT runtime, it has no effect on Word.

What I would do, is to figure out what the difference is.
First, create a COBOL program that fetches all installed printers on the machine and write the names to a file.
Then write a cobol program that inquires ActivePrinter for its current presentation.
Please compare then, the name of the printer as returned from ActivePrinter and the corresponding value in the listing you generated. I have no idea what to expect, but evidently the problem is in the naming convention.
I resolved the problem.
Depending on what server the Thin-Client, or Fat-Client user was connected to, the printers in question were being processed by differnet Print Servers. Even though they were defined with the same names, if Captured under one printer server, it could not be accessed when running under the other server. The problem went away when the network manager re-defined the printers under one common server.

[Migrated content. Thread originally posted on 16 November 2007]

Questions first:
1) If there is anything for the WINPRINT-PORT, it will be filled in automatically upon your call to WINPRINT-GET-CURRENT-INFO-EX. It is not to be set prior to this call.

2) No. using WINPRINT-SET-PRINTER-EX only affects the ACUCOBOL-GT runtime, it has no effect on Word.

What I would do, is to figure out what the difference is.
First, create a COBOL program that fetches all installed printers on the machine and write the names to a file.
Then write a cobol program that inquires ActivePrinter for its current presentation.
Please compare then, the name of the printer as returned from ActivePrinter and the corresponding value in the listing you generated. I have no idea what to expect, but evidently the problem is in the naming convention.
I resolved the problem.
Depending on what server the Thin-Client, or Fat-Client user was connected to, the printers in question were being processed by differnet Print Servers. Even though they were defined with the same names, if Captured under one printer server, it could not be accessed when running under the other server. The problem went away when the network manager re-defined the printers under one common server.

[Migrated content. Thread originally posted on 16 November 2007]

Questions first:
1) If there is anything for the WINPRINT-PORT, it will be filled in automatically upon your call to WINPRINT-GET-CURRENT-INFO-EX. It is not to be set prior to this call.

2) No. using WINPRINT-SET-PRINTER-EX only affects the ACUCOBOL-GT runtime, it has no effect on Word.

What I would do, is to figure out what the difference is.
First, create a COBOL program that fetches all installed printers on the machine and write the names to a file.
Then write a cobol program that inquires ActivePrinter for its current presentation.
Please compare then, the name of the printer as returned from ActivePrinter and the corresponding value in the listing you generated. I have no idea what to expect, but evidently the problem is in the naming convention.
I resolved the problem.
Depending on what server the Thin-Client, or Fat-Client user was connected to, the printers in question were being processed by differnet Print Servers. Even though they were defined with the same names, if Captured under one printer server, it could not be accessed when running under the other server. The problem went away when the network manager re-defined the printers under one common server.

[Migrated content. Thread originally posted on 16 November 2007]

Questions first:
1) If there is anything for the WINPRINT-PORT, it will be filled in automatically upon your call to WINPRINT-GET-CURRENT-INFO-EX. It is not to be set prior to this call.

2) No. using WINPRINT-SET-PRINTER-EX only affects the ACUCOBOL-GT runtime, it has no effect on Word.

What I would do, is to figure out what the difference is.
First, create a COBOL program that fetches all installed printers on the machine and write the names to a file.
Then write a cobol program that inquires ActivePrinter for its current presentation.
Please compare then, the name of the printer as returned from ActivePrinter and the corresponding value in the listing you generated. I have no idea what to expect, but evidently the problem is in the naming convention.
Good work! Thanks for sharing this.

[Migrated content. Thread originally posted on 16 November 2007]

Questions first:
1) If there is anything for the WINPRINT-PORT, it will be filled in automatically upon your call to WINPRINT-GET-CURRENT-INFO-EX. It is not to be set prior to this call.

2) No. using WINPRINT-SET-PRINTER-EX only affects the ACUCOBOL-GT runtime, it has no effect on Word.

What I would do, is to figure out what the difference is.
First, create a COBOL program that fetches all installed printers on the machine and write the names to a file.
Then write a cobol program that inquires ActivePrinter for its current presentation.
Please compare then, the name of the printer as returned from ActivePrinter and the corresponding value in the listing you generated. I have no idea what to expect, but evidently the problem is in the naming convention.
Good work! Thanks for sharing this.