c#中调用c语言编写的动态链接库,其中一个函数的声明是fun(char *string, int *index)

现在需要c#调用此函数,将经过fun修改值后的参数string,index带出,请问如何在c#中声明对应的函数实现此功能,我知道参数只有char *string可以,只有int *index也可以,两者都作为参数,运行时就会报错

估计是你在C#中声明的时候,类型写错了,在编译期间有些错误时发现不了的,必须等运行时才能报错,这也是这些个COM组件、标准dll的麻烦之处 。。。

试试这个:
[DllImport("xxx.dll")]
public extern static void fun( string strParam, IntPtr index );

为了更直观的使用(近C的语法),你可以使用unsafe关键字 ~~~ 查查MSDN吧~~
温馨提示:内容为网友见解,仅供参考
第1个回答  2012-05-24
DllImport("xxx.dll")]
public extern static void fun( StringBuilder strParam, ref int index );
第2个回答  2012-05-24
DllImport("***.dll")]
public static extern void fun(string str,ref int index);
第3个回答  2012-05-25
注意看ICECOOBE的回答.领悟一下
相似回答