Please visit this thread:
http://social.msdn.microsoft.com/Forums/en-US/vbinterop/thread/fec266fb-7a00-4700-9100-2349b772308e Also have a look at this article about CCW. Although it is related to compact framework, the theory is identical. We can know that the culprit is CCW which is not released here.
http://blogs.msdn.com/netcfteam/archive/2005/07/24/442612.aspx I think that ActiveX control should have reference to CCW for the underlying .NET Interop control, so .NET GC doesn't collect this .NET object. Finally ActiveX control is alive too.
The key reason is that ActiveX control has the reference to underlying .NET Interop control. Because there is the reference to .NET control, GC can't collect .NET Interop control. ActiveX control is not released in this situation. Currently I dynamically add .NET Interop control in AxtiveX control(please have a look at the following code snippet). After I remove this .NET control from control collection, the ActiveX terminate event is fired. Also please refer to the following links about Controls property in VB6.
http://msdn.microsoft.com/en-us/library/aa277578(VS.60).aspx
frmInteropControl code
Private Sub Form_Unload(Cancel As Integer)
Me.UCInteropControl1.cleanup
End Sub
ActiveX control code
Option Explicit
Dim Cmd1 As InteropTextBox1
Public MsgBoxOnTerminate As Boolean
Dim ctl As Control
Private Sub UserControl_Initialize()
Set Cmd1 = Controls.Add("InteropTextBox1.InteropTextBox1", "Cmd1")
Cmd1.Width = 2000
Cmd1.Top = 500
Cmd1.Left = 500
Cmd1.Visible = True
End Sub
Private Sub UserControl_Terminate()
If MsgBoxOnTerminate Then
MsgBox "UserControl_Terminate", vbInformation, UserControl.Name
End If
End Sub
Public Sub cleanup()
Controls.Remove "Cmd1"
Set Cmd1 = Nothing
End Sub
If you have any further issues, feel free to tell us.
Best regards,
Riquel
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.