Highlighted
Absent Member.
Absent Member.
1106 views

How can I launch default browser from COBOL? Thanks

Jump to solution

Hi all,

My environment: VS 2015, VC 2.32, Windows 10

I'm creating an html page (for a report) and I'd like to show it by launching the user's default browser from my COBOL program. What's the best way to do this?

Thank you,

Linden

Linden Rowland - IT Consultant
Owner/Developer, www.SchoolReportWriter.com
IT Consultant to Tindle Newspaper Group

0 Likes
1 Solution

Accepted Solutions
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: How can I launch default browser from COBOL? Thanks

Jump to solution

I you can either use: CBL_EXEC_RUN_UNIT/SYSTEM API with "cmd /c index.html" or use the Windows API ShellExecute.

For example:

      $set sourceformat"variable"
      $set ans85 mf defaultbyte"00" case
       copy "windows.cpy".
       identification division.
       program-id. "OpenHTML".
           call-convention 74 is WinAPI.

       data division.
       working-storage section.

       01 se-hInstance             HINSTANCE.
       01 sw-cwd                   pic x(1024).

       78 SHELL-OPEN-CMD-SIZE      value 5.
       01 ShellOpenCmd             pic x(SHELL-OPEN-CMD-SIZE).
       01 hInstResource            HINSTANCE.
       01 lnk-HtmlDocument         pic x(1024).

       local-storage section.
       01 RetCodeString    INT.

       linkage section.
       01 lnk-hInstResource    HINSTANCE.

       procedure division using by reference lnk-HtmlDocument.
           move z"open" to ShellOpenCmd

      *
      * Assume HTML Document is in the current directory!
      *
           call WinAPI GetCurrentDirectory using
                by value 1024 size 4,
                reference sw-cwd
           end-call
      *
      * ShellExecute is used because ShellExecuteEx is not supported
      * on NT 3.51... perhaps in NT 4.0!
      *
           call WinAPI ShellExecute using
                by value 0 size 4,
                by reference SHellOpenCmd,
                by reference lnk-HtmlDocument
                by value 0 size 4,
                by reference sw-cwd,
                by value SW-SHOWNORMAL
                returning se-hInstance
           end-call

           exit program returning se-hInstance.

 

and to test is use:

            01 html-file        pic x(1024) value z"index.html".

            call "OpenHTML" using by reference html-file

            exhibit named return-code.

 

You need to link with shell32.lib to resolve the ShellExecute API

View solution in original post

0 Likes
2 Replies
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: How can I launch default browser from COBOL? Thanks

Jump to solution

I you can either use: CBL_EXEC_RUN_UNIT/SYSTEM API with "cmd /c index.html" or use the Windows API ShellExecute.

For example:

      $set sourceformat"variable"
      $set ans85 mf defaultbyte"00" case
       copy "windows.cpy".
       identification division.
       program-id. "OpenHTML".
           call-convention 74 is WinAPI.

       data division.
       working-storage section.

       01 se-hInstance             HINSTANCE.
       01 sw-cwd                   pic x(1024).

       78 SHELL-OPEN-CMD-SIZE      value 5.
       01 ShellOpenCmd             pic x(SHELL-OPEN-CMD-SIZE).
       01 hInstResource            HINSTANCE.
       01 lnk-HtmlDocument         pic x(1024).

       local-storage section.
       01 RetCodeString    INT.

       linkage section.
       01 lnk-hInstResource    HINSTANCE.

       procedure division using by reference lnk-HtmlDocument.
           move z"open" to ShellOpenCmd

      *
      * Assume HTML Document is in the current directory!
      *
           call WinAPI GetCurrentDirectory using
                by value 1024 size 4,
                reference sw-cwd
           end-call
      *
      * ShellExecute is used because ShellExecuteEx is not supported
      * on NT 3.51... perhaps in NT 4.0!
      *
           call WinAPI ShellExecute using
                by value 0 size 4,
                by reference SHellOpenCmd,
                by reference lnk-HtmlDocument
                by value 0 size 4,
                by reference sw-cwd,
                by value SW-SHOWNORMAL
                returning se-hInstance
           end-call

           exit program returning se-hInstance.

 

and to test is use:

            01 html-file        pic x(1024) value z"index.html".

            call "OpenHTML" using by reference html-file

            exhibit named return-code.

 

You need to link with shell32.lib to resolve the ShellExecute API

View solution in original post

0 Likes
Highlighted
Absent Member.
Absent Member.

RE: How can I launch default browser from COBOL? Thanks

Jump to solution
Thank you for your reply and time. I will give this a try.
(I'm not getting reply notifications for some reason hence just found your answer - apols.)
Regards, Linden.

Linden Rowland - IT Consultant
Owner/Developer, www.SchoolReportWriter.com
IT Consultant to Tindle Newspaper Group

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.