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
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