Click here to Skip to main content
15,896,201 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm working on terminal emulator automation using IBM HACL. In the execution thread I can access the HACL programming objects and their properties/methods. My intention is not to block the main thread, but have the job done via background worker. Here all my attempts failed.

What I have tried:

This works:
VB
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
    Dim pConnList As AutConnListTypeLibrary.AutConnList
    pConnList = New AutConnListTypeLibrary.AutConnList
    pConnList.Refresh()
    Debug.Print("Number of sessions: " & pConnList.Count)
'Result:
'Number of sessions: 2
End Sub


But the same is not possible from the background worker. When creating the instance of the object the exception is thrown:
VB
Private Sub bw_DoWork(sender As Object, e As DoWorkEventArgs) Handles bw.DoWork
    Dim pConnList As AutConnListTypeLibrary.AutConnList
    Try
        pConnList = New AutConnListTypeLibrary.AutConnList
        pConnList.Refresh()
        Debug.Print("Number of sessions: " & pConnList.Count)
    Catch ex As Exception
        Debug.Print(ex.Message.ToString)
'Result:
'Exception thrown: 'System.InvalidCastException' in Pcomm test.exe
'Unable to cast COM object of type 'System.__ComObject' to interface type 'AutConnListTypeLibrary.AutConnList'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{3CB39CC1-6F18-11D0-910D-0004AC3617E1}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
    End Try
End Sub
Posted
Updated 30-Jan-17 2:59am

1 solution

Hi,

Use late binding
pConnList = CreateObject("PCOMM.AutConnList")
That should help

If You want to use intelisense You can try using
NuGet Gallery | PCOMMLib 1.0.1[^]
Source available here:
Vrzasq / PCOMMLib — Bitbucket[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900