c# 調用 c++的 dll 中關於 char*傳入傳出參數


c++的dll接口原型為:int CheckSN(const char* InfoList, char* msg);

c#調用轉換為:

[DllImport("sncplusInterface.dll", EntryPoint = "CheckSN", ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]
public static extern int CheckSN(string InfoList, StringBuilder msg);

調用為:

StringBuilder chOutMsg = new StringBuilder(1024);

CheckSN(chData, chOutMsg/*ref chOutMsg*/);

string str = chOutMsg.ToString();

用ref 或 out關鍵字會crash

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM