[Migrated content. Thread originally posted on 05 November 2010]
We're adding a button to allow users to save a copy of an email into our program. The button calls a COBOL program using wrunnet.dll like this:
Imports acucobol
Public Class MailToCOBOL
Implements IDisposable
Private COBOL As CVM
Private iFilename As String
Private iUsername As String
Private BasePath As String = "J:\\CFDEV2"
Public Sub New()
If COBOL Is Nothing Then
COBOL = New CVM
End If
COBOL.Debug = True
COBOL.NoStop = False
COBOL.ExtendedError = True
COBOL.RunPath = IO.Path.Combine(BasePath, "BIN")
COBOL.Cache = False
COBOL.ConfigFile = IO.Path.Combine(BasePath, "ETC\\CBLCONFI")
End Sub
Public Sub SendMessage()
Try
Environment.CurrentDirectory = COBOL.RunPath
Dim PATH As String = Environment.GetEnvironmentVariable("PATH")
If Not PATH.Contains(";" & COBOL.RunPath & ";") Then
Environment.SetEnvironmentVariable("PATH", PATH & ";" & COBOL.RunPath & ";")
End If
Dim ErrCode As errorTypes
Dim RtnCode As Integer
Dim Linkage(1) As Object
Linkage(0) = sUsername.ToString.PadRight(1024, " "c)
Linkage(1) = sFilename.ToString.PadRight(1024, " "c)
ErrCode = COBOL.Call("SAVEEMAIL.cob", Linkage, Nothing, "", RtnCode)
COBOL.CancelProgram("SAVEEMAIL.cob")
sUsername = Linkage(0).ToString
If Not (ErrCode = errorTypes.CS_OK) Then
MsgBox(ErrCode.ToString & vbCrLf & COBOL.LastErrorMsg.ToString)
End If
COBOL.CancelAllPrograms()
COBOL.UnloadAllPrograms()
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
End Class
Everything works well the first time through. After the call is completed, the calling class calls the Dispose method of MailToCOBOL, and in the Dispose method, we call "UnloadAllPrograms" and set COBOL = Nothing.
The second time this class is instantiated, the code appears to work fine, but the window is never opened (from within COBOL), and when the program gets to the ACCEPT, it gets a 97, so we exit. I have tried opening both INDEPENDENT and FLOATING windows, and either way, nothing appears on the screen.
It may be telling that the second time in, the values in our EXTERNAL data items are still there, even though we cancel the program, and set the COBOL object to nothing. I have tried calling the "Shutdown" method, but that just throws an exception. If I put a "STOP RUN" at the end of the program (in COBOL), the 2nd call results in a CS_COBOL_FATAL_ERROR message.
I'm sure there's something I'm doing incorrectly here, can anyone help?
Thanks in advance,
-Chris



