I have a C ++ structure
struct UnmanagedStruct
{
char* s;
};
and c # struct
struct ManagedStruct {
[MarshalAs(UnmanagedType.LPStr)]
string s;
}
C ++ library provides
extern "C" UnmanagedStruct __declspec(dllexport) foo( char* input );
And it is imported as
[DllImport("SomeDLL.dll", CharSet = CharSet.Ansi)]
static extern ManagedStruct foo( string input );
However, when I call this function, I get
MarshalDirectiveException was unhandled
The method type signature is not compatible with PInvoke.
The thing is, this function call works if I remove char * s and string s from structures.
source
share