(unsafe) Converting char*[] -> char** for PInvoke call

A

Adam Clauss

I am using PInvoke to call a function from a native C library.
As one of its parameters, it takes an array of strings in the form of char**.

I put the call into an unsafe block and created my array with a char*[] type. However, the compiler complains that it cannot conver
char*[] to char** when I try to make the call to the native function.

How can I do this conversion? Or is there a better way than using an unsafe block (using a System.String[] perhaps?)
 
M

Mattias Sjögren

Adam,
I put the call into an unsafe block and created my array with a char*[] type. However, the compiler complains that it cannot conver
char*[] to char** when I try to make the call to the native function.

Can't you change the parameter type to char*[] then?

Or is there a better way than using an unsafe block (using a System.String[] perhaps?)

It depends on what the parameter is for (input or output, who
allocates the memory and so on).



Mattias
 

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