AxInterOp/InterOp

Mystret

New member
Joined
Sep 27, 2006
Messages
2
Programming Experience
3-5
Hi,

I have got a question about AxInterOp and InterOp.
When I add a com control to my form, it automatically adds two references to my project; Ax<>.dll and <>.dll. After some research I found that the Ax-dll is the actual component used for the form (visibility) and VS automatically uses it when I add that control to my form.

The problem is; I need that control to be running in another thread, and I don't need the control to be visible on a form or something. I thought that would be possible somehow, so I started experimenting a bit. I thought that I could use the <>.dll class for that, because the Ax<>.dll did not work; it resulted in a threading error that I couldn't use it because it wasn't running in a single-threaded apartment.

So after some experimenting I made some code which I thought could work correctly:

'this in Form1_load()
t = New Thread(AddressOf interrupt)
t.Name = "Interrupt"
t.Start()

'this in sub interrupt()
Dim TVicLPT2 As TVICLPTLib.TVicLPT = New TVICLPTLib.TVicLPT()
TVicLPT2.Active = 1
TVicLPT2.IrqNumber = 7
TVicLPT2.UnmaskIrq()
AddHandler TVicLPT2.LptInterrupt, AddressOf TVicLPT2_LptInterrupt

Where I have got the TVICLPTLib and AxTVICLPTLib as the two dll's imported to my project.

But now when I run it, it gives me the following error at the line TVicLPT2.Active = 1 (and it also gives me that error for the Irqnumber and UnmaskIRQ() line. The AddHandler line doesn't produce an error, but the event doesn't fire when trying it):

Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))

I guess this has something to do with using the <>.dll instead of Ax<>.dll and then not being able to do such things. Is this true? If so, is there another way to accomplish what I'm trying to do. If it isn't true, what should I change in my code to make it work?

Thanks in advance,

Floris
 

JohnH

VB.NET Forum Moderator
Staff member
Joined
Dec 17, 2005
Messages
15,552
Location
Norway
Programming Experience
10+
About setting STA/MTA you could see this thread from yesterday: http://www.vbdotnetforums.com/showthread.php?t=13916

I think you have to add ActiveX COMs to a form to create a window handle. For example with the AxWebBrowser I get an error that says "Windowless ActiveX controls are not supported." If set it Visible=False I get "InvalidActiveXStateException". At least I can add the control normally and hide it behind something or location outside form.

If you create the Ax control there is also the method CreateControl available from the instance that could help, it forces creation of control with handle and child controls. (not that it worked with AxWebBrowser)
 

Mystret

New member
Joined
Sep 27, 2006
Messages
2
Programming Experience
3-5
Thanks for your reply.

It helped me a bit :)

When I use the Ax<>.dll lib now and set the thread to a STA, then I don't get the threading error anymore. And using the
TVicLPT2.CreateControl() line, prevented the InvalidActiveXStateException from coming up.

However, my interrupt handler doesn't fire when it is supposed to. The addhandler line (as in my first post):
AddHandler TVicLPT2.LptInterrupt, AddressOf TVicLPT2_LptInterrupt

And then the corresponding sub TVicLPT2_LptInterrupt:
Private Sub TVicLPT2_LptInterrupt(ByVal sender As System.Object, ByVal e As AxTVICLPTLib._DTVicLPTEvents_LptInterruptEvent)
MessageBox.Show(
"interrupted... ")
End Sub

To my knowledge, this should work normally; it does not though. Any ideas why?

Thanks,
Floris
 
Top Bottom