i am not sure what the problem is. i have a c++ function returning a string as follows
extern "C++" __declspec(dllexport) std::string D()
{
return "say hello";
}
and on my c#
[DllImport("MyMSG.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern string D();
when i run the wpf, i get an
'Unable to find an entry point named 'D' in DLL 'MyMSG.dll'.'
error. it seems to me that c++ and c# have a type mismatch on strings? i tried with other types like int and bool and i didnt get any problem. can someone explain please? thank you
EDIT first i would like to thank dxiv and andy for the response. i did more research and found that changing
public static extern string D();
to
public static extern System.IntPtr D();
then calling
string x = Marshal.PtrToStringAnsi(D());
seems to give me the right value.