Highlighted
Absent Member.
Absent Member.
376 views

Cobol calling visual basic and passing Structure as parameter

I have a netexpress program calling a vb subroutine passing 3 integer parameters which works fine.

If I try to pass the second 2 integers as a group then I cannot get it to work. (the group will eventually have about 50 items in it)

VB Prog

Imports System.Runtime.InteropServices

<ComClass(vbpan32.ClassId, vbpan32.InterfaceId, vbpan32.EventsId)> _
Public Class vbpan32

#Region "COM GUIDs"
' These GUIDs provide the COM identity for this class 
' and its COM interfaces. If you change them, existing 
' clients will no longer be able to access the class.
Public Const ClassId As String = "253aac3c-266c-4786-a71c-7185051536c2"
Public Const InterfaceId As String = "1882ce84-9369-4d02-ada6-1a6438e56a08"
Public Const EventsId As String = "d610f949-b193-4e5a-9398-7a9ed1426c4b"
#End Region

' A creatable COM class must have a Public Sub New() 
' with no parameters, otherwise, the class will not be 
' registered in the COM registry and cannot be created 
' via CreateObject.
Public Sub New()
MyBase.New()
End Sub
<StructLayout(LayoutKind.Sequential)> Structure wingad_params

<MarshalAs(UnmanagedType.I4)> Public num1 As Integer
<MarshalAs(UnmanagedType.I4)> Public num2 As Integer
End Structure

' Tried without MarshalAs and tried "R8" not "I4", "I8" tried too. SHOULD NOT need this anyway for integers.

'<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=30)> Public Param1 As String
'<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=30)> Public Param2 As String

'<VBFixedString(30)> Public Param1 As String
'<VBFixedString(30)> Public Param2 As String


Public Sub WinGad1(ByVal Func As Integer, ByRef num1 As Integer, ByRef num2 As Integer)
MsgBox("wingad Integer updated")
'
MsgBox("Win Gadget [" & Func & "] " & num1.ToString & " " & num2.ToString)

End Sub


Public Sub WinGad2(ByVal Func As Integer, ByRef Func2 As wingad_params)
MsgBox("wingad Structure")
'
MsgBox("Win Gadget [" & Func & "] " & Func2.num1.ToString & " " & Func2.num2.ToString)

End Sub

End Class

COBOL PROGRAM

 

$set ooctrl(+p)
* ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ
identification division.
program-id. winpanvb.
*
environment division.
configuration section.
source-computer. IBM-PC.
object-computer. IBM-PC.
special-names.
call-convention 74 is CallConvension74
console is crt.
* ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ
class-control.
winpan is class "$OLE$vbpan32.vbpan32".
data division.
* ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ
working-storage section.
copy "system.d01".
copy "winpan32.d01".
*
01 DLL-Obj object reference.

01 w-params.
03 w-num1 pic 9(8) comp.
03 w-num2 pic 9(8) comp.

01 w-func pic 9(8) comp value 1234.
* -----------------------------------------------------------------
01 w-message.
03 w-mess1 pic x(10) value "winpanvb".
03 w-messcnt pic 9999 value 0.
* ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ
procedure division.
winpan32-main section.
add 1 to w-messcnt.
display w-message.
*
invoke winpan "new" returning DLL-Obj.
move 888 to w-num1.
move 777 to w-num2.
*-------------------------------------------------------
stop "Call DLL-Obj using integers".
invoke DLL-Obj "WinGad1" using w-func
w-num1
w-num2.
*---------------------------------------------------------
stop "Call DLL-Obj using structure".
invoke DLL-Obj "WinGad2" using w-func
w-params.
*---------------------------------------------------------
stop "Call DLL-Obj Test Complete".
winpan32-end.
stop Run.

RESULTS

  

Calling 1st Routine wingad1 works fine passing integers.

 

Calling 2nd routine wingad2 with integer and group field fails. Tried to define a sequential structure to equate tto group field (found this in a sample program on MF site) but I must be missing something.

 

0 Likes
1 Reply
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Cobol calling visual basic and passing Structure as parameter

The group item in COBOL will be converted by the run-time system into a COM BSTR type which can be received into the VB.NET method as a .NET String. The VB.NET side will have to convert this into a structure or object. If you are passing this into a COBOL .NET method then you can define it as a group item on both sides and it will automatically be made available as this conversion is done for you.

The native COBOL COM support also allows you to create and pass data types of Variant or SafeArray and you can pass these to VB.NET as well.
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.