PDA

View Full Version : Get list<T> from c# dll and access to its items



pavel
12-20-2013, 08:15 AM
Hello everyone!
I wrote class library in c# like this (simplified):


namespace DotNetLibrary
{
public class CPoint
{
public int x;
public int y;

public CPoint(int x, int y)
{
this.x = x;
this.y = y;
}

public List<CPoint> GetSomePoints(int i_max, int j_max)
{
List<CPoint> result = new List<CPoint>();

for (int i = 0; i <= i_max; i++)
{
for (int j = 0; j <= j_max; j++)
{
result.Add(new CPoint(i, j));
}
}

return result;
}
}
}

In Excel in VBA I can create instance of class CPoint like this:


Private Sub TestDotNetCall()
Dim pt As New CPoint(100, 100)
End Sub Can you please help me, how can I call method 'GetSomePoints' in VBA? And how can I access to the items of the List in VBA?

Thanks,
Pavel

Kenneth Hobs
12-20-2013, 09:05 AM
Read through this thread for an example though my example is in vb.net.
http://www.vbaexpress.com/forum/showthread.php?45888-Calling-DLL-function-from-Excel-VBA-doesn-t-return-value

You could post the DLL I guess and show some sample input and output. Keep in mind that I am not too "sharp".