Marshaling a String Array


R

Rodger Brennan

I need to marshal as string array in C# to an IntPtr. Ist there any way to
do this. for instance.

string[] str = { "this", "should", "have", "a", "pointer" };
IntPtr ptr = Marshal.AllocHGlobal(Marhsal.SizeOf(str.Length * str.Length);
Marshal.StructureToPtr(str,ptr,false);

Thanks in Advance for any help.

Rodger
 
Ad

Advertisements

J

John Wood

You can use Marshal.Copy (in the interop namespace). Convert the string to a
char array then use Marshal.Copy to get the pointer out.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top