2

I have a COBOL program that calls a VB6 program, which reads data from a weight scale using COM port.

STRING WS-PATH, '\', LINK-KEY, '\vb.exe' DELIMITED BY ' ' INTO WS-COMMAND.
CALL   'SYSTEM' USING WS-COMMAND 128 GIVING WS-STATUS.
CANCEL 'SYSTEM'.

The data is saved into a TXT file, then the COBOL program opens the TXT and reads the data.

Dim i_data_file As Integer
    i_data_file = FreeFile
    Open App.Path & "\data.txt" For Binary Access Write As #i_data_file
    Put #i_data_file, , data
    Close #i_data_file
STRING '@[DISPLAY]:', WS-PATH, '\', LINK-KEY, '\data.txt' DELIMITED BY ' ' INTO WS-SOURCE
STRING WS-PREFIX2, WEIGHT-DATANAME DELIMITED BY ' ' INTO WS-TARGET
CALL   'C$COPY' USING WS-SOURCE, WS-TARGET GIVING WS-STATUS
CANCEL 'C$COPY'

Everything works fine so far, but is it possible to pass and receive data between the programs directly without creating any file?

Edit: So I created a DLL and used axdefgen for testing purposes:

      * clsMath
           CLASS @clsMath
               CLSID, 073F9971-1BE7-45A7-B50F-82AAAC511268
               NAME, "clsMath"
               PRIMARY-INTERFACE
               DEFAULT-INTERFACE, "_clsMath"
      * fSum
               METHOD, 1610809344, @fSum,
                   "long" @2, TYPE 3,
                   "long" @1, TYPE 3
                       RETURNING "long", TYPE 3

Now how do I call/pass parameters to the function fSum? I tried this:

           CREATE clsMath
                  SERVER-NAME IS '128.0.0.220'
                  HANDLE IN WS-TEMP.
           INQUIRE WS-TEMP fSum IN WS-TEMP2.
           DISPLAY WS-TEMP2.

And I get this:

'FSUM' must be a 'get' property or method of '@CLSMATH'

Does this mean I need something like this?

PROPERTY-GET, 17, @Day RETURNING "short"
CHC
  • 21
  • 2

1 Answers1

0

Depending on your execution environment, you might be able to call a system DLL (using CALL). If that's a possibility, you can create a DLL in VB6 through which you could communicate using a various approaches like a Socket or perhaps making your VB6 program an ActiveX EXE that COBOL can instantiate and talk directly to as an out-of-process server.

Étienne Laneville
  • 4,697
  • 5
  • 13
  • 29
  • 1
    There are tons of possibilities in Windows for [Interprocess communication](https://learn.microsoft.com/en-us/windows/win32/ipc/interprocess-communications), depending on your needs and/or capabilities of the programming languages used for the processes in question. A very easy (but unsecure) fileless method for data interchange that comes to mind: the Windows Clipboard. – Hel O'Ween Nov 13 '19 at 12:21
  • 1
    Its also possible to compile a VB6 DLL to be callable like a standard 'C' DLL. I think VBAdvance had some mechanism for that. This might be the most likely to provide an interface the COBOL program could call directly. – StayOnTarget Nov 15 '19 at 12:21
  • @Étienne I have tried your suggestion and edited the question. Please advise. – CHC Dec 12 '19 at 06:41