-
Nov 21st, 2021, 03:27 PM
#1
Thread Starter
Addicted Member
Reference a .NET DLL in VB5
We need to do some REST communications in our VB5 program to a credit card processing web app. We decided to use VS 2008 to create a DLL that would do the communicating and have one of the pieces of or VB5 program reference that DLL.
So far we have created a test DLL in VS2008 and tested it using a VS2008 Windows Form. It does work. When we try to add a Reference to the DLL in VB5, we get the message "Can't add a reference to the specified file."
I have found numerous threads about using .NET Dll's with VB6 but I have not been successful in getting any of the solutions to work. I'm now wondering if VB5 just will not reference a .NET DLL.
I'm wondering if we can use a "late bind", but I don't know the syntax to try it.
This is the very simple code from VS2008. It's purpose is just to see that we can use the add, mult and hello functions in VB5.
Namespace TstDLL
Public Class MathStuff
Public Function addXY(ByVal x As Integer, ByVal y As Integer) As Integer
Return x + y
End Function
Public Function multXY(ByVal x As Integer, ByVal y As Integer) As Integer
Return x * y
End Function
Public Function Hello()
Return "Hello World 12345"
End Function
End Class
End Namespace
-
Nov 21st, 2021, 03:40 PM
#2
Re: Reference a .NET DLL in VB5
Originally Posted by GRichG
I have found numerous threads about using .NET Dll's with VB6 but I have not been successful in getting any of the solutions to work.
Have you seen this one?
Also, if you're going to be working in .Net, I strongly recommend you use a more up to date version of Visual Studio. VS2019 and VS2022 are both available and 100% free to download and use.
-
Nov 21st, 2021, 03:53 PM
#3
Re: Reference a .NET DLL in VB5
They are not 100% free to download for ANYBODY. Enterprises have a strict definition, and strong limitations on how they are allowed to use VS. It is entirely likely, based on the question, that the OP is not allowed to get a free download.
My usual boring signature: Nothing
-
Nov 21st, 2021, 04:22 PM
#4
Re: Reference a .NET DLL in VB5
The community edition is free and is a complete product in and of itself. It is more than sufficient for the majority of users.
Originally Posted by Shaggy Hiker
It is entirely likely, based on the question, that the OP is not allowed to get a free download.
What gave you that impression?
-
Nov 21st, 2021, 06:00 PM
#5
Thread Starter
Addicted Member
Re: Reference a .NET DLL in VB5
Originally Posted by Niya
Have you seen this one?
Also, if you're going to be working in .Net, I strongly recommend you use a more up to date version of Visual Studio. VS2019 and VS2022 are both available and 100% free to download and use.
Hi Shaggy, yes, I saw a couple of examples you gave to make it happen. This was one of them. I also looked at another example which had a link within the link above. I followed the instructions, used VS2019 and couldn't get either of them to work.
Also, I backed off to VS2008 because it was closer to VB5.
Another wrinkle that may be the killer. The VB5 development system is XP SP3. I found VS2005 in the XP system and I'm going to see if that helps. Unfortunately the program is massive, about 1/2 million lines and includes a few add-on tools from the late 90's. We looked at converting to .NET several years ago but the program would not convert as there were way too many changes in code and syntax. I'm hoping this is doable.
I've been beating my head against this for about 20 hours and I'm cooked. I have to pull off for tonight but will be back on in the AM.
edit: one more thing....the VS2008 and VS2019 computer is a Win10 computer, so the VB5 program tried to register across a UNC, then we moved the DLL to the XP and tried again. Nada....
Last edited by GRichG; Nov 21st, 2021 at 06:09 PM.
-
Nov 21st, 2021, 09:45 PM
#6
Re: Reference a .NET DLL in VB5
You mentioned VB5, do you also happen to have a copy of VB6? Try it with VB6. The idea here is to confirm or eliminate the possibility that whatever differences exists between VB5 and VB6 are not the cause of your issues. All of the COM interop stuff I ever did was always with VB6, not VB5 so I don't know if it will work in VB5. I would assume it would but I actually do not know for sure.
-
Nov 21st, 2021, 10:41 PM
#7
Thread Starter
Addicted Member
Re: Reference a .NET DLL in VB5
Originally Posted by Niya
You mentioned VB5, do you also happen to have a copy of VB6? Try it with VB6. The idea here is to confirm or eliminate the possibility that whatever differences exists between VB5 and VB6 are not the cause of your issues. All of the COM interop stuff I ever did was always with VB6, not VB5 so I don't know if it will work in VB5. I would assume it would but I actually do not know for sure.
No, we don't have VB6. I'm going to just buy a copy. If nothing else, I can use it as a wrapper.
-
Nov 21st, 2021, 11:58 PM
#8
Re: Reference a .NET DLL in VB5
Originally Posted by Niya
The community edition is free and is a complete product in and of itself. It is more than sufficient for the majority of users.
That's true, but it depends where it is going to be used. If you're using it commercially, I believe that you can only do so in an organisation where a maximum of 5 people are doing so. Any more than 5 and you are legally required to buy Professional or Enterprise licenses. If you're a lone developer or part of a small team then you're good to go with Community.
-
Nov 22nd, 2021, 12:00 AM
#9
Re: Reference a .NET DLL in VB5
Originally Posted by GRichG
No, we don't have VB6. I'm going to just buy a copy.
I don't think that you can actually do so legally these days. You can probably do so illegally and that may not be a problem for you, but if you work for a company that is concerned about legal licenses for software, I don't think you'll be able to do it through them.
-
Nov 22nd, 2021, 01:00 AM
#10
Thread Starter
Addicted Member
Re: Reference a .NET DLL in VB5
Originally Posted by jmcilhinney
That's true, but it depends where it is going to be used. If you're using it commercially, I believe that you can only do so in an organisation where a maximum of 5 people are doing so. Any more than 5 and you are legally required to buy Professional or Enterprise licenses. If you're a lone developer or part of a small team then you're good to go with Community.
I'm the only developer. I have part time people sometimes and I farm out some work sometimes.
I've even used India twice.
Last edited by GRichG; Nov 22nd, 2021 at 01:06 AM.
-
Nov 22nd, 2021, 01:55 AM
#11
Addicted Member
Re: Reference a .NET DLL in VB5
Originally Posted by Niya
You mentioned VB5, do you also happen to have a copy of VB6? Try it with VB6. The idea here is to confirm or eliminate the possibility that whatever differences exists between VB5 and VB6 are not the cause of your issues. All of the COM interop stuff I ever did was always with VB6, not VB5 so I don't know if it will work in VB5. I would assume it would but I actually do not know for sure.
There is no problems in use VBNet 2005 or 2008 dlls via interop with VB5, it works like with VB6
-
Nov 22nd, 2021, 02:44 AM
#12
Re: Reference a .NET DLL in VB5
Originally Posted by GRichG
I'm the only developer. I have part time people sometimes and I farm out some work sometimes.
I've even used India twice.
In that case, you certainly can use the Community edition of VS, which, if I'm not mistaken has been available since 2012. Unless you have a specific reason to do otherwise, I would suggest using at least VS 2019. VS 2022 is the latest but is still quite new so may have more bugs than 2019 and is also missing some extensions that support 2019.
-
Nov 22nd, 2021, 03:31 AM
#13
Re: Reference a .NET DLL in VB5
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------------------
People call me crazy because i'm jumping out of perfectly fine airplanes.
---------------------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad
-
Nov 22nd, 2021, 11:23 AM
#14
Re: Reference a .NET DLL in VB5
Originally Posted by GRichG
No, we don't have VB6. I'm going to just buy a copy. If nothing else, I can use it as a wrapper.
Trying to figure out what you mean by use it as a wrapper? VB6 can load and compile VB5 projects without issue. I had lots of VB5 projects when I moved to 6 and did not have to do anything to any of them to move to 6. 6 works with everything 5 did and adds a good bit more plus the 6 service packs that came out later. The only reason to use 5 over 6 is if you have 5 and do not have 6.
-
Nov 22nd, 2021, 01:38 PM
#15
Thread Starter
Addicted Member
Re: Reference a .NET DLL in VB5
Originally Posted by DataMiser
Trying to figure out what you mean by use it as a wrapper? VB6 can load and compile VB5 projects without issue. I had lots of VB5 projects when I moved to 6 and did not have to do anything to any of them to move to 6. 6 works with everything 5 did and adds a good bit more plus the 6 service packs that came out later. The only reason to use 5 over 6 is if you have 5 and do not have 6.
By "wrapper" I mean "interface". Using a VB6 DLL to interface between the VB5.EXE and the .NET DLL.
A layer of complexity that I'd rather not use.
-
Nov 22nd, 2021, 01:49 PM
#16
Thread Starter
Addicted Member
Re: Reference a .NET DLL in VB5
Originally Posted by Zvoni
Originally Posted by gilman
There is no problems in use VBNet 2005 or 2008 dlls via interop with VB5, it works like with VB6
I'm not having a lot of success in getting the little test VB5 program to register or CreateObject while using a DLL created in VB2005 on the XP SP3 computer. If VB5 should register just like VB6 then getting a copy of VB6 will not help.
Unfortunately the article kb/817248 is mostly Greek to me. I did recognize a few things in it and rebuilt the DLL with a strong name and box "Register for COM Interop" checked (it wasn't)
I'm not sure what "interop" means but it looks like another level of complexity.
This is how I'm trying to do a late bind with it. Is this the correct syntax?
Private Sub btnTestAdd_Click()
Dim tDLL As Object
Set tDLL = CreateObject("TestVBDLL.dll")
Dim tstDLL As Object
Set tstDLL = tDLL.tstDLL
Text3.Text = tstDLL.addXY(Text1.Text, Text2.Text)
End Sub
It fails on CreateObject. "ActiveX component can't create object"
Last edited by GRichG; Nov 22nd, 2021 at 01:52 PM.
-
Nov 22nd, 2021, 02:35 PM
#17
Re: Reference a .NET DLL in VB5
Originally Posted by GRichG
This is how I'm trying to do a late bind with it. Is this the correct syntax?
Code:
Private Sub btnTestAdd_Click()
Dim tDLL As Object
Set tDLL = CreateObject("TestVBDLL.dll")
Dim tstDLL As Object
Set tstDLL = tDLL.tstDLL
Text3.Text = tstDLL.addXY(Text1.Text, Text2.Text)
End Sub
It fails on CreateObject. "ActiveX component can't create object"
I don't think that is how you use CreateObject. The name of the class you're trying to instantiate is supposed to be in CreateObject's first parameter.
Also, I've never tested COM Interop with CreateObject. I'm not entirely sure if it will work the same way. Why are you trying to use late binding anyway, is there a specific reason for this?
-
Nov 22nd, 2021, 02:48 PM
#18
Re: Reference a .NET DLL in VB5
Originally Posted by GRichG
By "wrapper" I mean "interface". Using a VB6 DLL to interface between the VB5.EXE and the .NET DLL.
A layer of complexity that I'd rather not use.
But you could just build the exe using VB6 and place whatever code needed directly into your main program. No need to add a layer of complexity.
-
Nov 22nd, 2021, 03:20 PM
#19
Thread Starter
Addicted Member
Re: Reference a .NET DLL in VB5
Originally Posted by Niya
I don't think that is how you use CreateObject. The name of the class you're trying to instantiate is supposed to be in CreateObject's first parameter.
Why are you trying to use late binding anyway, is there a specific reason for this?
I'm hoping, maybe foolishly, that a late bind might work where the early referencing doesn't.
Originally Posted by Niya
I don't think that is how you use CreateObject. The name of the class you're trying to instantiate is supposed to be in CreateObject's first parameter.
You're right. It's not the right syntax.
-
Nov 22nd, 2021, 03:25 PM
#20
Re: Reference a .NET DLL in VB5
Ok I've just tested the use of CreateObject in my CodeBank sample referenced in the second post and it works fine.
I was able to show the GridForm object like this:-
Code:
Dim gd As GridForm
Set gd = CreateObject("GridDisplay.GridForm")
gd.Show
So with that I'm going to guess that you are indeed not using CreateObject correctly. You must include the project name and the name of the object you're trying to create. If you're not sure about the project name, you can use the object browser(press F2) to find out the name of the project that contains the .Net COM class you want to instantiate.
-
Nov 22nd, 2021, 03:34 PM
#21
Re: Reference a .NET DLL in VB5
Also, there is one other very important thing I forgot to ask. Are you sure you're registering the .Net DLL? This is a very important step and it won't work without being registered just like any other COM server.
-
Nov 22nd, 2021, 03:52 PM
#22
Thread Starter
Addicted Member
Re: Reference a .NET DLL in VB5
Originally Posted by Niya
Also, there is one other very important thing I forgot to ask. Are you sure you're registering the .Net DLL? This is a very important step and it won't work without being registered just like any other COM server.
On the XP computer;
When I use regsvr32, I get TestVBDLL.dll was loaded, but the entry point was not found. When I use RegAsm and Register.bat (without the /codebase, because it complained about that), shown before the pause, I get,
Types registered successfully
Assembly exported to 'C:\VBPrograms\TestVBs\Test REST DLLs\TestVBDLL.tlb', and the type library was registered successfully
I got RegAsm and Register.bat from your examples posted on this forum.
How about this "entry point" how do I define that when I make the DLL. I've made about 20 DLL's in VB5 to use with the program and I've never had to deal with any of this except to register them on the target computers.
-
Nov 22nd, 2021, 04:07 PM
#23
Re: Reference a .NET DLL in VB5
Originally Posted by GRichG
(without the /codebase, because it complained about that)
What was the error? I remember when I was first exploring COM Interop, I didn't get RegAsm to work without /codebase.
Originally Posted by GRichG
How about this "entry point" how do I define that when I make the DLL. I've made about 20 DLL's in VB5 to use with the program and I've never had to deal with any of this except to register them on the target computers.
Regsvr32 doesn't actually do anything that complicated. All it does is load the DLL and tries to call a function named DllRegisterServer. However, .Net compilers do not create this entry point in .Net COM interop DLLs which is why we use RegAsm.
-
Nov 22nd, 2021, 04:36 PM
#24
Thread Starter
Addicted Member
Re: Reference a .NET DLL in VB5
Originally Posted by Niya
What was the error? I remember when I was first exploring COM Interop, I didn't get RegAsm to work without /codebase.
From the .BAT when ran with /codebase on XP
C:\temp\temp>regasm TestVBDLL.dll /tlb:TestVBDLL.tlb /codebase
Microsoft (R) .NET Framework Assembly Registration Utility 2.0.50727.5483
Copyright (C) Microsoft Corporation 1998-2004. All rights reserved.
RegAsm : warning RA0000 : Registering an unsigned assembly with /codebase can cause your assembly to interfere with other applications that may be installed on the same computer. The /codebase switch is intended to be used only with signed assemblies. Please give your assembly a strong name and re-register it.
Types registered successfully
Assembly exported to 'C:\temp\temp\TestVBDLL.tlb', and the type library was registered successfully
C:\temp\temp>pause
Press any key to continue . . .
I feel like my problem is that I'm not doing something right when creating the .DLL
-
Nov 22nd, 2021, 04:54 PM
#25
Re: Reference a .NET DLL in VB5
In the VB5-IDE go to references and look for your objects from that dll.
they should appear there
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------------------
People call me crazy because i'm jumping out of perfectly fine airplanes.
---------------------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad
-
Nov 22nd, 2021, 05:07 PM
#26
Re: Reference a .NET DLL in VB5
Originally Posted by GRichG
From the .BAT when ran with /codebase on XP
C:\temp\temp>regasm TestVBDLL.dll /tlb:TestVBDLL.tlb /codebase
Microsoft (R) .NET Framework Assembly Registration Utility 2.0.50727.5483
Copyright (C) Microsoft Corporation 1998-2004. All rights reserved.
RegAsm : warning RA0000 : Registering an unsigned assembly with /codebase can cause your assembly to interfere with other applications that may be installed on the same computer. The /codebase switch is intended to be used only with signed assemblies. Please give your assembly a strong name and re-register it.
Types registered successfully
Assembly exported to 'C:\temp\temp\TestVBDLL.tlb', and the type library was registered successfully
C:\temp\temp>pause
Press any key to continue . . .
I feel like my problem is that I'm not doing something right when creating the .DLL
Well according to that it worked. I wouldn't worry too much about that warning. For your purposes I think you can safely ignore that warning. Strongly named assemblies are a throwback to a bygone era where the GAC was a big deal.
Also, Zvoni is correct. After RegAsm registers the DLL, it should show up in the VB5/6 IDE under references. Does it show up in the references for you?
-
Nov 22nd, 2021, 05:42 PM
#27
Thread Starter
Addicted Member
Re: Reference a .NET DLL in VB5
Originally Posted by Niya
After RegAsm registers the DLL, it should show up in the VB5/6 IDE under references. Does it show up in the references for you?
YES!!! It did!!!
It worked................. :-)
I need a drink.....I'm buying!
Now to tackle REST and responding to events in some DLL.
Thank you very much Niya, Angel of Code
-
Nov 22nd, 2021, 10:33 PM
#28
Re: Reference a .NET DLL in VB5
Glad we could be of service
-
Nov 23rd, 2021, 06:01 AM
#29
Re: Reference a .NET DLL in VB5
Originally Posted by Niya
Glad we could be of service
LOL
Both you and the angel?
cheers,
</wqw>
-
Nov 25th, 2021, 12:52 AM
#30
Re: Reference a .NET DLL in VB5
Originally Posted by wqweto
LOL
Both you and the angel?
cheers,
</wqw>
Lol I was actually referring to the other posters in the thread but looking at it now I see what you saying....
-
Nov 30th, 2021, 08:04 PM
#31
Thread Starter
Addicted Member
Re: Reference a .NET DLL in VB5
I thought this may help if someone opens this post looking for how-to-do-it. I just happened to stumble on this. This article is referenced elsewhere on this forum. It does a pretty good job of explaining why Niya's solution worked. It's pretty involved but is a good read for a .NET novice like me.
Calling a .NET Component from a COM Component
https://docs.microsoft.com/en-us/pre...ectedfrom=MSDN
-
Nov 30th, 2021, 08:55 PM
#32
Re: Reference a .NET DLL in VB5
Yea, that is a good article. It's gets into the theory behind it. I just focused on how to do it in my post.
-
Nov 30th, 2021, 10:42 PM
#33
Thread Starter
Addicted Member
Re: Reference a .NET DLL in VB5
Originally Posted by Niya
Yea, that is a good article. It's gets into the theory behind it. I just focused on how to do it in my post.
Yes....and I'm glad you did. I was able to understand more of what the article was saying because of using the tools you specified.
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
|