tags:

views:

184

answers:

1

I have a DLL that I need to P/Invoke the following method: DWORD Foo( int a, int *b, char *c );

Per the documentation, parameter 'c' is an out parameter that must be a char array of size 16. A null terminated string is placed into it.

What is the P/Invoke definition for parameter 'c' (I've got the others fine)? How is the content of 'c' read after the call?

+1  A: 

I prefer to use StringBuilder for these things actually. It's far easier to deal with than char arrays or immutable strings. Just make sure you initialize it with enough capacity (16 in this case) for the DLL to fill. Typically it marshalls over just fine, but you may have to set the character set in your DLLImport declaration.

Here is a little more info on this: Marshaling between Managed and Unmanaged Code from MSDN magazine (Stringbuilder section)

Egor
Works like a charm, thanks!