2014-06-12

I got this working after all. I was doing some things wrong, which I only found by starting over with the AmortControl example (which is a .NET example) rather than basing my work on browser.cbl (which is an ACUGUI example). I'm not sure if this helped, but I also changed the NETDEFGEN settings to use the 32-bit .NET 4.0 version of ILASM.EXE. The HTML file: !DOCTYPE html html lang="en" head meta charset="utf-8" title HTML5 + JavaScript Example /title script type="text/javascript" // A function that the .NET ObjectForScripting object can call. // The function receives and displays a message, and then returns // the currently selected client. function getSelectedClient(message) { alert(message); var clients = document.getElementsByName("client"); var client; for (var i = 0; i clients.length; i++) { if (clients[i].type === "radio" && clients[i].checked) { client = clients[i].value; } } return client + " is selected"; } function clientSelected(element) { var client = element.getAttribute("value"); window.external.ScriptEvent("selected", client); } /script /head body" div fieldset legend Select a client, and watch for the response from COBOL. /legend input type="radio" name="client" value="client A" onclick="clientSelected(this)"/ Client A br / input type="radio" name="client" value="client B" onclick="clientSelected(this)"/ Client B br / input type="radio" name="client" value="client C" onclick="clientSelected(this)"/ Client C br / /fieldset /div /body /html The C# file: using System; using System.Windows.Forms; namespace MyNamespace { public delegate void EventFired(); public class MyWebBrowser : WebBrowser { public event EventFired FireEvent; public MyWebBrowser() { Anchor = (AnchorStyles.Bottom | AnchorStyles.Right); ObjectForScripting = this; } public void Go(String UriString) { base.Navigate(UriString); } public void FillParent() { Size = Parent.ClientSize; Top = 0; } public String InvokeScript(String name, string arg) { // Call the specified JavaScript function in the HTML document. Object obj = Document.InvokeScript(name, new Object[] { arg }); // Return what JavaScript returned to us. String s = obj.ToString(); return s; } // The following function is provided as something that // JavaScript can call via IE's window.external object. public void ScriptEvent(String Name, String Data) { if (FireEvent != null) { // This will need to be modified to pass EventArgs. FireEvent(); } } } } The COBOL file: IDENTIFICATION DIVISION. PROGRAM-ID. AMORT. ENVIRONMENT DIVISION. CONFIGURATION SECTION. SPECIAL-NAMES. COPY "MyNamespace.MyWebBrowser.def". . DATA DIVISION. WORKING-STORAGE SECTION. 77 SCREEN-1-HANDLE HANDLE OF WINDOW. 77 KEY-STATUS IS SPECIAL-NAMES CRT STATUS PIC 9(4) VALUE 0. 88 EXIT-PUSHED VALUE 27. 88 MESSAGE-RECEIVED VALUE 95. 88 EVENT-OCCURRED VALUE 96. 88 SCREEN-NO-INPUT-FIELD VALUE 97. 88 SCREEN-TIME-OUT VALUE 99. 01 CONFIGURATION-DATA. 05 WS-LINES PIC S99999V99 VALUE 40. 05 WS-SIZE PIC S99999V99 VALUE 80. 01 URI PIC X(256) VALUE "C:\Windows\Temp\DotNetBrowser\test.html". 01 JAVASCRIPT-RETURN-VAL PIC X(256) VALUE SPACE. COPY "acucobol.def". COPY "acugui.def". COPY "crtvars.def". SCREEN SECTION. 01 SCREEN-1. 03 WB-HANDLE, "MyWebBrowser", NAMESPACE IS "MyNamespace", CLASS-NAME IS "MyWebBrowser", LINE 1, COL 1, LINES WS-LINES, SIZE WS-SIZE EVENT PROCEDURE IS USERCONTROL-EVENTS. PROCEDURE DIVISION. ACCEPT SYSTEM-INFORMATION FROM SYSTEM-INFO. ACCEPT TERMINAL-ABILITIES FROM TERMINAL-INFO. DISPLAY STANDARD GRAPHICAL WINDOW TITLE "Pace Scheduler", TITLE-BAR, NO WRAP, LINES WS-LINES, SIZE WS-SIZE, AUTO-MINIMIZE, COLOR IS 65793, WITH SYSTEM MENU, RESIZABLE, HANDLE IS SCREEN-1-HANDLE. DISPLAY SCREEN-1 UPON SCREEN-1-HANDLE. MODIFY WB-HANDLE "Go"(URI) INITIALIZE KEY-STATUS. PERFORM UNTIL EXIT-PUSHED ACCEPT SCREEN-1 ON EXCEPTION PERFORM EVAL-SCR-EXCEPTION THRU EVAL-SCR-EXCEPTION-EXIT END-ACCEPT IF EVENT-OCCURRED AND EVENT-TYPE = NTF-RESIZED * Resize the .NET control to fill its resized parent. DIVIDE EVENT-DATA-1 BY 100 GIVING WS-LINES DIVIDE EVENT-DATA-2 BY 100 GIVING WS-SIZE MODIFY WB-HANDLE LINES WS-LINES SIZE WS-SIZE MODIFY WB-HANDLE "FillParent"() END-IF END-PERFORM. PERFORM EOJ THRU EOJ-EXIT GOBACK. EVAL-SCR-EXCEPTION. EVALUATE TRUE WHEN EVENT-OCCURRED IF EVENT-TYPE = CMD-CLOSE SET EXIT-PUSHED TO TRUE END-IF END-EVALUATE MOVE 1 TO ACCEPT-CONTROL. EVAL-SCR-EXCEPTION-EXIT. EXIT. USERCONTROL-EVENTS. EVALUATE EVENT-TYPE WHEN MSG-NET-EVENT EVALUATE EVENT-DATA-2 WHEN @MyWebBrowser_FireEvent DISPLAY MESSAGE BOX "COBOL detected the .NET event, " "@MyWebBrowser_FireEvent!" * THE NEXT STATEMENT CALLS A C# FUNCTION IN THE * WEB BROWSER CONTROL, WHICH IN TURN CALLS A * JAVASCRIPT FUNCTION IN THE HTML DOCUMENT. modify wb-handle "InvokeScript"( "getSelectedClient", "COBOL called JavaScript via C#") giving javascript-return-val display message box "COBOL received data from C#: " javascript-return-val END-EVALUATE END-EVALUATE. USER-CONTROL-EVENTS-EXIT. EXIT. EOJ. DESTROY wb-handle. DESTROY screen-1-Handle. EOJ-EXIT. EXIT. The end result is: The COBOL program can use the .NET framework's WebBrowser.ObjectForScripting.InvokeScript function to call JavaScript functions in the WebBrowser's HTML document. JavaScript can call a C# function, which in turn raises a .NET event that is detected by ACUCOBOL. (This is the piece that was broken before.)

Show more