Link to home
Start Free TrialLog in
Avatar of electrum2003
electrum2003

asked on

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

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
Avatar of doobdave
doobdave

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
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.
Avatar of electrum2003

ASKER

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.
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"

You will find Regasm on .Net Framework installed path, default is
C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\Regasm.exe
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.
Strange??? Try using Late binding
Not sure what you mean by late binding in this context. Can you provide an example?
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
While browsing net i found another usefull artical
http://www.ondotnet.com/pub/a/oreilly/dotnet/news/complus_0801.html
Any Commnet on it
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
ASKER CERTIFIED SOLUTION
Avatar of Computer101
Computer101
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial