I have a C++ struct
struct UnmanagedStruct { char* s; // Other members }; and a C# struct
struct ManagedStruct { [MarshalAs(UnmanagedType.LPStr)] string s; // Other members } the C++ library exposes
extern "C" UnmanagedStruct __declspec(dllexport) foo( char* input ); And it is imported like
[DllImport("SomeDLL.dll", CharSet = CharSet.Ansi)] static extern ManagedStruct foo( string input ); However when I call this function I get
MarshalDirectiveException was unhandled
Method's type signature is not PInvoke compatible.
The thing is, this function call works if I remove the char* s and the string s from the structs.