0

I return COM object in C# from C++ COM library. The object has a property that returns the type C# - "object". The documentation indicated that its type is a "Variant"(in C++) and contains one-dimensional array of three "double" values​​. After making the cast,

Object obj = m.TextPosition;  // "m" - is com object
var d3 = (System.Double[])obj;// cast

I get the error: "Unable to cast object of type 'System.Double[*]' to type 'System.Double[]'.

How to solve this problem?

1 Answer 1

1

You need to create a SAFEARRAY with a lower bound of 0 to be compatible with a .NET double[].

If that's not an option then you need to cast to Array in your C# code and use its GetValue() method to access the elements. Use GetLowerBound() to know where to start.

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you! Your answer helped me find a solution. Read more above.
Your answer gave me the solution space, from which to get what I needed was not difficult. That mean you answer was accurate for me. Thanks!

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.