PInvoke and C "char **"

Hi guys ... im working on a c# wrapper for a C dll ... i have a function that takes a "char **" :

void examplefunc( int argc, char ** argv );

so in C i would do :

char ** argv ;

argv = new char *[1];
argv[0] = new char[0xff];

strcpy( argv[0], "im some dummy text" );

examplefunc( 1, argv );


i would appreciate if someone could explain me how to do this in c# with pinvoke



Answer this question

PInvoke and C "char **"

  • Michael Wittenburg

    Simone,

    I believe the following will work for you:

    public static extern void ExampleFunc(int argc, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0, ArraySubType = UnmanagedType.LPStr)] string[] argv);

    Hope that helps!
    Anson Horton
    Visual C# IDE PM



  • PInvoke and C "char **"