0

I have a general purpose C DLL, with functions to return pointer to a double array.

I have been able to use it in Perl and C# (Return C++ array to C#) as per my requirement.

How do I use the array (double) being returned by the DLL in VB.NET?

Kanchu
  • 3,721
  • 1
  • 15
  • 14
  • Are you talking about VB.NET or VB6? Your question is tagged with VB6 but it is more likely you mean VB.NET. – DAXaholic Jul 17 '16 at 06:45
  • @DAXaholic - corrected! – Kanchu Jul 17 '16 at 07:59
  • The C# code directly translated to VB.NET should work. If it doesn't, please explain that in the question. – Heinzi Jul 17 '16 at 08:02
  • @Heinzi - Translation using http://converter.telerik.com/ worked! Thank you... – Kanchu Jul 17 '16 at 08:25
  • @Kanchu: You're welcome! I suggest that you [add an answer to your question](http://stackoverflow.com/help/self-answer), so that others with the same problem can profit from your solution. – Heinzi Jul 17 '16 at 13:19

1 Answers1

0

As suggested by @Heinzi:

Imports System.Runtime.InteropServices

Declare Function functionReturnsArrayPointer Lib "cLibrary.dll" _
        (ByVal argument1 As Double, ByVal argument2 As Integer) As IntPtr

Sub Main()
    Dim arrayWithResult As Double() = New Double(2) {}
    Dim pointerToArray As IntPtr = functionReturnsArrayPointer(12.345, 6)

    Marshal.Copy(pointerToArray, arrayWithResult, 0, 2)
    ' Can also be done as:
    ' Marshal.Copy(functionReturnsArrayPointer(12.345, 6), arrayWithResult, 0, 2)

    ' Do whatever with array
End Sub
Kanchu
  • 3,721
  • 1
  • 15
  • 14