1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > C#向C++编写的DLL传递字符串参数的办法

C#向C++编写的DLL传递字符串参数的办法

时间:2022-03-12 16:10:36

相关推荐

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时会出现问题

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。