I am new to C++.
And I am developing a just simple dll.
I have to C++ function from C# with a file location information which should be string.
And C++ returns some string to C#.
Here are my codes..
extern "C" __declspec(dllexport) const char* ParseData(char *filePath)
{
string _retValue(filePath);
printf(_retValue.c_str()); //--> this prints ok
return _retValue.c_str();
}
[DllImport("D:\\Temp\\chelper.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern IntPtr ParseData(string s);
static void Main(string[] args)
{
string s = "D:\\Temp\\test.bin";
string ret = Marshal.PtrToStringAnsi(ParseData(s));
Console.WriteLine(ret);
}
When I look into the string that C++ returns, it looks like below.
硼硼硼硼硼硼硼硼硼硼硼硼硼硼硼硼硼硼硼硼硼硼硼硼硼硼硼硼硼硼硼硼硼硼硼硼硼硼硼硼硼硼硼硼硼硼硼硼硼硼硼硼
I am expecting "D:\Temp\test.bin" which I passed to C++ dll.
What's wrong with my code?