C++ dll的某条函数
extern "C" _declspec(dllexport) char* __stdcall test03(char* inStr);
C#中进行调用
[DllImport("test.dll",EntyPoint = "test03",CallingConvention = CallingConvention.StdCall)]
public static extern IntPtr test03C(byte[] inStr);
public string test03(string str)
{
//将string 转成byte[]数组
byte[] inStr = System.Text.Encoding.Default.GetBytes(str);
//添加字符串结束符'\0'
Array.Resize(ref inStr, inStr.Length + 1);
inStr[inStr.Length - 1] = 0;
//将InPtr转为string并返回
return Marshal.PtrToStringAnsi(test03C(inStr));
}