Highlighted
Absent Member.
Absent Member.
3316 views

Calling Native Code from Managed Code

Jump to solution

Hi,

I am facing a technical problem in calling a native code from a managed code. I have created a native COBOL project and another managed COBOL project, I followed the documentation and no progress!! I would like some help. after I add the native code DLL reference to the managed project I try to call it using CALL "NativeCOBOL" using data-record. and the IDE(Visual Studio) doesn't recognize it despite that I have added the MicroFocus.COBOL.Runtime so anyone guide me please 

Best Regards

0 Likes
2 Solutions

Accepted Solutions
Highlighted
Micro Focus Expert
Micro Focus Expert

Please take a look at the tutorial here as it covers this topic in great detail.

Thanks.

View solution in original post

0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

There are many more tutorials like this in our knowledgebase.

We have just recently integrated the kb system with the community site.

To access other tutorials which cover the call statement, click on the magnifying glass icon at the top right of this web page and select to search Visual COBOL.

Then enter in your search which in this case would be:      call statement

As to question number 2.

Is there a specifc reason why you are using a native project to do your file handling instead of a managed project?
If your UI is a Windows Form or WPF application then it would be much better to call a managed subprogram to handle the file IO- so that you don't have to go through this interop layer.

For a ListBox control in Windows Forms you can create a COBOL array (managed) and bind to it by setting the DataSource property of the Listbox to the array.

In the example below you would set the array items to your values returned from the call to your file handling program instead of using the literals shown here.

Listbox is for simple items.
If you need something more comnplex then you should look at the ListView instead.

method-id button1_Click final private.
      01 mylistitems   string occurs any.
      procedure division using by value sender as object e as type System.EventArgs.

          set size of mylistitems to 5
          set mylistitems[0] to "Red"
          set mylistitems[1] to "Blue"
          set mylistitems[2] to "Green"
          set mylistitems[3] to "White"
          set mylistitems[4] to "Yellow"
          set listBox1::DataSource to mylistitems

end method.

View solution in original post

0 Likes
3 Replies
Highlighted
Micro Focus Expert
Micro Focus Expert

Please take a look at the tutorial here as it covers this topic in great detail.

Thanks.

View solution in original post

0 Likes
Highlighted
Absent Member.
Absent Member.

Dear Chris,

Thank you very much for the above tutorial. I would like to ask you two more questions:

Q1: Where can get more of these awesome tutorials Big Smile ?

Q2: I have a native code that is reading records and I want to receive them in a collections/data structures so I can put them in a ListBox - I don't want to spend a night on turning around it Cool- what best practice you would advise me to use ?

Thanks

Tags (1)
0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

There are many more tutorials like this in our knowledgebase.

We have just recently integrated the kb system with the community site.

To access other tutorials which cover the call statement, click on the magnifying glass icon at the top right of this web page and select to search Visual COBOL.

Then enter in your search which in this case would be:      call statement

As to question number 2.

Is there a specifc reason why you are using a native project to do your file handling instead of a managed project?
If your UI is a Windows Form or WPF application then it would be much better to call a managed subprogram to handle the file IO- so that you don't have to go through this interop layer.

For a ListBox control in Windows Forms you can create a COBOL array (managed) and bind to it by setting the DataSource property of the Listbox to the array.

In the example below you would set the array items to your values returned from the call to your file handling program instead of using the literals shown here.

Listbox is for simple items.
If you need something more comnplex then you should look at the ListView instead.

method-id button1_Click final private.
      01 mylistitems   string occurs any.
      procedure division using by value sender as object e as type System.EventArgs.

          set size of mylistitems to 5
          set mylistitems[0] to "Red"
          set mylistitems[1] to "Blue"
          set mylistitems[2] to "Green"
          set mylistitems[3] to "White"
          set mylistitems[4] to "Yellow"
          set listBox1::DataSource to mylistitems

end method.

View solution in original post

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.