[問題] C#使用C++ dll之回傳char

看板C_Sharp作者 (沉默而偉大的球隊)時間18年前 (2007/11/13 15:55), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串1/5 (看更多)
在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

11/14 05:12, , 1F
我不懂c++和c#,但我建議你試試 static char testStr[]="Hell
11/14 05:12, 1F
文章代碼(AID): #17ELXah_ (C_Sharp)
討論串 (同標題文章)
文章代碼(AID): #17ELXah_ (C_Sharp)