Highlighted
Honored Contributor.
Honored Contributor.
1748 views

How to CALL or INVOKE a Managed Console program from a Native program?

Jump to solution

VS2013 / VC 2.2

I know how to have a Native program CALL another Native program (a traditional CALL).
I know how to have a Native program INVOKE a Managed Windows program/app (CCW/COM Interop).

What I can't figure out is how to have a Native program CALL? / INVOKE? a Managed Console program.
Would like to see an example.

Thanks

0 Likes
1 Solution

Accepted Solutions
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: How to CALL or INVOKE a Managed Console program from a Native program?

Jump to solution

Unfortunately in order to call a managed code .NET assembly from a native COBOL program you must go through the CCW Interop layer which involves registering the managed assembly for COM interop. If you wish to call a managed procedural program from native then you will have to create a managed wrapper class that you can instantiate and then call the managed COBOL program from this.

There is a 3rd party extension for Visual Studio that will expose managed methods as native entry points if you decorate them with the appropriate attributes but this currently does not work right out of the box for Visual COBOL. This technology can be downloaded here:

If this is something that is of interest to you let me know and perhaps we can work on getting it to work with your application..

View solution in original post

0 Likes
4 Replies
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: How to CALL or INVOKE a Managed Console program from a Native program?

Jump to solution

Can you please clarify what you mean by managed console application? Are you referring to a managed console application compiled as an .EXE or as a .DLL? Are you referring to a managed procedural program instead of a class?

0 Likes
Highlighted
Honored Contributor.
Honored Contributor.

RE: How to CALL or INVOKE a Managed Console program from a Native program?

Jump to solution

Chris, thanks for your reply.  I will try to answer your questions and explain myself better below:

Say that I have an existing native COBOL program named TEST1 and from it I want to CALL or INVOKE a new program named TEST4.  And TEST4 will be the type described below.  Assume both executables will be in the same directory.

When I go into VS and say I want to create a new project and I then highlight Managed in the [Project Type] pane on the left and Console Application in the [template] pane in the middle.  Then after it creates the new project (say TEST4), I go to Properties and change the Output type from Console Application to Class Library so that it will create a DLL instead of an EXE.  I do this because I am under the impression that you can't really directly CALL or INVOKE an EXE from another COBOL program, it has to be a DLL if you are going to CALL it or INVOKE it.  If I am wrong on this, please let me know.

The resulting "program" is not a class - it is a procedural program with some version of the Net Framework as the Target framework.  The skeleton "Program1" code that it creates is a simple procedural type and not a class.

However, I can't seem to simply / directly CALL this "Managed Console" program (changed properties to a DLL) from a Native COBOL program like I would CALL a Native program (DLL) from a Native COBOL program.  It falls through the CALL and doesn't even give me an exception.

I know that I can treat this situation similar to a situation where I wanted a Native COBOL program to INVOKE a Managed Windows Forms Application (which I changed the Output type to Class Library).  In other words, create and bolt a Class1 onto this new program and follow the steps similar to the CCW / Com Interop examples.  And then once in Class1, I would CALL "TEST4.Program1" since it was procedural.  This works, although using the AssemblyName.ProgramName in the CALL is a bit new and strange.

Seems like I should be able to just simply and directly "CALL TEST4" in/from TEST1.

Clear as mud?

Thanks

0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: How to CALL or INVOKE a Managed Console program from a Native program?

Jump to solution

Unfortunately in order to call a managed code .NET assembly from a native COBOL program you must go through the CCW Interop layer which involves registering the managed assembly for COM interop. If you wish to call a managed procedural program from native then you will have to create a managed wrapper class that you can instantiate and then call the managed COBOL program from this.

There is a 3rd party extension for Visual Studio that will expose managed methods as native entry points if you decorate them with the appropriate attributes but this currently does not work right out of the box for Visual COBOL. This technology can be downloaded here:

If this is something that is of interest to you let me know and perhaps we can work on getting it to work with your application..

View solution in original post

0 Likes
Highlighted
Honored Contributor.
Honored Contributor.

RE: How to CALL or INVOKE a Managed Console program from a Native program?

Jump to solution

OK, well now I know.  Since we are already relatively comfortable with the CCW COM Interop approach (as we already have a number of Native COBOL programs calling managed Win Forms COBOL apps), we will just do it that way, which is the way you suggested.  Thanks.

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.