Highlighted
Outstanding Contributor.
Outstanding Contributor.
2005 views

Default printer

Jump to solution

Hello,

How I can detect which is the default printer in windows?

I've done various experiments and should not walk away.
If you use PC_PRINTER_INFO PC_PRINTER_OPEN after the printer is set by default prints a blank page.
If you use PC_PRINTER_SET_DEFAULT opens a window to select a printer.
In both cases I can know the default printer but is not very good print a blank page or be closing a window.

Thanks

Alberto Ferraz

0 Likes
1 Solution

Accepted Solutions
Highlighted
Outstanding Contributor.
Outstanding Contributor.

RE: Default printer

Jump to solution

Hi.

Thanks for the solution. It´s work and resolve my problem.

Regarding the type of code used think, maybe for my English, do not have me well explained.

The application I'm doing is developed in Visual Cobol (Visual Studio) and is being developed from scratch.

The reference I made to a migrated application NetExpress was a sample application I unloaded the net to see if there was a solution he needed. This application is containing the COBOL LINK tab.

Thanks again for your help.

Best Regards

Alberto Ferraz

View solution in original post

0 Likes
10 Replies
Highlighted
Absent Member.
Absent Member.

RE: Default printer

Jump to solution

Hi,

You could use the MS API GetDefaultPrinter ( msdn.microsoft.com/.../dd144876.aspx) .

COBOL code snippet

...

      special-names.

          call-convention 74 is stdcall.

...

WSS:

      78 LENGTH-pszBuffer value 100.

      01 pszBuffer         pic x(LENGTH-pszBuffer).

      01 pcchBuffer       DWORD value LENGTH-pszBuffer.

      01 b pic 9(9) comp-5. *>bool.

...

PROCEDURE DIVISION.

...

          call STDCALL "GetDefaultPrinterA"

              using by reference pszBuffer

                    by reference pcchBuffer

              returning b

          if b = 0   display "*--> Pb in GetDefaultPrinter"

                     stop run

          end-if

...

When linking, link with MS lib  Winspool.lib ... delivered by MS.

Regards

Yvon

0 Likes
Highlighted
Outstanding Contributor.
Outstanding Contributor.

RE: Default printer

Jump to solution

Hi Ivon,

Thanks for the answer.

I need more help: how am new to VC do not know how to use Winspool.lib to link the application.

Can you send me an example?

Thanks

Alberto Ferraz

0 Likes
Highlighted
Absent Member.
Absent Member.

RE: Default printer

Jump to solution

in a MS VS Native project, right clicking in project->properties. You should see this text-box 'Link with these libs"... Just add these the full pathname of winspool.lib ( delivered in MS SDK )...

from a VC command prompt, it would have to be: cbllink [-d] XXX.cbl winspool.lib ( assuming it's an the current DIR or LIB envt variables pointing on DIR where winspool.lib is located ) or  cbllink [-d] XXX.cbl 'winspool.lib full path' ...

Regards

Yvon

0 Likes
Highlighted
Outstanding Contributor.
Outstanding Contributor.

RE: Default printer

Jump to solution

Hi again,

I tried to find my project in this field to enter the .LIB but the property is not.

I have a demo withdrawal of the net that has this option and is registered to the Winspool.LIB.

How do I register the LIB in my project?

Send two prints: one of the properties of my project and one of the demo version.

Best regards

Alberto Ferraz

0 Likes
Highlighted
Absent Member.
Absent Member.

RE: Default printer

Jump to solution

I would understand you are using a managed project. Correct?

Than I would believe we should not use the MS native API, but some .NET class to do the work

Regards

Yvon

0 Likes
Highlighted
Outstanding Contributor.
Outstanding Contributor.

RE: Default printer

Jump to solution

Right, I'm using a managed project created by Visual Studio with Visual Cobol.

What is the alternative then? So I can not use the MS native API?

Do you know why my project does not have the "COBOL LINK" tab? The project was imported in NexExpress and was converted. Is it because of this that has the "COBOL LINK"?

Best regards

Alberto Ferraz

0 Likes
Highlighted
Outstanding Contributor.
Outstanding Contributor.

RE: Default printer

Jump to solution

"The project was imported in NexExpress and was converted. Is it because of this that has the "COBOL LINK"?"

This project to which I am referring is that imported the net (enumprint) and that has the tab to register the MS LIB.

Best regards

Alberto Ferraz

0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Default printer

Jump to solution

The COBOL Link tab of the Properties Pages will only exist for native projects as managed code projects do not have a link step. When creating an executable for a native project, each separate program will cause as .obj file to be generated. These .obj files are then run through the system linker to generate an .EXE or .DLL. If the project is being converted from Net Express then it will be a native project, although you might also be generating .int/.gnt code instead of .obj. In managed code the source files are generated as IL code and an assembly is generated containing the compiled programs. Although these have the same extensions as native executables, .EXE/.DLL they are not the same.

To find the default printer in managed code you can use something like the following: For this to work you will have to have a reference to the System.Drawing assembly under Project References.

     $set ilusing"System.Drawing.Printing"
      program-id. Program1 as "testdefaultprinter.Program1".
      data division.
      working-storage section.
      procedure division.
          declare settings as type PrinterSettings = new PrinterSettings
          display settings::PrinterName
          goback.

      end program Program1.

0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Default printer

Jump to solution

I guess a bigger question here would be why are you using managed code? Is this intentional? If you are bringing code over from an existing Net Express program then perhaps you should stay with native code unless there is a technical requirement to use managed code such as modernization using .NET technologies such as Windows Forms, WPF, WCF services, etc.

If you are just getting started in this area I would recommend that you check out the video series:

Visual COBOL In a Nutshell

There is a video that covers Object Code Formats that talks about the differences between native and managed code. There are also videos that will help you get started with the IDE as well such as Projects and Solutions, Debugging, etc.

0 Likes
Highlighted
Outstanding Contributor.
Outstanding Contributor.

RE: Default printer

Jump to solution

Hi.

Thanks for the solution. It´s work and resolve my problem.

Regarding the type of code used think, maybe for my English, do not have me well explained.

The application I'm doing is developed in Visual Cobol (Visual Studio) and is being developed from scratch.

The reference I made to a migrated application NetExpress was a sample application I unloaded the net to see if there was a solution he needed. This application is containing the COBOL LINK tab.

Thanks again for your help.

Best Regards

Alberto Ferraz

View solution in original post

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.