不同的字符集与dllimport的多个PARAMS [英] different charset for multiple params with dllimport

查看:168
本文介绍了不同的字符集与dllimport的多个PARAMS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能为独立PARAMS声明不同的字符集选项



继承人我的意思?



  [dllimport的(my.dll,字符集= charset.Ansi)] 
无效MYFUNC(字符串CharPtrInCPP,StringBuilder的WCh​​arPtrInCPP);



问题是C ++函数需要一个char *的文件名和WCHAR *为收到的数据回来...



在C ++:

 无效myfuncImpl(CHAR *文件名,WCHAR *缓冲区,INT LEN); 
//另一种方法,MYFUNC,包装此


解决方案

前面已经指出的那样,你应该能够为各个参数指定的MarshalAs。另一种方法是指定一个默认字符集的类型,然后指定鹤立鸡群编组。例如,

 函数[DllImport(my.dll,字符集= CharSet.Unicode)] 
无效MYFUNC( [的MarshalAs(UnmanagedType.LPStr)]字符串的文件名,
StringBuilder的缓冲,INT LEN);


Is it possible to declare different charset options for seperate params?

heres what i mean:

[dllimport("my.dll", charset = charset.Ansi)]
void myfunc(string CharPtrInCPP, StringBuilder WCharPtrInCPP);

the problem is the c++ function takes a char* for the filename and a wchar* for the data recieved back...

in c++:

void myfuncImpl(char *filename, WCHAR *buffer, int len); 
//another method, myfunc, wraps this

解决方案

As already pointed out, you should be able to specify MarshalAs for each parameter. Another way would be to specify a default character set type and then specify the marshalling for the odd one out. For example,

  [DllImport("my.dll", CharSet=CharSet.Unicode)]
  void myfunc( [MarshalAs( UnmanagedType.LPStr )] String filename, 
               StringBuilder buffer, int len );

这篇关于不同的字符集与dllimport的多个PARAMS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆