Click to See Complete Forum and Search --> : Calling .NET control from VB6


masterK
September 30th, 2005, 02:08 AM
I have created a very simple .NET control with one method and have set the 'Register for COM Interop' build option. I am having problems calling it from VB6.

In the first example I can create the control and it displays in my VB6 project yet I can't call the method on it as I get a VB6 error.

Example 1
Dim aVar As Control

Set aVar = Controls.Add("SimpleClassLibrary.simpleControl", "test")
aVar.Visible = True
aString = aVar.getString

SimpleControl is the .NET control.
In the second example I can create the control and call it's methods, but it does not appear on the VB6 form.

Example 2
dim mSimple As SimpleClassLibrary.simpleControl
Set mSimple = CreateObject("SimpleClassLibrary.simpleControl")
aString = mSimple.getString

Can anybody tell me what I am doing wrong, it's driving me mad at this stage. I want the VB.NET control to appear on the VB6 form and to be able to call it's methods.

naskew
October 7th, 2005, 07:10 AM
I'm trying to do the very same thing (I guess we are both late jumping on the .Net bandwagon :-)).

I have managed to get the control to appear in the Active-X test container but it refuses to appear in a VB application unless it is created dynamically through controls.Add. Still this should be sufficient for us and there is nothing stopping you creating a VB6 wrapper around your .Net component so you can create it statically in your VB6 applications.

You can read the following article which helped me get as far as I have http://www.codeproject.com/cs/miscctrl/exposingdotnetcontrols.asp.

All the articles I've read suggest that Microsoft has dropped support for this so even if you get it working you are very much on your own and cannot rely on Microsoft to continue to support whatever loophole you find. Still I won't be put off and I'll share anything I find.