看板 C_Sharp 關於我們 聯絡資訊
※ 引述《spursGM (沉默而偉大的球隊)》之銘言: : 在C++ dll 程式概述如下: : char * test(void) : { : char testStr[]="Hello World!"; : return *testStr; : } 這個寫法就算在 C/C++ 都是錯的呀 @_@ 你的 return type 是 char*, 可是你卻 return char 就算你是要 return testStr 的字串好了 (即 testStr), 可是該字串的內容是配置在 test 的 call stack中, 一但 return 就不該使用 : static extern byte[] test(void); 在 .NET 中, char* 不能直接轉成 byte[], 但 string 可以, 所以可以用兩種寫法 1. static extern IntPtr test(void); 再用 Marshal.PtrToStringXXX (XXX可以是Ansi,Unicode或Auto) 跟 IntPtr 有關的處理幾乎都可以在 Marshal 找到~ 2. static extern String test(void); 依情況使用, 不過 output 東西出來通常都建議用 IntPtr .. -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 220.139.144.20