Skip to main content

[archive] Calling COBOL From Outlook

  • November 8, 2010
  • 10 replies
  • 0 views

[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

10 replies

[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
You should try call the Shutdown method at the end.

[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
Gisle;
When I call the "shutdown" method (I'm not sure what the "message" parameter is supposed to be, I just used a zero), the whole application shuts down, with no message or additional information (it closes Outlook).

-Chris

[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
Ah, I mixed up. Sorry, you should not do that, you are right. (It is even stated in the docs, shame on me)

[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
Ah, I mixed up. Sorry, you should not do that, you are right. (It is even stated in the docs, shame on me)

[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
A little more information, which may or may not be helpful... When I get to the last line of my program (GOBACK or STOP RUN), the initial window doesn't close unless I have the .NoStop property set to False, the problem being that this also causes Outlook to close. If .NoStop is set to True, the window doesn't go away until control returns to Outlook, and when I try to run the program again, I never see the windows that should be displayed.

[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
Another interesting piece of trivia. Due to some issues with the CVM closing Outlook, I had started calling MailToCOBOL in a thread. This seems to have been part of the problem. Once I stopped calling in a thread I was able to get windows to open properly in subsequent calls to the DLL. I'm still working out a few quirks, but it seems to be working...

[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
Another interesting piece of trivia. Due to some issues with the CVM closing Outlook, I had started calling MailToCOBOL in a thread. This seems to have been part of the problem. Once I stopped calling in a thread I was able to get windows to open properly in subsequent calls to the DLL. I'm still working out a few quirks, but it seems to be working...

[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
Another interesting piece of trivia. Due to some issues with the CVM closing Outlook, I had started calling MailToCOBOL in a thread. This seems to have been part of the problem. Once I stopped calling in a thread I was able to get windows to open properly in subsequent calls to the DLL. I'm still working out a few quirks, but it seems to be working...

[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
.NoStop is imperative if you use STOP RUN. If this is FALSE (default), the entire process is shut down.

[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
I found that out :D