C#调用DLL中的函数返回字符串的方法

  • Post author:
  • Post category:其他


unity/C#

public class CalAngle : MonoBehaviour
{
    [DllImport("EllipseDetectTest1")]
    public static extern int GetStr(ref byte str);
    
    // Use this for initialization
    void Start()
    {
       
        int aa = CircleDetec(ref s[0]);
        string strGet = System.Text.Encoding.Default.GetString(s, 0, s.Length); //将字节数组转换为字符串
        Console.WriteLine(strGet);
        Debug.Log(strGet); //打印接收到的字符串

    }

}

C++

extern "C" int EXPORT_API GetStr(char* str)
{
	
	string send = "12356";
	char attr[1024];
	memset(attr, 0, sizeof(attr));
	strcpy_s(attr, send.c_str());
	//memcpy(attr, s, sizeof(s));
	memcpy(str, attr, sizeof(attr));		
	return 0;

}



版权声明:本文为huahhh原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。