Click to See Complete Forum and Search --> : Using Vb Dll In Asp.net


kashyaplalit
October 13th, 2003, 07:37 AM
i am having a DLL which is made in vb6 now if i want to use that dll in asp.net framework the step which i folled are
1)i included refences of that dll now i have created an object of tha dll
like dim obj as new <dll name>.class name
now to use function of this i used
obj.<func()>
but it gives me an error
so what is te way to do this
help

TheCPUWizard
October 13th, 2003, 07:50 AM
If you are referring to a COM DLL written in VB6 and wish to use it SERVER side, the procedure is the same as for accessing any COM object from within .NET...You need to create a wrapper (using the utility provided with .NET). Once this is done you can access it like any other .NET.

If you are referring to a control what you wish to use on the CLIENT side, you can simply place it in the ASPX file using the OBJECT tag.

kashyaplalit
October 13th, 2003, 08:22 AM
thankx for reply what the tool which ur talking tell me what is the name of the tool to write a wrapper i ahve never used so just send sample useing any dll plz

poochi
October 13th, 2003, 05:23 PM
A .Net component/application can not directly access a non .net COM component. To access it, you need to create a wrapper called runtime-callable wrapper (RCW). RCW sits inbetween your .Net component and COM component and acts as a mediator. RCW maintains all "AddRef", "Release" for you. If you are using VS.Net and references a COM dll, VS.Net automatically creates the RCW for you. If you are not using VS.Net, you can use TlbImp.exe (which is included in .Net SDK) to generate the wrapper.

How to call a VB component from ASP.Net:

The first thing you should know is, AFAIK, all VB components are Single Threaded Apartment Components. But, ASP.Net applications are MTA. So, as per microsoft document, your VB component won't work in ASP.Net environment if you don't set an attribute in ASP.Net page. The attribute is called "aspcompat".

<%@Page aspcompat=true Language=VB%>.

The above line force your asp page to use STA instead of MTA.

Previous ASP version(s) were supporting only "late binding" method to create and access COM components (thro' IDispatch interface).

Ex:
Dim Obj As Object
Obj = Server.CreateObject("ProgID")
Obj.MyMethodCall

But, ASP.Net supports early and late binding methods. Early binding is, you can directly create an object as you do in VB or C# applications. To do that, you need the wrapper (RCW) for the COM object. Use the TlbImp.exe to create the wrapper and place the wrapper dll under <yourwebdirectory>/bin folder. Then you should be able to create the object like the following..

Dim obj as MyClasName
obj = new MyClassName
obj.CallSomeMethod()

Poochi..