Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using a .net component in a VB6 exe file...

Status
Not open for further replies.

hackproof

Programmer
Feb 29, 2004
41
0
0
PH
Is it possible to use a created .net tlb file in a created VB6 exe file? I created a dll component in .net and i want to use that .net dll in my VB6 exe file but I having an "automation" problem. could anyone help me on this one? Thanks.
 
Yes.

Step 1: Build your .DLL

Step 2: Copy your DLL to anywheres you want to access it from a COM app. (IE: your VB6 development machine, and any machines that will be using the VB6 app)

Step 3: Install the .Net Framework on any machines that will use this DLL

Step 4: Use regasm.exe to register your DLL to a TLB from the command line on any machine that will use the DLL:
Code:
regasm YourDll.dll /tlb YourDll.tlb

Step 5: In vb6, add a reference to the .tlb file.

Step 6: Deploy the vb6 app. Again, make sure you regasm the .Net dll to a tlb on every machine that will use it.

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
Begin with

'Imports System.Runtime.InteropServices'

then use GuidGen to generate three GUIDS and add a section like this inside your class...

#Region "COM GUIDs"
Friend Const ClassId As String = "9029E0FE-5554-496c-885B-12F7E8C7D872"
Friend Const InterfaceId As String = "B7FB59F0-76C6-4c0b-8702-A9BCA943E946"
Friend Const EventsId As String = "2A1A8808-FB6A-4aaa-8F99-B3FBB420D993"
#End Region

Then, on the live above your Public Class Class1, include this tag so that it looks like this...

<ComClass(Class1.ClassId, Class1.EventsId, Class1.InterfaceId)> _
Public Class Class1

Then, go into the properties of project/Configuration Properties and check the box for "Register For COM Interop"

Build your DLL, and distribute it along with your app.

:)
James
 
Then, go into the properties of project/Configuration Properties and check the box for "Register For COM Interop"

I've found that using that option will only register it on the development machine, you'll still have to regasm it on any machines it gets deployed to.

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
That will create a COM-callable wrapper - a COM component that delegates all calls into your .NET assembly. It will also create a COM type library for the wrapper and register it in the windows registry. After that's all done and he has built his solution, he can switch over to VB6 and his new "COM" compatible object will show up in his references section and he'll even have intellisense.


--
James
 
Left this part out...

And yes, Rick is right, you will still need to RegAsm it on the machines that will be using your VB6 app. Or, you can build a setup package for your app and your COM compatible DLL with get distributed and registered automatically.

--
James
 
But the VB6 deployment packages won't load the .Net DLL into the GAC will it? I beat on it a few times and never got it to load correctly. I finally just broke down and regasm'd it.

On the bright side however, as long as you don't change any used signatures, you can copy/paste new versions of the .net dll over the old one. Saves you from having to re-regasm it every deployement.

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
No, you're right, the VB6 deployment package won't load it into the GAC. Looking back, I used VS.NET to create a distribution package for the object.

--
James
 
off topic

tyreejp did you do the weather module on your site yourself and if yes how. I don't won't it on my site I want it on my windows forms.

Christiaan Baes
Belgium

If you want to get an answer read this FAQ faq796-2540
There's no such thing as a winnable war - Sting
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top