c#调用c++封装dll 参数为字符串输出函数的解决办法

来源:互联网 发布:纸箱厂软件 编辑:程序博客网 时间:2024/05/17 07:58

有时候c#需要调用 c++dll 参数为字符串且为输出的函数  。

如: c++ dll函数如下:

int test(char _OUT *str);

str为输出。


c#中调用如下:

 [DllImport("test.dll", CallingConvention = CallingConvention.Cdecl)]        public extern static int test(StringBuilder str);

注意一定要用StringBuilder 不能用String

  public string test()        {            string list;            StringBuilder lp;                   lp = new StringBuilder(100);            int ret=test(lp);            list = lp.ToString();            return list;        }


0 0