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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Call .NET form from VB6

Status
Not open for further replies.

M3Fan

Programmer
Dec 28, 2001
73
US
Hopefully this is an easy question. I'm new to interop between .NET and COM. I'm wondering how I can make my legacy VB6 application call a .NET component which has its own .NET form. I'd like the VB6 app to pass a SQL string to the .NET component, which would launch and open its own form containing a slick .NET report based on the SQL. Any ideas? Almost everything online that I've found has not provided a clear solution. HELP!!!!!!!!!!!!!!! Don't know if I have to make an EXE and pass the parameters as a command line or if a .NET DLL can do this on its own. Very lost here.
 
Make your .net project into a .dll

find the program "regasm.exe" on your machine (should be in the .net framework folder)

run: regasm [.net project].dll /tlb:[.net project].tlb

copy the .tlb file, the original .dll file and ALL dependencies to a folder.

In VB6 add a reference to the .tlb file.

Note that you need to 1) Have the .Net framework installed on any machine you want to use your .dll on and 2)Must run regasm on each machine (even if using the VB 6 deployment wizard)

The .tlb file is a com interface for your .Net code. it does not actually contain any compile code, just a COM interface and references to your .Net DLL.

-Rick

----------------------

[monkey] I believe in killer coding ninja monkeys.[monkey]
 
Rick- I appreciate the answer. I tried this a couple times, even generating a "strong key" using some snk command, etc, and I couldn't get it to work. I could find the reference in VB6, and VB6 even saw the classes as shown by its autocomplete knowing their names. However, it would always say that one of its dependancies could not be found when I tried to call the .NET DLL. So, almost by accident, I chose the "Register For Com Interop" on the build menu of the project in .NET. I copied that .DLL and .TLB file from the bin file, both generated by building from the .NET IDE, into the VB6 folder, and it worked. What was this build option doing that the manual command line option wasn't doing? Does it have to do with the strong name or GUID? Anybody know what this build option does, or have any more insight on this? I'd like to roll this out to a client machine at some point and I don't want to have to use the IDE to do it. This application does use a third party reporting component, if that makes any difference.
 
That option does the same thing as /regasm. But if you distribute your VB6 app, it won't work on other machines as the .Net DLL will need to be registered with regasm again.

If you are getting a missing dependencies error, then you are missing dependencies. Look at the references in your .Net project, make sure they are all set to "copy local". Make sure that when you register the .dll to .tlb you have all of those files (Just copy everything from the Bin folder) with the .dll

-Rick

----------------------

[monkey] I believe in killer coding ninja monkeys.[monkey]
 
Ok, maybe I just did something out of order and it was just coincidence that it worked from the IDE- very possible. Out of curiosity, what is a strong key and why do some other tutorials mention it? They also mention putting an assembly key parameter in the Assemblyinfo.vb file. What are these things?
 
Those keys create a unique identifier for your application.

So if two people develope and release 2 different applications with a dll called "MySuperFlyApp.dll" the unique key will uniquely identify the libraries in the GAC.

-Rick

----------------------

[monkey] I believe in killer coding ninja monkeys.[monkey]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top