作者leicheong (睡魔)
看板C_Sharp
标题Re: [问题] C#使用C++ dll之回传char
时间Tue Nov 13 17:35:15 2007
※ 引述《spursGM (沉默而伟大的球队)》之铭言:
: 在C++ dll 程式概述如下:
: char * test(void)
: {
: char testStr[]="Hello World!";
: return *testStr;
: }
: 在C#宣告如下:
: static extern byte[] test(void);
: 在C#使用如下:
: try
: {
: byte[] output = test();
: String outputStr = System.Text.Encoding.Default.GetString(output);
: label1.Text = outputStr;
: }
: catch (Exception ex)
: {
: label1.Text = ex.ToString();
: }
C++ 不应在export时回传void *类型. (pointer没有锁定, 记忆体拥有权
也不清楚...)
请把回传的变数宣告成如void test(char * strRet)这样...
另外在C#的宣告应改成: void test(System.Text.StringBuilder strRet)...
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 202.134.126.84