Calling Native Code from Managed Code

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

  • Verified Answer

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

    Thanks.

  • 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  ?

    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 - what best practice you would advise me to use ?

    Thanks

  • Verified Answer

    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.