Skip to main content

Call win forms from native cobol program with copy books

  • October 28, 2015
  • 2 replies
  • 0 views

Hi,

I am new to visual cobol and 3 yrs exp to Visual Studio.

We have requirement where we need to design a win forms using VS and write a cobol program which will call these win forms. We will set some values in copy book from the cobol program and pass that copy book to win forms for displaying data to user.

The Cobol Program is the entry point which will invoke win forms based on certain condition.

The cobol program should be of native project type and win forms should be of manged type.

I did some googling and was able to call win forms but when I add copy books as parameter to a method I am not able to make a call. I am getting error  saying "The parameter name is incorrect".

I have added a sample project file of my work.


#COBOLVISUALCOBOLMIGRATION
#FormVisualCobol
#MicroFocusVisualCobol
#MicroFocus

2 replies

Chris Glazier
Forum|alt.badge.img+2

Hi,

I am new to visual cobol and 3 yrs exp to Visual Studio.

We have requirement where we need to design a win forms using VS and write a cobol program which will call these win forms. We will set some values in copy book from the cobol program and pass that copy book to win forms for displaying data to user.

The Cobol Program is the entry point which will invoke win forms based on certain condition.

The cobol program should be of native project type and win forms should be of manged type.

I did some googling and was able to call win forms but when I add copy books as parameter to a method I am not able to make a call. I am getting error  saying "The parameter name is incorrect".

I have added a sample project file of my work.


#COBOLVISUALCOBOLMIGRATION
#FormVisualCobol
#MicroFocusVisualCobol
#MicroFocus

Hi,

When passing parameters from native code to managed code COBOL you cannot directly use a COBOL group item in the linkage section. You can instead define the group item as a string and then set the group item to this string.

I have fixed your two programs so that they now work.

Calling native program:

      $set ooctrl( p) 
       identification division.
       program-id. Program1.
       class-control.
           objClass is class "$ole$WinForms.CallingClass".
       configuration section.

       data division.
       working-storage section.
        01 objInstance object reference.
           COPY "NAME.CPB".
      
       procedure division.
           invoke objClass "new" returning objInstance
           invoke objInstance "openForm1" using "Form 1 opened"
           invoke objInstance "openForm2" using "Form 2 opened"
           move "Hello" to name-test
           move "world" to details
           invoke objInstance "openForm3" using WW-TEST-RECORD
           
           goback.

       end program Program1.



Called managed class:

       class-id WinForms.CallingClass.

       working-storage section.
       01 objForm type System.Windows.Forms.Form.
       method-id InstanceMethod.
       local-storage section.
       procedure division.

           goback.
       end method.
       method-id openForm1.
       procedure division using frmTitle as string.
           set objForm to new type WinForms.Form1
           set objForm::Text to frmTitle
           invoke objForm::ShowDialog()
           goback.
       end method.
       method-id openForm2 public.       
       procedure division using frmTitle as string.
           set objForm to new type WinForms.Form2
           set objForm::Text to frmTitle
           invoke objForm::ShowDialog()
           goback.
       end method.    
       
       method-id openForm3.  
        copy "NAME.CPB".     
       procedure division using astring as string.
           set WW-TEST-RECORD to astring
           set objForm to new type WinForms.Form2
           set objForm::Text to WW-TEST-RECORD
           invoke objForm::ShowDialog()
           goback.
       end method.
         end class.

Hi,

I am new to visual cobol and 3 yrs exp to Visual Studio.

We have requirement where we need to design a win forms using VS and write a cobol program which will call these win forms. We will set some values in copy book from the cobol program and pass that copy book to win forms for displaying data to user.

The Cobol Program is the entry point which will invoke win forms based on certain condition.

The cobol program should be of native project type and win forms should be of manged type.

I did some googling and was able to call win forms but when I add copy books as parameter to a method I am not able to make a call. I am getting error  saying "The parameter name is incorrect".

I have added a sample project file of my work.


#COBOLVISUALCOBOLMIGRATION
#FormVisualCobol
#MicroFocusVisualCobol
#MicroFocus

Thanks it helped a lot