C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Articles » .NET Framework »

How To Call ActiveX DLL in .Net Environment


Posted Date: 02 Jun 2004    Resource Type: Articles    Category: .NET Framework
Author: chandrakant SarodeMember Level: Bronze    
Rating: 1 out of 5Points: 5



How To Call ActiveX DLL in .Net Environment

Summary

In Visual Basic 6.0 we can create COM Server with ActiveX EXE or DLL, as you know ActiveX EXE is Out-Process Server and DLL is In-Process Server. once you create ActiveX DLL i.e.COM Server and implement it to Visual Basic Client Program so this done through Visual Basic. After create DLL Server how to call this in .Net Plot form.
This article deals with this idea.

Managed Code and Unmanaged Code

A Visual Basic 6.0 DLL is Unmanaged that means it not being generated By CLR (Common Language Runtime)

But A C# or any .net Language while compile time it generate IL (Intermediate Language) and it called as Managed Code.

But we can make this DLL to C# Environment, by Covering the same into .Net Compatible version. Now follow this example.

Step1.
First you Create an ActiveX DLL
1. Select new ActiveX DLL form project dialog box icon
2. Change the name VB_DLL
3. Create a function with Tools | Add procedure menu and Specify Function Name i.e. VBDLL_Message.
4. Add Code the message function.



5. Public Function VBDLL_Message ()
Msgbox (“This is Visual Basic DLL Server”)
End Function


6. Set the Binary Compatibility form the Components tab of the above menu.
7. Save the Project

Step2.
Call this DLL in .Net environment
1. It is not possible for a C# program to communicate with a VB DLL
2. First we have to converting the same into .Net equivalent.
3. I.e. with help of .Net SDK provides a tool called tlbimp.
4. It stands for Type Library Import and Coverts your DLL to its equivalent .Net Assembly

Step 3.
Set Proper Setting the environment Variable:

Tlbimp Csharpcorner.dll / out:newCsharp.dll
A New .Net compatible file called newCsharp.dll will be placed in the appropriate directory.

In Client type this code.


Using newCsharp;
Using System;

Public class apply {
Public static void main () {
Our_newCsharp D = new our_newCsharp();
d.VBDLL_Message();
}
}


After execution you can see the VBDLL Message i.e “ This is Visual Basic DLL Server”

Note:

If you are using Visual Studio.Net ,then you can refer the DLL Form Project | Add Reference | Com Tab.
Select your DLL by using the browse button. this will add reference t your project.

Please let me know Feedback.






















Responses

Author: Praveen    05 Jun 2004Member Level: Silver   Points : 0
The article gives a nice intro to a very needy topic. However, English needs some improvement. Great article overall.


Author: Rakesh Chander Sharma    02 Jul 2004Member Level: Silver   Points : 0
Very nice article, english used is quite simple and thats the best part of it. A very nice article overall.


Author: Ravi    17 Aug 2004Member Level: Bronze   Points : 0
Its really very simple and great example


Author: newmangl    08 Sep 2004Member Level: Bronze   Points : 0
I don't believe you have to do any conversion to get an ActiveX/COM DLL to work in .NET, at least for non-GUI functionality, anyway. I recently created a VB ActiveX DLL that returned some string values, and it works just fine in an ASP.NET page. I simply added a COM reference to the VB DLL and used the VBProjectName.ClassName format to declare an instance of the object. Easy as pie, no conversion. We even create instances of Office in .NET, and Office is COM based also.

What am I missing?



Author: Bert Credo    21 Dec 2004Member Level: Bronze   Points : 0
Hi, I had the following activeX dll created in VB 6.
DAL - Data Access Layer
BLL - Business Logic Layer
WFL - Work Flow Layer

which I used in ASP, it works fine. How can I apply these in C#? Im new on this environment.
Where to put the ConnectionString in the Global.asax. Is in Application_Start or Session_Start?

In ASP, Global.asa I used to put in:
Sub Session_OnStart
Session("DOCTRACKER_CONNECTIONSTRING") = "Provider=SQLOLEDB;Server=servername;Database=databasename;UID=username;PWD=userpwd"
End Sub

Please help how to apply in C#.

Thnks,


Author: vijay    29 Apr 2005Member Level: Bronze   Points : 0
good one for beginers... msg conveyed english doesn matter.... wateveh....

vijay


Author: V.Venkatesa Prasath    19 Aug 2005Member Level: Bronze   Points : 0
Thanks U.
I will Except more such type of article Reg .NET From you.

Thanks,
PrasathVV


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Handling The Network Errors
Previous Resource: Assigning One Array Reference Variable To Another.
Return to Discussion Resource Index
Post New Resource
Category: .NET Framework


Post resources and earn money!
 
Related Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use