C# and ActiveX DLLs

Creating an ActiveX DLL using Visual Basic 6.0

  1. Fire up Visual Basic and select ActiveX DLL Icon from the New Project dialog box.
  2. Change the class name to something meaningful like “Our_csharp”
  3. Now supply the following code:

               Public Function Show()
               MsgBox ("Message box created by using Visual Basic")
               End Function

  1. For creating a function, you can use Tools | Add procedure menu.
  2. Save the project by supplying relevant class and project names.
  3. Change the Project name and Description by selecting Project | Properties menu.
  4. Set the Binary Compatibility from the components tab of the above menu. This will not create separate GUID upon each compilation.
  1. Finally create your DLL by selecting File | Make CsharpStation.dll. This is the name by which you save your VB project.
  1. That’s all. Your DLL is now ready to use in a C# program.

It is not possible for a C# program to communicate with a VB DLL without converting it into a .NET equivalent. For doing so .NET SDK provides a tool called tlbimp. It stands for Type Library Import and converts your DLL to its equivalent .NET Assembly. For the above project, supply the following command after properly setting the Environment Variables:

tlbimp CsharpStation.dll /out:Csharp.dll

A new .NET compatible file called Csharp.dll will be placed in the appropriate directory. Type in the following C# client program and execute as usual:

   using Csharp;
   using System;

   public class Csharpapply     {

       public static void main()         {
           Our_csharp c = new Our_csharp();
           s.Show();
       }
    }

Upon execution, you can be able to see the message box from our VB DLL.

Notes:

If you are using Visual Studio. NET, then you can refer the DLL from Project | Add Reference | COM Tab. Select your DLL by using the browse button. This will add reference to your project. After adding a reference copy the above code and execute.

.NET SDK users have to run a batch file named corvars.bat before attempting compilation. This batch file is included with the SDK and located in the bin directory.

About the Author

Anand Narayanaswamy is a graduate of the University of Kerala. He is currently working as an instructor in a institution affiliated with Manipal Academy of Higher Education at Thiruvananthapuram, Kerala State, India. He has over 2+ years of experience in the following skills: Java, JavaScript, Visual Basic, ASP, XML, Microsoft FrontPage, HTML, Microsoft Visual Interdev, NT Server Administration, SQL Server.

Currently he's exploring the possibilities and features of C# and related .Net Technologies.

He also runs http://www.learnxpress.com.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值