c++代码
#include "stdafx.h"
extern "C" _declspec(dllexport) char* GetJson(char* pStr)
{
return "abcdefg";
}
c#代码
public class CC
{
[DllImport("Win32Project1.dll", EntryPoint = "GetJson", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr GetSnrJson([MarshalAs(UnmanagedType.LPStr)]string temp);
public void Do()
{
StringBuilder sb = new StringBuilder(@"test");
IntPtr pStr = GetSnrJson(sb.ToString());
string json = Marshal.PtrToStringAnsi(pStr);
Console.ReadLine();
}
}
输出: