In one project that I am working on, I need to use an ActiveX object that has been built for magnetic card readers. My problem is that some workstations have have this reader installed, and some may not. So I can early reference this object in my code.
I've been trying to find a way to late bind to this DLL, if the computer has it installed. Using Reflection, I've been able to do this. However, when I try to call a method, it gives me a InvalidActiveXStateException error. Can someone please tell me what I am doing wrong?
This is the error message that I'm getting:
Exception of type 'System.Windows.Forms.AxHost+InvalidActiveXStateException' was thrown.
I've been trying to find a way to late bind to this DLL, if the computer has it installed. Using Reflection, I've been able to do this. However, when I try to call a method, it gives me a InvalidActiveXStateException error. Can someone please tell me what I am doing wrong?
Code:
Option Strict Off
Public Sub BindDLL()
Dim pobjAssembly As System.Reflection.Assembly
Dim pobjAssemblyName As System.Reflection.AssemblyName
Dim pobjType As Type
Dim pobjClass As Object = Nothing
pobjAssemblyName = System.Reflection.AssemblyName.GetAssemblyName("AxInterop.ctlUSBHID.dll")
pobjAssembly = System.Reflection.Assembly.Load(pobjAssemblyName)
pobjType = pobjAssembly.GetType("AxctlUSBHID.AxUSBHID")
pobjClass = Activator.CreateInstance(pobjType)
[b]pobjClass.PortOpen = True[/b] [COLOR=red]' <-- Error happens here.[/color]
End Sub
This is the error message that I'm getting:
Exception of type 'System.Windows.Forms.AxHost+InvalidActiveXStateException' was thrown.