Click to See Complete Forum and Search --> : Using VB.NET UserControl from VB6


Paul Carey
April 3rd, 2002, 04:18 AM
I am doing a feasibility study for a new project.
What we would like to do is write some controls, using VB.NET, based on a Windows Forms UserControl (TextBox, for example).
This part has proved easy, as long as you then use the control from applications written using VB.NET.
However, we need to make it possible for our users who are still on VB6 to use our new control.
This is proving incredibly difficult, at a number of levels, and I am beginning to believe that what we are doing is unsupported.

Here is the experimental code for the control:

<System.Runtime.InteropServices.ProgId("VBInheritest.TGATextBox")> public Class TGATextBox
Inherits System.Windows.Forms.TextBox

#Region " Windows Form Designer generated code "
' generated code omitted
#End Region

public ReadOnly property TGAFieldName() as string
get
TGAFieldName = "Hello"
End get
End property

public Function DoTest() as string
DoTest = "testing .. testing"
End Function

End Class



... and the extra line in the assembly, to give it a StrongName

<Assembly: AssemblyKeyFileAttribute("Inheritest.snk")>



It compiles and runs fine, if you run it from a VB.NET application.

To call it from VB6 the docs say that the first thing to to is to run tlbexp.exe to make a type library.
I do this and it seems to work OK. However, if I examine the the generated typelib with oleview.exe (either the one supplied with VS.NET or the old one from VC++ V6) there is no mention of the property TGAFieldName or the method DoTest. Very worrying ....?
(BTW the same thing happens if I use regasm.exe with the /tlb flag to generate the typelib, instead of tlbexp.exe.)

Anyway, if I ignore that little matter and carry on, then I run regasm.exe and gacutil.exe. Again, everything superficially seems to work OK but things soon get worse.

Basically regasm only seems to have done half a job. Many necessary registry entries are missing.
Initially, it is impossible to even attempt to refer to the component from VB6, because it does not appear on any of the tabs of the Project>Components dialog.
So, I try an easier test and use the ActiveX Control Test Container. Initially, there is the same problem (control not mentioned). But then - some success. If I uncheck 'Control' in the 'Implemented Categories' then I can insert my control.
The control itself (e.g. its UI) seems to work fine. Then a problem; the Container reports that the control has no properties or methods. This is, of course, consistent in a way with the typelib problem above.

I then laboriously made manual changes to the Registry. I put empty keys 'Control', 'Insertable' and 'Programmable' in the HKCR\CLSID\{clsid} key for the control.
At last, the control appears on the VB6 Project>Components dialog. But if I try to select it, there is some meaningless error message like 'Failed to Load Control'.
So, I made more registry changes. I put a 'TypeLib' key in the HKCR\CLSID\{clsid} key and a corresponding structure under HKCR\Typelib\{typelib}. Slightly more success this time; the error message changed to 'C:\WINNT\System32\mscoree.dll could not be loaded'.

Now I have reached the end of my own problem-solving resources in this area and I am asking for some help.

1) Can anyone tell me what I am doing wrong?
2) Am I trying to push water uphill by attempting to call a Windows Forms UserControl from VB6?
3) If it is practicable, is there any way of making regasm.exe (or maybe some other tool) do a proper job.

Thanks in advance

Paul Carey

deepaksatam
June 1st, 2005, 09:25 AM
hi

paul do u able to crack this problem if yes then please pass to me. bcause i am also facing the same problem

awaiting for ur reply

Rgds

Deepak

DSJ
June 1st, 2005, 09:47 AM
Have you checked the "Register for COM-Interop" checkbox on the project's properties page?

deepaksatam
June 6th, 2005, 05:23 AM
yes

i had ticked that option. but still not working. another things by using some assemble attributes. i am able to place a vb.net control in vb 6 activex test control. but not in vb6 standard exe project.

please help me on this

rgds

deepak

DSJ
June 6th, 2005, 10:41 AM
See if this helps. http://support.microsoft.com/default.aspx?scid=kb;en-us;317535

DaKinMan
July 7th, 2005, 11:00 AM
Hi

Through many ideas, I managed to get a UserControl ActiveX DLL (registered as COM Interop) developed in .NET inside VB6.

The VB6 project shows visually the UserControl, handles the .NET events AND also shows through intellisense its available methods for ease of development for VB6 users.

The .NET DLL also registers quite easily in the registry.. no hardcoded registry keys like ClassID and such.

If you want some info on this if you think it can help you:
alexandre.roy@sanilogik.com

Natasa
December 19th, 2005, 04:58 PM
I really need help with this. I have managed to get a textbox from .net into vb6, but i am unable to work with events. I would appreaicate any help on the subject.

siskhoalanka
December 22nd, 2005, 11:53 AM
Maybe it would be grate explaining right here don' t you think ?
I mean, it' s a forum...........
Anyway, I read all this and now my VB6 gives me this error when executing:
"VB6.EXE MSCOREE.DLL load error (Error code =%X)."
Anyone knows how to help me ?

Thanks!

Natasa
December 27th, 2005, 07:56 PM
"Maybe it would be grate explaining right here don' t you think ?"

what do you want an explenation for?

avy32
January 10th, 2007, 03:42 AM
Hi

I have an usercontrol problem.
I make an usercontrol(that inherits usercontrol class) in VB.net 2005 that contains a toolstrip control and on that toolstrip I add in runtime 9 buttons.
I make this usercontrol as tlb and I try to add in VB 6 as components and it give me an error: "Name conflicts with existing module, project, or object library"
Do you have any solution for that?
When I develop a usercontrol that inherits button class and not usercontrol class it is working.I think this is a problem but I am not so sure.
Could anyone help me with that, please?
Thks
Avy

avy32
January 11th, 2007, 05:22 AM
Hi again.
I solved my last problem.... but now I have another one.
I have a VB.NET usercontrol that contains a toolstrip, on that toolstrip I load in runtime 9 toolstripbuttons by code:
tsToolBar.Items.Add(tsButtons(i))
AddHandler tsButtons(i).Click, AddressOf tsButtons_Click
I declare at start of the usercontrol :
Public event ButtonClick() -this event I want to use in VB 6.
How and where I have to raise this event (ButtonClick) that it have same behavior as click on a toolstripbutton?
Could anyone help me with that?
Thks
Avy

George1111
January 11th, 2007, 08:11 AM
You may find this relevant also

http://msdn2.microsoft.com/en-us/vbasic/aa701257.aspx

saikatch
January 25th, 2008, 08:42 AM
Hi every body....

I was also doing the same. And hope I have found the solution.

Once u register ur .Net control as an activeX control other than HKCR\CLSID\GUID key .. u need to add two more keys ...

1. HKCR\Interface
2. HKCR\TypeLib

U can find out the other subkey by ur own

in the TypeLib subkey
HKCR\TypeLib\{ur Assembly GUID}\1.0\0\win32
default key value must point to ur exact tlb file location

same as in HKCR\TypeLib\{ur Assembly GUID}\1.0\HELPDIR
must point to ur tlb file's folder location.

I did this and I am able to load .net activeX in VB6 exe project successfully.

rgds
Saikat