In one of the post Titled "Call a c++ method that returns a string, from c#"
Its said that , to make the following Pinvoke to work change the C++ signature to as
extern "C" REGISTRATION_API void calculate(LPSTR msg)
C++ code
extern "C" REGISTRATION_API void calculate(char* msg)
C# code
[DllImport("thecpp.dll", CharSet=CharSet.Ansi)]
static extern void calculate(StringBuilder sMsg);
How can stringBuilder which is a class ,convertd to long ptr to string .(but this is the accepted answer)
Shouldnt we use use IntPtr as below ?
extern "C" REGISTRATION_API void calculate(Intptr msg)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…