Click here to Skip to main content
15,885,909 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How do I return an array of doubles from a managed .NET C# object to unmanaged c++ COM code?

If in C# i define a class as: (and tell visual studio to make the assembly COM visible)

C#
public interface _myinterface
{
    public double[] getDoubles()
}
public class myinterface: _myinterface
{
    public double[] getDoubles()
    {
        double[] doubles;
        doubles = new double[10];
        // set values here
        return doubles;
    }
}


I'm ending up with a type library declaration of:

C++
SAFEARRAY(double) getDoubles();


and when i create a C++ class in visual studio 2008 based on the type library i get:

C++
SAFEARRAY * getDoubles()
{
    InvokeHelper(0x6002000a, DISPATCH_METHOD, VT_EMPTY, NULL, NULL);
}


which doesn't even compile because it is not returning a value.

Does what i'm attempting here make sense and/or is there a different way to do this that will yield better results?

Thanks,
Barry
Posted
Updated 10-Nov-11 6:36am
v2

1 solution

working within Com API and unmanaged code is always tricky. Below thread might help you.

http://www.codeproject.com/KB/cs/UnmanagedArraysInCSharp.aspx

Regards
Rushi
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900