当前位置:编程学习 > C#/ASP.NET >>

c# 调用c++ dll 时 wchar_t 应该怎么对应


c# 在调用这个的时候应该怎么写呢
extern "C" __declspec(dllexport) int mtinit(
wchar_t *path_to_profile
);
 里面这个参数应该怎么去对应。 --------------------编程问答-------------------- public static extern int mtinit(
stringbuilder path_to_profile
);
注意编码格式选成Unicode就可以了,没有做测试
有问题继续问 --------------------编程问答--------------------
引用 楼主 kppig30372050 的回复:
c# 在调用这个的时候应该怎么写呢
extern "C" __declspec(dllexport) int mtinit(
wchar_t *path_to_profile
);
 里面这个参数应该怎么去对应。


这个函数设计得不合理,有两种方法改进:
1、增加 size 参数,用来指定 wchar_t* 的实际长度;
2、可以用 wchar_t path_to_profile[255] 指定它的长度。

如果用的是第二种方法,可以在 c# 里使用 MarshalAs 指定 path_to_profile 参数为 StringBuffer 类型,并且 SizeConst=255。
补充:.NET技术 ,  .NET Framework
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,