views:

58

answers:

3

This is my first major application using multiple classes. It is written in vb and I know about creating objects of the class and using that instance to call functions of the class. But how do I create an object with constructors to allow another program written in C# to access my classes and functions and accept things from the program.

Hope this makes sense.

A: 
Dim myClassInstance As New MyClass()

edit: Ah, you want to define a class with constructors? If that is the case, try this:

Public Class MyClass
    Public Sub New(myNumber As Integer) 'Defines a constructor with an Integer as argument
    End Sub
End Class
devoured elysium
+3  A: 

Simply create a .NET class library and include that library as a reference inside the C# program. In .NET all libraries are .DLL files.

Once you do that the library will be available to C# with C# syntax.

Brian R. Bondy
+1  A: 

You need to compile your VB classes into a class library (DLL) not an application.

From you C# application you need to add a reference to your newly compiled DLL. This DLL contains the classes and methods that you can instantiate and call from C#.

Once you've added a reference to the VB DLL from your C# assembly, you can access the VB classes (mostly) as though they were all in the same assembly. (I say mostly because access modifiers can change this, especially the 'internal' access modifier).

Michael Shimmins
so theres no need for creating objects with constructors etc. right. Just giving my partner the path to the dll should allow him access to my functions and dont they have to be public shared or something?
vbNewbie
Michael Shimmins
thank you for your response. One more if you dont mind...my overall program function is to produce a list of parsed items to a stream which he said he can provide so as to access. So like you said as long as methods are public or shared it should work?
vbNewbie
Yes - if you have a class called "StreamGenerator" with a method "Generate", both public, he can access the stream by adding a reference to your DLL and then doing:StreamGenerator generator = new StreamGenerator();generator.Generate();
Michael Shimmins