C#向C++编写的DLL传递字符串参数的办法
生活随笔
收集整理的這篇文章主要介紹了
C#向C++编写的DLL传递字符串参数的办法
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
使用StringBuilder,舉例:
?
C++代碼中函數定義如下:
PVPOWERFORCASTDLL_API int PVPowerForcast(SForcastInfo &_ForcastInfo,char* DatePtr,char* Dir)
?
C#代碼中這樣使用:
[DllImport("PVPowerForcastDll.dll", EntryPoint = "PVPowerForcast", CallingConvention = CallingConvention.Cdecl)]
private static extern int PVPowerForcast(ref SForcastInfo ForcastInfo, StringBuilder date,StringBuilder dir);
?
另外,如果C++中SForcastInfo 定義為struct,在C#中也要使用struct對應定義,使用class時會出現問題
轉載于:https://www.cnblogs.com/ashlee/p/3422647.html
總結
以上是生活随笔為你收集整理的C#向C++编写的DLL传递字符串参数的办法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: MVC4做网站六后台管理:6.2网站信息
- 下一篇: Android安装包apk文件在某些版本