當(dāng)前位置:
首頁(yè) >
C#向C++编写的DLL传递字符串参数的办法
發(fā)布時(shí)間:2025/5/22
37
豆豆
生活随笔
收集整理的這篇文章主要介紹了
C#向C++编写的DLL传递字符串参数的办法
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
使用StringBuilder,舉例:
?
C++代碼中函數(shù)定義如下:
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對(duì)應(yīng)定義,使用class時(shí)會(huì)出現(xiàn)問(wèn)題
轉(zhuǎn)載于:https://www.cnblogs.com/ashlee/p/3422647.html
總結(jié)
以上是生活随笔為你收集整理的C#向C++编写的DLL传递字符串参数的办法的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: MVC4做网站六后台管理:6.2网站信息
- 下一篇: C#如何把日期转成YYYYMMDDHHM