[問題] 獲得MFC dll裡的CString資訊

看板C_Sharp作者 (幹!我是肌董)時間9年前 (2015/07/08 13:51), 9年前編輯推噓0(001)
留言1則, 1人參與, 最新討論串1/1
各位先進好!! 基本C#讀取MFC(C++)的dll功能已大致了解 但現在碰到了CString的問題... 我利用MFC所編譯的dll檔: _EXTERN_C_ CString testCString() { CString str = _T("Show CString"); return str; } 希望能夠過C#來獲得CString內容 由於網路上說CString並不是C#裡有定義的型態 所以必須透過一些方式來讀取其內容 我照著在StackOverFlow上此篇的方式 h ttp://ppt.cc/AmZ2Y 透過System.Text.StringBuilder來進行編寫 在類別(SdkFunction)內導入dll檔的內容: [DllImport("MFCLibrary.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl)] public extern static System.Text.StringBuilder testCString(); 在主程式呼叫的內容: System.Text.StringBuilder testCString; //定義變數 testCString = SdkFunction.testCString(); //將SDK的內容讀入 Console.WriteLine("testCString: " + testCString.ToString()); Console.ReadLine(); 結果還是無法成功 程式會自行結束T_T 希望各位熱心的版友能提供一點意見! 謝謝您!! -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 211.72.212.97 ※ 文章網址: https://www.ptt.cc/bbs/C_Sharp/M.1436334686.A.C1B.html ※ 編輯: srxrrr (211.72.212.97), 07/08/2015 13:52:57 ※ 編輯: srxrrr (211.72.212.97), 07/08/2015 14:14:25

07/10 10:30, , 1F
簡單一點編一個C++的dll呼叫MFC 再用C#呼叫
07/10 10:30, 1F
感謝f大的回覆! 不好意思再請問一下 您說的這個方式 有沒有什麼關鍵字 或文章可參考@@? 謝謝!! ※ 編輯: srxrrr (123.193.54.226), 07/10/2015 18:58:38
文章代碼(AID): #1LdBfUmR (C_Sharp)