Solved

Create Web Reference dll in VB.NET, to be used in VB6

Posted on 2006-11-02
15
866 Views
Last Modified: 2008-02-01
I've little experience with .NET but have seen its cool feature of being able to add a Web Reference to a project and it builds the classes for you.

I am coding in VB6 and would like to use the .NET generated code via a DLL but can't get it to work. Can someone show me how to do the following:

1) Create a VB2005 project, adding the Web Reference https://api.betfair.com/global/v3/BFGlobalService.wsdl

2) Turn this into a DLL that can be referenced in VB6, which exposes the methods and attributes with Intellisense.

3) Show me the basic construction for calling one of the web services from the VB6 environment.

So far, I have managed to do the following:

1) Can create the VB2005 project and add the web reference.
 
2) http://vb-helper.com/howto_vb6_use_net_dll.html says I need to "Register for COM Interop," which I've done, and add "<ClassInterface(ClassInterfaceType.AutoDual)> _" to my class statement. The web reference shown above creates 23 methods from this service, so do I need to add this to every class created? If so, where, because I can't seem to put it anywhere that works.

Without completing the steps in 2, Intellisense will not show the methods and attributes for this DLL, which is what I need. Can someone help me through the steps needed to get this DLL working in VB6?

Regards
James
0
Comment
Question by:electrum2003
15 Comments
 
LVL 8

Expert Comment

by:doobdave
ID: 17856846
Hi,

The attribute: "<ClassInterface(ClassInterfaceType.AutoDual)> _" is a class-level attribute, therefore your can only apply it at the class level, eg:

<ClassInterface(ClassInterfaceType.AutoDual)> _
Public Class MyClass

...

End Class

In order to have intellisense, you will need to add your own comments by typing ''' before each method, this will create the stub for you in VB2005, you will then need to manually add the comments for each method/property that you wish to expose to your VB6 app.

Hope this sets you on the right path, post back if you need further help.

Best Regards,

David
0
 
LVL 5

Expert Comment

by:DEEPESH
ID: 17857020
In the above scenario i woukld like to add one thing
For using .Net Dll in VB6 you require it to register this dll on client machine using Regasm.exe, this will list this assembly in Project Refrence Dialog box of Vb6, actually it going to make an entry in registry, which make it interopertable with vb6.
0
 

Author Comment

by:electrum2003
ID: 17857246
Hi doobdave

>The attribute: "<ClassInterface(ClassInterfaceType.AutoDual)> _" is a class-level attribute, therefore your can only
> apply it at the class level, eg:
>
> <ClassInterface(ClassInterfaceType.AutoDual)> _
> Public Class MyClass
>
> ...
>
> End Class

Do you mean I have to write my own classes? I'm hoping to just use .NET to auto-generate classes from the web reference.

>In order to have intellisense, you will need to add your own comments by typing ''' before each method, this will
> create the stub for you in VB2005, you will then need to manually add the comments for each method/property
> that you wish to expose to your VB6 app.

I've added some comments to the auto-generated classes but none of this shows up in intellisense in VB6. However, I have referenced the .tlb file in VB6 and intellisense now shows all the web service methods as classes, but does not show the tool-tip with the parameters required to use the class.

eg I can write

"Dim bf1 As" and intellisense shows the complete list of methods, and I select GetEventsReq
"Set bf1 = New GetEventsReq"
"bf1."

At this stage, intellisense should show me all the events and attributes associated with class GetEventsReq, but it doesn't bring up anything. All the methods are there in Object Browser too, but all of them are empty.

>Hope this sets you on the right path, post back if you need further help.

I need to crack this so any help would be very much appreciated.
0
 

Author Comment

by:electrum2003
ID: 17857262
Hi DEEPESH

I can't find regasm.exe! I have tried using regsvr32 but it says it can not find an entry point.

I can still use the .tlb created by VB2005 from the References section in VB6 by browsing to the location of the .tlb file. Trying to do this with the .dll causes "can't add a reference to the specified file"

0
 
LVL 5

Expert Comment

by:DEEPESH
ID: 17857324
You will find Regasm on .Net Framework installed path, default is
C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\Regasm.exe
0
 

Author Comment

by:electrum2003
ID: 17857361
Hi DEEPESH

Thanks, I've registered it successfully so it now appears in the References list in VB6.

However, the classes still show no members in object browser.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 5

Expert Comment

by:DEEPESH
ID: 17857387
Strange??? Try using Late binding
0
 

Author Comment

by:electrum2003
ID: 17857745
Not sure what you mean by late binding in this context. Can you provide an example?
0
 
LVL 5

Expert Comment

by:DEEPESH
ID: 17864771
By lateBinding I mean try using CreateObject,

Just to revice, have you done this two things
1.) Generated Strong Name for your assembly
2.) used tlb option in Regasm

I suggest you to go through these links
http://www.vbdotnetheaven.com/Code/May2004/AccessNetCompsFromVBIA.asp
http://msdn2.microsoft.com/en-us/library/tzat5yw6.aspx
0
 
LVL 5

Expert Comment

by:DEEPESH
ID: 17865393
While browsing net i found another usefull artical
http://www.ondotnet.com/pub/a/oreilly/dotnet/news/complus_0801.html
0
 
LVL 5

Expert Comment

by:DEEPESH
ID: 17987447
Any Commnet on it
0
 

Author Comment

by:electrum2003
ID: 18146146
The solution to achieve the classes being visible to VB6 is to put

ClassInterface(ClassInterfaceType.AutoDual), _

in the class headers for every class created by the web reference and, crucially, to put

Imports System.Runtime.InteropServices

in the first lines of the .vb file created by the web reference.

As none of the respondents was able to tell me this I am unable to award them points, although I thank them for their contribution.

Regards
James
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 18225515
PAQed with points refunded (500)

Computer101
EE Admin
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now