Link to home
Start Free TrialLog in
Avatar of akashchopra
akashchopra

asked on

Returning arrays from C++ DLL to VB.net

I've got a C++ DLL which has a function that returns an array:

double* Test()
{
    double ReturnArray[10];
...
   return ReturnArray;
}

I call this from VB.net as follows:

Declare Function C_Test Lib "Test.dll" Alias "Test" () As Double()
Dim C_Result(9) As Double
C_Result = C_Test()

but get a "Can not marshal return value" error.

What am I missing?
Thanks
Akash
Avatar of skaykay
skaykay

This is a consequence of interaction between managed and unmanaged code. You can use the methods in Marshal class to convert from an unmanaged to a managed heap..

Check for article Q306801 in the microsoft knowledge base to see how to accomplish this, or check for marshal class in MSDN.

Cheers,
skaykay!
Avatar of akashchopra

ASKER

Thanks, but there is so much information in that article that I'm not sure where to start. Could you provide an example, or at least a reference to the appropriate method of the marshal class?
ASKER CERTIFIED SOLUTION
Avatar of skaykay
skaykay

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial