Consume web services published on internet

2014-08-19
2014-09-08
  • Tony Girgenti

    Tony Girgenti - 2014-08-19

    Hello,

    Is it possible to use GNU Cobol to write a client that will consume web services published on the internet?

    Any help would be gratefully appreciated.

    Thanks,
    Tony

     
  • Brian Tiffin

    Brian Tiffin - 2014-08-19

    You mean like

    http://opencobol.add1tocobol.com/gnucobol/#how-do-i-use-gnu-cobol-for-cgi (with an eye toward the AJAX and jQuery blurbs?)

    The short answer is yes.

    If the link above doesn't lead to the right info, feel free to ask again. There are other samples in the FAQ as well, libcURL, etc.

    Cheers,
    Brian

     
  • Tony Girgenti

    Tony Girgenti - 2014-08-19

    Hello Brian.

    Thanks for your help.

    I think that is what I want to do except that your cgienvform.html is the client consuming the service of gnucobolcgi and I want to code my client in GNU Cobol.

    Thanks,
    Tony

     
  • Brian Tiffin

    Brian Tiffin - 2014-08-19

    Yeah, consuming...hmmm?

    COBOL, by and large isn't network aware, at least not from the reserved words side of things.

    You could spend a few minutes/hours wrestling with netcat, nc, and forcefudging things through files for READ, WRITE. That will work, but it might be hairpulling.

    libCURL, presents a pretty handy API. Short, steep learning curve, one or two functions later and it is just tweaking flags and names.

    There are socket read libraries available, ezaSockets, and native POSIX

    So, while the short answer is yes, the real answer is more verbose. ;-)

    Umm, take a look at http://opencobol.add1tocobol.com/gnucobol/#function-id

    The sample is a read-url function. Please note: this is working, yet incomplete; ideas into the ether, details may change

    Cheers,
    Brian

     
    Last edit: Brian Tiffin 2014-08-19
  • Tony Girgenti

    Tony Girgenti - 2014-08-19

    Brian,

    I have a consuming client working and I wrote it in Microsoft VS 2013 C# program.

    Can I call a C# program(.dll/.exe) to simply do the consuming and pass the data back to a GNU Cobol program for display and reporting?

    Thanks,
    Tony

     
    • Simon Sobisch

      Simon Sobisch - 2014-08-20

      Not very quick as CALLs from GNU Cobol are "native" with C only, not C++ and in no way C#.

      The quick and dirty way is using an exe-file, and

          CALL 'SYSTEM' using 'c#.exe some params "including text"'
          END-CALL
      

      if you have more things you want to pass write a LINE SEQUENTIAL FILE.
      The way back (despite of the RETURN CODE) would be a LINE SEQUENTIAL FILE.

      The better way would be using a c#.dll, writing a small C++ wrapper with external "C". This wrapper can be called via 'CALL' and you can pass data in both directions, see COBOL<->C.

      This would definitely be a worth entry for the FAQ if you document this with a small sample (COBOL --> [using C++ as a wrapper] --> C#). The other way (C# --> COBOL) is missing in the FAQ, too and likely goes down to import and call cob_resolve, then call the result. Feel free to write the necessary samples and docs, Brian Tiffin will surely add this to the FAQ when finished.

      Simon

       
      • Tony Girgenti

        Tony Girgenti - 2014-08-21

        Simon,

        Do you know how to do this?

        The better way would be using a c#.dll, writing a small C++ wrapper with external "C". This wrapper can be called via 'CALL' and you can pass data in both directions<<

        I would like to try it, but I don't know how to do it.

        Thanks,
        Tony

         
        • Simon Sobisch

          Simon Sobisch - 2014-08-21

          Sure I can help.
          What are the problems when following the steps linked above?

          Simon

           
          • Tony Girgenti

            Tony Girgenti - 2014-08-23

            Simon,

            I have this working:
            http://stackoverflow.com/questions/4139456/how-to-reuse-a-net-assembly-from-a-pure-c-application

            What does the output from the solution need to be to be called from an GNU Open COBOL program?

            Thanks,
            Tony

             
            • Simon Sobisch

              Simon Sobisch - 2014-08-23

              Assuming you have the wrapper program callable as C:

              • check that you have it declared as C_EXTERN (see the old wiki entry that I've linked before)

              • CALL 'SHARPWRAP' USING a-binary-long-if-you-want-to-pass-some-number maybe-a-binary-long-with-parameter-length-for-next-pic-x whatever-you-need-as-pic-x END-CALL

              If it doesn't work please a short sample code of both C# and wrapper. We will tweak and fix it until it works (and can be placed into the FAQ ;-).

              Simon

               
              • Tony Girgenti

                Tony Girgenti - 2014-08-25

                Simon,

                I have been trying to link my COBOL program to a 'C' object file using this command line: "cobc -x -o callcsl callcsl.cob projectctest.obj" and I am getting this error: "projectctest.obj:1: Error: Invalid indicator 'û' at column 7"

                When I build/compile my solution that has the ProjectCTest (plain ANSI 'C'), it gives warnings, not errors. I'm trying to get rid of the warnings to see if that will fix the problem.

                I know you want short sample code, but I will give you these files:

                -------------------- COBOL 2.0 program ---------------------

                        IDENTIFICATION DIVISION.
                        PROGRAM-ID. CallCSL.
                        ENVIRONMENT DIVISION.
                        DATA DIVISION.
                        WORKING-STORAGE SECTION.
                         01 VALUE-A USAGE BINARY-LONG.
                         01 VALUE-B USAGE BINARY-LONG.
                        PROCEDURE DIVISION.
                          CALL "ProjectCTest" USING VALUE-A VALUE-B
                      END-CALL. 
                          STOP RUN.
                

                ---------------- The plain ANSI 'C" program --------------

                #include "stdafx.h"
                #pragma comment(lib, "CPPCLibrary.lib") 
                
                #ifndef C_EXTERN
                #if defined (_WIN32) || defined (__CYGWIN__)
                #define C_EXTERN __declspec(dllexport) extern
                #else
                #define C_EXTERN extern
                #endif
                #endif
                C_EXTERN int;
                extern __declspec(dllimport) int MathAdd(int a, int b);
                int _tmain(int argc, _TCHAR* argv[])
                {
                    int answer = MathAdd(10, 32);
                    _tprintf(_T("%d\n"), answer);
                    while (8 == 8) {}
                    return 0;
                }
                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                
                ------------ The C++ program (CPPCLibrary.h) ---------------
                
                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                ::c++
                #pragma once
                using namespace System;
                namespace CPPCLibrary {
                
                extern "C" __declspec(dllexport) int MathAdd(int a, int b)
                
                {
                    return CSLibrary::Math::Add(a, b);
                    };
                }
                

                --------------------- The C# Program -----------------------

                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                ::csharp
                using System;
                using System.Collections.Generic;
                using System.Linq;
                using System.Text;

                namespace CSLibrary
                {
                static public class Math
                {
                static public int Add(int a, int b)
                {
                int c = a + b;
                return c;
                }
                }
                }
                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

                Of course you know that most of this came from here:
                http://stackoverflow.com/questions/4139456/how-to-reuse-a-net-assembly-from-a-pure-c-application

                Any help that you can provide to make this work would be gratefully appreciated.

                Thanks,
                Tony

                ModEdit: syntax highlighting added

                 
                Last edit: Simon Sobisch 2014-08-26
                • Vincent (Bryan) Coen

                  Need to add -free to cobc command line or add as first line of
                  Cobol source file starting in column 8

                  source free

                  At the moment the compiler thinks your programs is written as fixed format.

                  Vince

                   
                  Last edit: Simon Sobisch 2014-08-27
                  • Vincent (Bryan) Coen

                    Hmm editor seems to be removing the two greater thans signs..
                    ">>source free"

                    See if that is any better :(

                    Vince

                     
                    Last edit: Simon Sobisch 2014-08-26
                    • Tony Girgenti

                      Tony Girgenti - 2014-08-26

                      Vince,

                      I added this ">>SOURCE FORMAT IS FREE" to first line of CallCSL.cob starting in column 8 and got the same error:
                      "projectctest.obj:1: Error: Invalid indicator 'û' at column 7"

                      I also tried "cobc -free -x -o callcsl callcsl.cob projectctest.obj" and
                      "cobc -x -o callcsl -free callcsl.cob projectctest.obj" and got these warnings/errors:

                      projectctest.obj:2: Warning: Line not terminated by a newline
                      projectctest.obj:3: Warning: Line not terminated by a newline
                      projectctest.obj:4: Warning: Line not terminated by a newline
                      projectctest.obj:5: Warning: Line not terminated by a newline
                      projectctest.obj:6: Warning: Line not terminated by a newline
                      projectctest.obj:6: Error: syntax error, unexpected TOKEN, expecting '.'

                      Aren't those warnings/errors referring to projectest.obj?

                      Thanks,
                      Tony

                       
                      • Vincent (Bryan) Coen

                        In a nutshell yes, you are trying to compile through cobc callCSL.cob
                        AND projecttest.obj

                        Suggest you compile the C program first them compile the Cobol program
                        and link it with the o/p from the C compile.

                        Now I am guessing here :) try:

                        cobc -x callcsi cllcsi.cob -l project.o

                        The above is assuming you are using Linux so if using Windows the
                        extension for project may well be .obj.

                        Vince

                         
                        Last edit: Simon Sobisch 2014-08-27
                        • Tony Girgenti

                          Tony Girgenti - 2014-08-26

                          Vince,

                          ProjectCTest.c is compiled in Visual Studio to produce ProjectCTest.obj.

                          I thought this: "cobc -x -o callcsl callcsl.cob projectctest.obj" was compiling callcsl.cob and linking ProjectCTest.obj to it.

                          I'm confused.

                          Thanks,
                          Tony

                           
    • Brian Tiffin

      Brian Tiffin - 2014-08-20

      Along with Simon's response firstly to say, any samples allowed in the FAQ, will get added, happily.

      Tony;

      Umm, C# eh? I'd like to point you at Vala ...

      https://wiki.gnome.org/Projects/Vala

      C# (ish) syntax, 100% compatible, and sympatico, with GNU Cobol.

      Vala is "well bound" to everything libc and glib, networking is well covered. It's not .NET, (and Mono works), but the coverage is vast within glib (GNOME) space, and that space is 100% open to CALL.

      https://wiki.gnome.org/Projects/Vala/GIONetworkingSample

      That's a path, but...

      Direct COBOL with CALL, for the win. libCURL in particular. With a FUNCTION-ID interface. ;-)

      Cheers,
      Brian

       
      Last edit: Brian Tiffin 2014-08-20
  • Vincent (Bryan) Coen

    What you are doing according to the cobc command line is compiling both
    files and the second is an object already so precede '-l' before the
    object module name as shown on my previous message.

    E.g., "cobc -x -o callcsl callcsl.cob -lprojectctest.obj"

    Well that's the way I see it :)

    Vince

     
    Last edit: Simon Sobisch 2014-08-27
    • Tony Girgenti

      Tony Girgenti - 2014-08-26

      Vince,

      I'm sorry for being mixed up about how to do this. I should learn to read more of the documentation and reading people's posts.

      I used this at the command line: "cobc -x -o callcsl callcsl.cob -lProjectCTest.obj"

      I now have this error:
      "ProjectCTest.obj : warning LNK4075: ignoring '/EDITANDCONTINUE' due to '/OPT:ICF' specification"

      Thanks,
      Tony

       
      • Vincent (Bryan) Coen

        Err...

        I have absolutely no idea what that is about.

        I assume you are using a VC compiler and it is coming from the MS linker.

        Might be worth a search for the error # (LNK4075) on the MS website or
        online docs.

        Another possible is try leaving a space after '-l' and Projec....

        Don't know the MS linkers command syntax so totally guessing.

        Vince

         
        Last edit: Simon Sobisch 2014-08-27
        • Tony Girgenti

          Tony Girgenti - 2014-08-26

          Vince,

          I got by the LNK4075 error.

          I am now getting this error: "error LNK2005: _main already defined in cob18108_0.obj".

          Thanks,
          Tony

           
          • Simon Sobisch

            Simon Sobisch - 2014-08-27

            The main error is because you want your C program being a module, not a main. As it's a main (along with command line params) and the -x from cobc adds a main, too, you get the error.
            For being easy accessible from COBOL your module entry point should be named like the CALL you want to do, in your sample ProjectCTest and should take your ints like the CPP version does.

            .obj and .lib files should be passed to cobc without -l, cobc checks if it just has to link them or not. Same is true for .c files, therefore the following should work:

            cobc -x -v callcsl.cob projecttest.c
            

            Simon

             
            • Tony Girgenti

              Tony Girgenti - 2014-08-27

              Simon,

              I don't have a projectctest.c file.

              Thanks,
              Tony

               
          • Vincent (Bryan) Coen

            Well that one is clear.

            You have duplicate entry points called _main so rename the one in the C
            routine to the name of the routines you cannot alter the Cobol names.

            Vince

            Guessing by the way...

            On 27/08/14 00:56, Tony Girgenti wrote:

            Vince,

            I got by the LNK4075 error.

            I am now getting this error: "error LNK2005: _main already defined in
            cob18108_0.obj".

            Thanks,
            Tony


             
            • Tony Girgenti

              Tony Girgenti - 2014-08-27

              Vince,

              My entry point in my C program is "main", not "_main".

              Thanks,
              Tony

               
              • Vincent (Bryan) Coen

                Change 'main' to name of module and recompile and see what happens

                .

                On 27/08/14 14:26, Tony Girgenti wrote:

                Vince,

                My entry point in my C program is "main", not "_main".

                Thanks,
                Tony


                 
                • Tony Girgenti

                  Tony Girgenti - 2014-08-27

                  Vince,

                  If I change "main" to "projectctest", I get the following link error in my Visual Studio compile:
                  "error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup"

                  Thanks,
                  Tony

                   
                  • Vincent (Bryan) Coen

                    Sorry Tony I have run out of steam.

                    Any one else help?

                    On 27/08/14 16:37, Tony Girgenti wrote:

                    Vince,

                    If I change "main" to "projectctest", I get the following link error
                    in my Visual Studio compile:
                    "error LNK2019: unresolved external symbol _main referenced in
                    function ___tmainCRTStartup"

                    Thanks,
                    Tony


                     
                  • Simon Sobisch

                    Simon Sobisch - 2014-08-27

                    As you build in VS you have to change the target of the C/C++-project to Dynamic Library (.dll), it's currently set to Application (.exe); do so in project options -> General Property Page -> Project Defaults -> Configuration Type, Check that Target Name is set to projecttest, too.

                    In any case: please reload the win binaries, I've updated them as they had a severe mpir-related bug (same is true for win_prerequisites).

                    And: I've retested it with the version in the download area, the following works (always add -v as there is a filter in the MSC build that filters too much in r411):

                    cobc -x -v callcsl.cob projecttest.obj
                    

                    if you want to remove warnings or pass linker options to cl.exe add /K mylinkeroption to the options.

                    Simon

                     
                    • Anonymous - 2014-08-28

                      Simon,

                      I changed the Configuration Type for the program to .dll and it compiled without error.

                      I ran this:
                      ~
                      "cobc -x -v callcsl.cob projectctest.obj"
                      ~

                      and got these results:

                      ~
                      C:\OpenCOBOL20\Projects\CallCSLibrary>cobc -x -v callcsl.cob projectctest.obj
                      Command line: cobc -x -v callcsl.cob projectctest.obj
                      Preprocessing: callcsl.cob -> C:\Users\Tony\AppData\Local\Temp\cob9180_0.cob
                      Return status: 0
                      Parsing: C:\Users\Tony\AppData\Local\Temp\cob9180_0.cob (callcsl.cob)
                      Return status: 0
                      Translating: C:\Users\Tony\AppData\Local\Temp\cob9180_0.cob -> C:\Users\Tony\AppData\Local\Temp\cob9180_0.c (callcsl.cob)
                      Executing: cl /c /I "C:\OpenCOBOL20\include" /MD
                      /Fo"C:\Users\Tony\AppData\Local\Temp\cob9180_0.obj"
                      "C:\Users\Tony\AppData\Local\Temp\cob9180_0.c"
                      Microsoft (R) C/C++ Optimizing Compiler Version 18.00.21005.1 for x86
                      Copyright (C) Microsoft Corporation. All rights reserved.

                      cob9180_0.c
                      Executing: cl /MD /Fe"callcsl"
                      "C:\Users\Tony\AppData\Local\Temp\cob9180_0.obj"
                      "projectctest.obj" libcob.lib /link /manifest /LIBPATH:"C:\GNU
                      Cobol 2.0\libs" /LIBPATH:"C:\OpenCOBOL20\lib"
                      Microsoft (R) C/C++ Optimizing Compiler Version 18.00.21005.1 for x86
                      Copyright (C) Microsoft Corporation. All rights reserved.

                      Microsoft (R) Incremental Linker Version 12.00.21005.1
                      Copyright (C) Microsoft Corporation. All rights reserved.

                      /out:callcsl.exe
                      /manifest
                      "/LIBPATH:C:\GNU Cobol 2.0\libs"
                      /LIBPATH:C:\OpenCOBOL20\lib
                      C:\Users\Tony\AppData\Local\Temp\cob9180_0.obj
                      projectctest.obj
                      libcob.lib
                      Creating library callcsl.lib and object callcsl.exp
                      LINK : warning LNK4098: defaultlib 'MSVCRTD' conflicts with use of other libs; use /NODEFAULTLIB:library
                      projectctest.obj : error LNK2011: precompiled object not linked in; image may not run
                      callcsl.exe : fatal error LNK1120: 1 unresolved externals
                      ~

                      I wish I knew more about compiling and linking, but I will try to figure these errors out.

                      I am not sure I understand what you mean by this:
                      ~
                      In any case: please reload the win binaries, I've updated them as they had a severe mpir-related bug (same is true for win_prerequisites).
                      ~

                      What are "win binaries" and "win_prerequisites"?

                      Thanks,
                      Tony

                       
                    • Tony Girgenti

                      Tony Girgenti - 2014-08-28

                      Simon,

                      I changed the Configuration Type for the program to .dll and it compiled without error.

                      I ran this:

                      "cobc -x -v callcsl.cob projectctest.obj"
                      

                      and got these results:

                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                      C:\OpenCOBOL20\Projects\CallCSLibrary>cobc -x -v callcsl.cob projectctest.obj
                      Command line: cobc -x -v callcsl.cob projectctest.obj
                      Preprocessing: callcsl.cob -> C:\Users\Tony\AppData\Local\Temp\cob9180_0.cob
                      Return status: 0
                      Parsing: C:\Users\Tony\AppData\Local\Temp\cob9180_0.cob (callcsl.cob)
                      Return status: 0
                      Translating: C:\Users\Tony\AppData\Local\Temp\cob9180_0.cob -> C:\Users\Tony\AppData\Local\Temp\cob9180_0.c (callcsl.cob)
                      Executing: cl /c /I "C:\OpenCOBOL20\include" /MD
                      /Fo"C:\Users\Tony\AppData\Local\Temp\cob9180_0.obj"
                      "C:\Users\Tony\AppData\Local\Temp\cob9180_0.c"
                      Microsoft (R) C/C++ Optimizing Compiler Version 18.00.21005.1 for x86
                      Copyright (C) Microsoft Corporation. All rights reserved.

                      cob9180_0.c
                      Executing: cl /MD /Fe"callcsl"
                      "C:\Users\Tony\AppData\Local\Temp\cob9180_0.obj"
                      "projectctest.obj" libcob.lib /link /manifest /LIBPATH:"C:\GNU
                      Cobol 2.0\libs" /LIBPATH:"C:\OpenCOBOL20\lib"
                      Microsoft (R) C/C++ Optimizing Compiler Version 18.00.21005.1 for x86
                      Copyright (C) Microsoft Corporation. All rights reserved.

                      Microsoft (R) Incremental Linker Version 12.00.21005.1
                      Copyright (C) Microsoft Corporation. All rights reserved.

                      /out:callcsl.exe
                      /manifest
                      "/LIBPATH:C:\GNU Cobol 2.0\libs"
                      /LIBPATH:C:\OpenCOBOL20\lib
                      C:\Users\Tony\AppData\Local\Temp\cob9180_0.obj
                      projectctest.obj
                      libcob.lib
                      Creating library callcsl.lib and object callcsl.exp
                      LINK : warning LNK4098: defaultlib 'MSVCRTD' conflicts with use of other libs; use /NODEFAULTLIB:library
                      projectctest.obj : error LNK2011: precompiled object not linked in; image may not run
                      callcsl.exe : fatal error LNK1120: 1 unresolved externals
                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

                      .

                      I wish I knew more about compiling and linking, but I will try to figure these errors out.

                      I am not sure I understand what you mean by this:

                      >> In any case: please reload the win binaries, I've updated them as they had a severe mpir-related bug (same is true for win_prerequisites). <<
                      

                      What are "win binaries" and "win_prerequisites"?

                      Thanks,
                      Tony

                       
                      Last edit: Tony Girgenti 2014-08-28
  • Simon Sobisch

    Simon Sobisch - 2014-08-28

    I don't know where you've got cobc/libcob/cobcrun from. If you use any OC2.0 builds (likely from kiska.net) you should upgrade to a GC2.0 build.

    If you've grabbed the GC2.0 build that was uploaded some days ago from the downloads area (as it seems from the output you've posted) you should reload them as they had a severe problem, I've updated them 18 hours ago.
    These are the "win binaries". "win_prerequisites" are available in the download area, too, and can be used to self-compile GC from svn with VisualStudio. They were updated, too.

    And to not confuse anyone naming the folder not "OpenCOBOL" could help as this implies an old version (you can even use spaces with VC builds, if you unpack the package to "C:\GNU Cobol 2.0" you even don't have to call the set_env batch).

    To the linker error: You can try

    cobc -x -v callcsl.cob projectctest.obj /K /NODEFAULTLIB:MSVCRTD
    

    But I guess the error is resolved/changed when you use a release version of projetctest.obj (seems like it was build with a DEBUG target).

    Simon

     
    • Tony Girgenti

      Tony Girgenti - 2014-08-28

      Simon,

      I resolved the linker errors by changes made to my Visual Studio solution.

      I ran this: "cobc -x -v callcsl.cob projectctest.obj"

      and got this output:

      C:\OpenCOBOL20\Projects\CallCSLibrary>cobc -x -v callcsl.cob projectctest.obj
      Command line:   cobc -x -v callcsl.cob projectctest.obj
      Preprocessing:  callcsl.cob -> C:\Users\Tony\AppData\Local\Temp\cob6348_0.cob
      Return status:  0
      Parsing:        C:\Users\Tony\AppData\Local\Temp\cob6348_0.cob (callcsl.cob)
      Return status:  0
      Translating:    C:\Users\Tony\AppData\Local\Temp\cob6348_0.cob -> C:\Users\Tony\AppData\Local\Temp\cob6348_0.c (callcsl.cob)
      Executing:      cl /c /I "C:\OpenCOBOL20\include" /MD
                      /Fo"C:\Users\Tony\AppData\Local\Temp\cob6348_0.obj"
                      "C:\Users\Tony\AppData\Local\Temp\cob6348_0.c"
      Microsoft (R) C/C++ Optimizing Compiler Version 18.00.21005.1 for x86
      Copyright (C) Microsoft Corporation.  All rights reserved.
      
      cob6348_0.c
      Executing:      cl /MD /Fe"callcsl"
                      "C:\Users\Tony\AppData\Local\Temp\cob6348_0.obj"
                      "projectctest.obj" libcob.lib /link /manifest /LIBPATH:"C:\GNU
                      Cobol 2.0\libs" /LIBPATH:"C:\OpenCOBOL20\lib"
      Microsoft (R) C/C++ Optimizing Compiler Version 18.00.21005.1 for x86
      Copyright (C) Microsoft Corporation.  All rights reserved.
      
      Microsoft (R) Incremental Linker Version 12.00.21005.1
      Copyright (C) Microsoft Corporation.  All rights reserved.
      
      /out:callcsl.exe
      /manifest
      "/LIBPATH:C:\GNU Cobol 2.0\libs"
      /LIBPATH:C:\OpenCOBOL20\lib
      C:\Users\Tony\AppData\Local\Temp\cob6348_0.obj
      projectctest.obj
      libcob.lib
         Creating library callcsl.lib and object callcsl.exp
      LINK : warning LNK4098: defaultlib 'MSVCRTD' conflicts with use of other libs; use /NODEFAULTLIB:library
      Executing:      mt /manifest "callcsl.exe.manifest"
                      /outputresource:"callcsl.exe";#1
      Microsoft (R) Manifest Tool version 6.3.9600.16384
      Copyright (c) Microsoft Corporation 2012.
      All rights reserved.
      

      I executed "CallCSL.exe" and it gave this error:

      [Window Title]
      callcsl.exe
      
      [Main Instruction]
      callcsl.exe has stopped working
      
      [Content]
      A problem caused the program to stop working correctly. Windows will close the program and notify you if a solution is available.
      
      [Debug] [Close program]
      

      With this in the command prompt window:

      C:\GNU COBOL 2.0\Projects\CallCSLibrary>callcsl
      
      Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'CSCalc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencie
      s. The system cannot find the file specified.
         at MathAdd(Int32 a, Int32 b)
         at _mainCRTStartup()
      

      I then downloaded this file: gnu-cobol-2.0_nightly_r411_win32_vc11_bin (1).7z and expanded it to the "C:\GNU Cobol 2.0" folder.

      I then ran this: "cobc -x -v callcsl.cob projectctest.obj /K /NODEFAULTLIB:MSVCRTD"

      and received this output:

      C:\GNU COBOL 2.0\Projects\CallCSLibrary>cobc -x -v callcsl.cob projectctest.obj /K /NODEFAULTLIB:MSVCRTD
      Command line:   cobc -x -v -K -NODEFAULTLIB:MSVCRTD callcsl.cob projectctest.obj
      Preprocessing:  callcsl.cob -> C:\Users\Tony\AppData\Local\Temp\cob7748_0.cob
      Return status:  0
      Parsing:        C:\Users\Tony\AppData\Local\Temp\cob7748_0.cob (callcsl.cob)
      Return status:  0
      Translating:    C:\Users\Tony\AppData\Local\Temp\cob7748_0.cob -> C:\Users\Tony\AppData\Local\Temp\cob7748_0.c (callcsl.cob)
      Executing:      cl /c /I "C:\OpenCOBOL20\include" /MD
                      /Fo"C:\Users\Tony\AppData\Local\Temp\cob7748_0.obj"
                      "C:\Users\Tony\AppData\Local\Temp\cob7748_0.c"
      Microsoft (R) C/C++ Optimizing Compiler Version 18.00.21005.1 for x86
      Copyright (C) Microsoft Corporation.  All rights reserved.
      
      cob7748_0.c
      Executing:      cl /MD /Fe"callcsl"
                      "C:\Users\Tony\AppData\Local\Temp\cob7748_0.obj"
                      "projectctest.obj" libcob.lib /link /manifest /LIBPATH:"C:\GNU
                      Cobol 2.0\libs" /LIBPATH:"C:\OpenCOBOL20\lib"
      Microsoft (R) C/C++ Optimizing Compiler Version 18.00.21005.1 for x86
      Copyright (C) Microsoft Corporation.  All rights reserved.
      
      Microsoft (R) Incremental Linker Version 12.00.21005.1
      Copyright (C) Microsoft Corporation.  All rights reserved.
      
      /out:callcsl.exe
      /manifest
      "/LIBPATH:C:\GNU Cobol 2.0\libs"
      /LIBPATH:C:\OpenCOBOL20\lib
      C:\Users\Tony\AppData\Local\Temp\cob7748_0.obj
      projectctest.obj
      libcob.lib
         Creating library callcsl.lib and object callcsl.exp
      LINK : warning LNK4098: defaultlib 'MSVCRTD' conflicts with use of other libs; use /NODEFAULTLIB:library
      Executing:      mt /manifest "callcsl.exe.manifest"
                      /outputresource:"callcsl.exe";#1
      Microsoft (R) Manifest Tool version 6.3.9600.16384
      Copyright (c) Microsoft Corporation 2012.
      All rights reserved.
      

      I ran the "CallCSL.exe" again and got the same error.

      Thanks,
      Tony

       
  • Simon Sobisch

    Simon Sobisch - 2014-08-28

    Hi Tony,

    I've no idea how your solution looks like. Please open the vs solution, do a cleanup (removing all the binaries) and put everything in a zip file for uploading it here. I'll check it afterwards.

    Simon

     
    • Tony Girgenti

      Tony Girgenti - 2014-08-28

      Simon,

      I used Visual Studio 2013 Pro to build this.

      Thanks,
      Tony

       
  • Simon Sobisch

    Simon Sobisch - 2014-08-28

    Hi Tony,

    these are the changes I've did

    • downgrade to vc11 (just changing PlatformToolset to vc110 and TargetFrameworkVersion to v4.5, ToolsVersion to 4.0
    • CPPClibrary: changed TargetType to .dll
    • ProjectCTest: set the PrecompiledHeader option for all targets, added CPPCLibrary.lib to Additional Dependencies and ../$(Configuration) to Additional Library Directories
    • created TargetPlatform x86 for CSCalc in ConfigurationManager
    • changed target of the solution to Win32 only
    • changed CallCSL.cob and ProjectTest.CPP as below

    CallCSL.cob

            IDENTIFICATION DIVISION.
            PROGRAM-ID. CallCSL.
            ENVIRONMENT DIVISION.
            DATA DIVISION.
            WORKING-STORAGE SECTION.
             01 VALUE-A USAGE BINARY-LONG value 1.
             01 VALUE-B USAGE BINARY-LONG value 2.
            PROCEDURE DIVISION.
              CALL "ProjectCTest" USING VALUE-A VALUE-B
              END-CALL. 
              STOP RUN.
    

    ProjectTest.CPP

    #include "stdafx.h"
    
    extern __declspec(dllimport) int MathAdd(int a, int b);
    extern __declspec(dllexport) int ProjectCTest(int a, int b); // put this line either here or in stdafx.h, not in both
    
    int ProjectCTest(int a, int b)
    {
        int answer = MathAdd(a, b);
        _tprintf(_T("%d\n"), answer);
        return answer;
    }
    

    This is necessary for the COBOL module to find the C source later.

    I've compiled/run with

    cobc-x -v CallCSL.cob ..\..\CSLibrary\Debug\ProjectCTest.lib
    set PATH=..\..\CSLibrary\Debug;%PATH%
    set COB_LIBRARY_PATH=..\..\CSLibrary\Debug
    CallCSL.exe
    

    The good news: CallCSL will find ProjectCTest and the call will be fine, you only need the PATH to ProjectCTest in environment COB_LIBRARY_PATH and the PATH to the DLLs that are called from there in environment PATH.

    The better news: You don't need the Wrapper ProjectCTest, but can call the CPP wrapper directly (as long as the export "C" is in and you link against it's lib). You either have to set COB_PRELOAD=name_of_cpp_wrapper_without_dll or rename the dll to match the exported name.

    The bad news here: the error is still the same as before and occurs in the loading of the C# module.
    Did you try the "simple" solution that was posted at stackoverflow (without cobc/libcob)? Did this work? If yes: it should work with libcob identical (needing a different signature and type for ProjectCTests as above, but the rest should work). If not I suggest to get this working before by posting the problems at the stackoverflow topic linked before.

    Simon

     
    Last edit: Simon Sobisch 2014-08-28
    • Tony Girgenti

      Tony Girgenti - 2014-08-31

      Simon,

      I did get this to run without a problem using the sample C# program CSCalc. Don't ask me how because I'm not sure I understand how to accomplish all of your bullet points at the beginning of your post. I was able to figure out some of them, but not all.

      I then changed the C# program from CSCalc to the program that I started all this for. That runs also beginning from the COBOL program CallCSL.exe, but it bombs out looking for a web service reference.

      I will work on that, but it did display the form and allowed interaction.

      Thanks for all of your help.

      Tony

       
    • Anonymous - 2014-09-01

      Simon,

      Just to update you, I got all of this to work the way I wanted it to. The COBOL program calls the C/C++/C# mess and executes my C# web service client.

      Now I can concentrate on passing data from the COBOL program to the web service client and back to the COBOL program.

      Thanks,
      Tony

       
    • Tony Girgenti

      Tony Girgenti - 2014-09-01

      Simon,

      Just to update you, I did get this to work the way I wanted it to. The COBOL program calls the C/C++/C# mess and the web service client works.

      Now, I would like to pass data from the COBOL program to the web service client and back again.

      Thanks,
      Tony

       
  • Simon Sobisch

    Simon Sobisch - 2014-09-01

    Sounds good.

    I've never done that but I'd go with PIC X(n) <-> char [n] <-> byte [n] as you have fixed length vars in COBOL most times. Just keep in mind that char isn't the same in .net (as it's a multibyte chararacter) as it's in C/C++.

    I think you'll be able to get this working, just try one step after another :-)

    In the end there will be a good sample in the FAQ, removing the need to do all these tests again :-)

    Simon

     
  • Tony Girgenti

    Tony Girgenti - 2014-09-02

    Simon,

    Knowing what you do about this solution, can you give me a little more detail of how to code this between the three projects.

    Thanks,
    Tony

     
    • Simon Sobisch

      Simon Sobisch - 2014-09-02

      I didn't passed vars in this environment. The passing from COBOL to C/C++ is explained in the wiki (see link on the first page of this discussion), passing data in both directions will be the first step. If you have an additional C++ project pass the data there next, too.

      After this works fine you can do the C++ <-> C# part (I didn't do this before but as this has nothing to do with COBOL or GC in general you should find help at stackoverflow or other places where C# coders meet).

      Simon

       
    • Simon Sobisch

      Simon Sobisch - 2014-09-08

      Just a head-up:
      You can pass char *, too. The only things you have to do

      COBOL --> C
      Use whatever PIC X you want and make sure to place a x'00' at the end of the string you want to pass.
      The cleanest solution is likely to use a c-pointer defined as USAGE POINTER and set it to the address of the working-storage item, pass it via USING c-pointer (or via USING vars, where vars is a group item with multiple char * and other vars if you like).

      C --> COBOL
      Use char * from C and a USAGE POINTER from COBOL, set the address of a LINKAGE or (non-allocated) BASED item to the pointer (see [820849dc#2052/97be/d783])
      a) via return value from C, with added "RETURNING c-pointer" to the CALL (this was done in the sample above as the C function already existed this way)
      b) via USING c-pointer (possible n times, you can use the same pointer vars you may have used in the other direction if you used the "likely cleanest solution" mentioned above).

      add a check for NULL in both COBOL and C and you have optional parameters for passing back and forth.

      Simon

       

      Related

      Discussion: getaddrinfo in GNU COBOL


Anonymous

Cancel  Add attachments





Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks