|
-
Jan 26th, 2006, 11:37 AM
#1
Thread Starter
Hyperactive Member
.NET code in VB6 application
I have our main application for the company written in .NET. I would like to be able to rewrite functions and such in .NET into a dll and use it through the application's VB6 code. I know how to create a class library to make the dll, but how would I go about being able to use it through VB6? I know this is possible and I think that if I do it in stages like this, that I will be able to keep the program running while rewriting it into .NET so I wouldn't have to drop enhancements and such because I devote time to only rewriting hundreds of thousands of lines.
By the way, most of th ecode was written by a hobbiest and is so redundant it isn't funny, so the effort isn't nearly the job I thought it would be at first.
Thanks for the info!
Currently Using: VS 2005 Professional
-
Jan 26th, 2006, 11:43 AM
#2
Re: .NET code in VB6 application
-
Jan 26th, 2006, 12:05 PM
#3
Thread Starter
Hyperactive Member
Re: .NET code in VB6 application
Another question, why does a Class Library not have a messagebox object? I cannot use messagebox.show.
Just curious.
ThanksALL!
Currently Using: VS 2005 Professional
-
Jan 26th, 2006, 12:11 PM
#4
Re: .NET code in VB6 application
Because the MessageBox is part of System.Windows.Forms, and a class library has no visual interface itself. Only forms do.
-
Jan 26th, 2006, 12:13 PM
#5
Re: .NET code in VB6 application
you can use it though if you set a refernce to windows forms in your project. It doesn't create any extra dependancy, as forms is part of the standard framework.
Or if your "REALLY" wanted to, you could use msgbox instead, however I personally stay away from legacy VB stuff.
-
Jan 26th, 2006, 12:16 PM
#6
Thread Starter
Hyperactive Member
Re: .NET code in VB6 application
I may be writing this in C# and I was wondering if this was the same case in a C# class library as well? Can you do a using statement to include it?
Currently Using: VS 2005 Professional
-
Jan 26th, 2006, 12:20 PM
#7
Re: .NET code in VB6 application
yes you can
BUT...
when you create a windows form project (either in VB or CS) it adds the needed reference to the forms.dll in the framework.
if this is a class library app, then by default, I don't think the reference is added, so you will need to add it yourself from the .net tab of the references screen. Once you have a reference to the forms.dll, you can use imports or using to shorten your qualified names.
-
Jan 26th, 2006, 12:30 PM
#8
Thread Starter
Hyperactive Member
Re: .NET code in VB6 application
Hmm, I just read those 2 articles and had a question. Does Regasm.exe make these type libraries the same way the .NET IDE makes an Interop? I know an interop is basically a wrapper of older, non.NET code so that .NET can use it.
So if I use regasm.exe, I will be able to make all of my functions, subs, ect. usable throught the VB6 application GUI even though it is .NET? That is cool if it will, this will make reprogramming this legacy code MUCH easier.
Currently Using: VS 2005 Professional
-
Jul 20th, 2006, 06:19 AM
#9
Re: .NET code in VB6 application
For people's general info:
All you have to do to make a DLL visible from VB6 is this:
1. in .NET Go to the Project properties...application...Assembly Info... and set the "Make Assembly COM-Visible" to TRUE.
2. Build your .net DLL
3. Copy the .net DLL to the same directory as your VB6 exe file.
4. Start-Menu...Programs...Visual Studio 2005...tools...Visual Studio 2005 Command Prompt
5. use this command prompt to navigate to your VB6 folder and then enter...
regasm mydllname.dll /tlb:mydllname.tlb
This should give you a success message (if no then you didn't build the DLL properly).
6. Go into your VB6 project and Project...references...browse. then navigate to your VB6 project folder, then select the tlb file that you just made with regasm.
Hopefully this will now come up in your references list. Click OK and then try to make an instance of one of the classes in your DLL from inside your VB6 project.
I did all this just now and it works beautifully.
However this doesn't explain how to deploy a VB6 app made in this way. I am not sure what wwould have to be done on the target machine, You'd probably have to put a call to Regasm in the setup project. If anyone knows for sure then please PM me and I'll update this thread accordingly.
Hope this helps.
I don't live here any more.
-
Jul 20th, 2006, 07:34 AM
#10
Re: .NET code in VB6 application
Here is a thread that I replied to sometime back on CG which shows you how to create a DLL in .NET and call it from VB 6.
http://www.codeguru.com/forum/showthread.php?t=358450
To deploy it, you will have to create a Setup Project in VS.NET for the class library and then run this Setup on the Target machine.
Use [code] source code here[/code] tags when you post source code.
My Articles
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|