Marshaling a String Array

  • Thread starter Thread starter Rodger Brennan
  • Start date Start date
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
 
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.
 
Back
Top