views:

76

answers:

1

I've got a managed C++ method that takes as a parameter a list of String^

the method needs to populate an unmanaged structure with pointers to the memory in the String^

extracting the WCHAR* is simple enough with PtrToStringChars

however I dont know the number of pin_ptr's to allocate at design time

I'd like to add the pinned ptr to a list, with something similar to the below List< pin_ptr< const wchar_t>>

doing this yields error C3225: generic type argument for 'T' cannot be 'cli::pin_ptr', it must be a value type or a handle to a reference

is there a way to do this? in managed C++

+1  A: 

Well you have a few problems. First pin_ptr isn't a managed type, so you wouldn't be able to put it in a List. You could use a C++ vector instead except:

Pinning pointers can only be declared as non-static local variables on the stack.

from http://msdn.microsoft.com/en-us/library/1dz8byfh%28VS.80%29.aspx.

Instead you'll likely have to use GCHandles with a GCHandleType of Pinned directly.

Logan Capaldo