-1

I've got a COM DLL with a function that should be returning an array of objects of a type that is dependant on the arguments passed in.

I know what the return type should be, but what is returned is of type System.Object[*]

Despite searching I have no idea how to cast that to anything useful. Simply trying to cast to the type it should be "someType[]" fails, also casting to System.Object[] fails. What does the * mean in this context in C#?

H H
  • 263,252
  • 30
  • 330
  • 514
Harvs
  • 34
  • 1
  • 2
    Please show it in context. C# or C++. – H H Nov 11 '14 at 08:27
  • 1
    Never seen that, unless `*` means `dynamic`. Show a screenshot. – leppie Nov 11 '14 at 08:27
  • You posted an invalid piece of code, so elaborate. What is your source (documentation)? – H H Nov 11 '14 at 08:52
  • 2
    It is a non-conformant array, its lower-bound doesn't start at 0. Not unusual in COM, the next most popular choice is 1. You'll have to use the Array class to access the array. Use its GetLower/UpperBound() method to discover valid indices, use GetValue() to retrieve an element. – Hans Passant Nov 11 '14 at 08:53
  • @HansPassant is right. I'm guessing I can't accept a comment as the answer? – Harvs Nov 11 '14 at 09:14

1 Answers1

-2

I'm assuming you mean casting to System.Object[] fails compile-time. Try casting this way:

someType[] myObj = (someType[]) (System.Object) theDllObj.theDllCall();

It's a cast-via-Object-trick I've used many times when the compiler is being grumpy.

Nilzor
  • 18,082
  • 22
  • 100
  • 167