Highlighted
Absent Member.
Absent Member.
875 views

Calling Unmanaged COBOL from Managed COBOL: System.AccessViolationException

Jump to solution

I'm following the tutorial to call unmanaged COBOL code from managed COBOL, but I get this exception: "System.AccessViolationException".

What is causing it?

0 Likes
1 Solution

Accepted Solutions
Highlighted
Micro Focus Expert
Micro Focus Expert
Oh yes that tutorial. I wrote that tutorial back in 2012. I just went thru and performed the entire tutorial and did not encounter a problem. I used Visual COBOL for VS2017 V3.0. Which Visual COBOL version and Visual Studio product are you using? Could you possibly zip up your solution folder and upload it to the post here? You might have to delete the output folders containing the .exe and .dlls if the zip file is too large.

View solution in original post

0 Likes
5 Replies
Highlighted
Micro Focus Expert
Micro Focus Expert
I am not sure which tutorial it is to which you are referring? Can you provide a link to the docs that you are using? At what point do you get that error?
0 Likes
Highlighted
Absent Member.
Absent Member.
I get the error on the "CALL" instruction:
"call "prog2" using custRecord"
I found the tutorial here: community.microfocus.com/.../visual-cobol-for-visual-studio-getting-started-with-solutions-projects-and-the-cobol-call-statement-pinvoke

Thank you!!
0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert
Oh yes that tutorial. I wrote that tutorial back in 2012. I just went thru and performed the entire tutorial and did not encounter a problem. I used Visual COBOL for VS2017 V3.0. Which Visual COBOL version and Visual Studio product are you using? Could you possibly zip up your solution folder and upload it to the post here? You might have to delete the output folders containing the .exe and .dlls if the zip file is too large.

View solution in original post

0 Likes
Highlighted
Absent Member.
Absent Member.

I'm using VS2015 and VC3.0, but I don't need this feature anymore.

Now all projects are Managed Cobol and calls work perfecly except when I try to call a program using a variable.

E.g. if I try this:

01 toBeCalled PIC X(8).

move 'TABEL010' to toBeCalled

call toBeCalled

I get error 173 (program not found), instead doing:

call 'TABEL010'

the program is called correctly.

 

THank you for your help!

0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

What is the name of the assembly in which TABEL010 is contained? If the assembly name is different than the program name being called and you are calling it dynamically then you first need to load the assembly in order to make it's entry points visible.

This is done automatically when you use a static call (call 'TABEL010') because the compiler can resolve the program name to a referenced assembly at compile time. It cannot do this if you are calling dynamically using a data name.

There are several ways to load the assembly and I believe that a few of these are covered in the tutorial you are using.

You can add a call statement to call the name of the assembly (.dll). The default name is the project name but this can be changed. So of your project name containing TABEL010 is called 'project2' then you could do:

  call 'project2'

  call 'TABEL010'

You can also set a procedure-pointer to the assembly name:

01 pp procedure-pointer.

  set pp to entry 'project2'

  call 'TABEL010'

You can also create an app.config file and place the names of the .dlls that need to be loaded into the preload section as documented here:

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.