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?

5
  • Are you talking about VB.NET or VB6? Your question is tagged with VB6 but it is more likely you mean VB.NET. Commented Jul 17, 2016 at 6:45
  • @DAXaholic - corrected! Commented Jul 17, 2016 at 7:59
  • The C# code directly translated to VB.NET should work. If it doesn't, please explain that in the question. Commented Jul 17, 2016 at 8:02
  • @Heinzi - Translation using converter.telerik.com worked! Thank you... Commented Jul 17, 2016 at 8:25
  • @Kanchu: You're welcome! I suggest that you add an answer to your question, so that others with the same problem can profit from your solution. Commented Jul 17, 2016 at 13:19

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.