Highlighted
Absent Member.
Absent Member.
987 views

[archive] Selecting Printers from MS Word

[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.
0 Likes
7 Replies
Highlighted
Absent Member.
Absent Member.

RE: [archive] Selecting Printers from MS Word

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 ?
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Selecting Printers from MS Word

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.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Selecting Printers from MS Word

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 ?
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Selecting Printers from MS Word

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.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Selecting Printers from MS Word

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.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Selecting Printers from MS Word

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.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Selecting Printers from MS Word

Good work! Thanks for sharing this.
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.