0

My question carries forward the issue from cli/C++ how to define cli::array with unmanaged type element?

I understand that to create a managed array with an unmanaged type, I need to supply its pointer so.

array<UserType*>^ args=gcnew array<UserType*>(2);

Now if I want to send this array to a native function expecting a const UserType* parameter, how do I go about it?

Community
  • 1
  • 1
Krishter
  • 489
  • 8
  • 24

1 Answers1

0

Use pin_ptr. The managed array may not have a fixed address (it can be relocated by the garbage collector).

EDIT: You have an array of UserType* so your unmanaged function should be expecting a UserType* const* instead.

Alexandre C.
  • 55,948
  • 11
  • 128
  • 197
  • could you possibly add a code snippet? i've already tried using the pin_ptr but i'm probably not doing it right. – Krishter Nov 11 '10 at 13:46
  • It's more likely that the signature of the native function is already determined, in which case the managed array needs to be changed to `cli::array^` (not pointer). – Ben Voigt Nov 11 '10 at 15:39
  • wouldn't cli::array^ be disallowed since I cannot create a managed array using a user-defined unmanaged type? (btw modifying the unmanaged type is not an option) – Krishter Nov 11 '10 at 17:02