Mkcanada

Hi,

I am writing a C# program with Visual Studio 2005,

I have to use a dll which has been written with Visual Basic.net.

How can I use it

Thanks,

MK



Re: Windows Forms General How can I use the Visual Basic.Net DLL in C#

Christopher Payne

You can add a reference to the compiled VB dll in your C# project. Open your Solution Explorer for your C# project, and right-click on References. Select Add Reference, then click Browse and browse to the dll you want to reference.

While each project is restricted to a single language, you can reference any dll's you want. You can even reference a .Net 2003 dll in a .Net 2005 project, or vice versa. Of course the PC that runs the app would then need both the 2003 and 2005 frameworks installed to run the app.





Re: Windows Forms General How can I use the Visual Basic.Net DLL in C#

Mkcanada

Thanks for your reply.

How can I instantiate the DLL

MK





Re: Windows Forms General How can I use the Visual Basic.Net DLL in C#

Christopher Payne

Once you have added the dll as a reference, you can instantiate objects defined in that dll the same way you instantiate other objects. If you know the name(s) of the namespace(s) defined in the dll, you can start there and let intellisense guide you. Or you can use the object browser to find the names of the namespaces and classes defined in the dll.

As long as you have a reference to the dll, using it won't be any different than using any other dll. You may know that the dll was written in VB, but it doesn't matter, you'll still use C# syntax when using it.

For example, let's say the dll uses a namespace MyVBDLL, and has a class named MyVBClass. And for the sake of argument we want to read a property called MyVBMessage. We would do that like this:

Code Snippet

private void Foo()

{

MyVBDLL.MyVBClass vbObject = new MyVBDLL.MyVBClass();

MessageBox.Show(vbObject.MyVBMessage);

}