作者spursGM (沉默而伟大的球队)
看板C_Sharp
标题[问题] C#使用C++ dll之回传char
时间Tue Nov 13 15:55:15 2007
在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++ DLL回传个字串给C#吃
呼叫DLL方面我省篇幅先略掉 确定是没问题的
因为我用int test(void) 可成功
但是char*/byte[]会有问题
"System.NotSupportedException......" 囧
不知道到哪个环节问题需要更改
感谢大大们指教喔<(_ _)>
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 59.115.235.15
1F:推 pttlz:我不懂c++和c#,但我建议你试试 static char testStr[]="Hell 11/14 05:12