日期:2014-05-18  浏览次数:20753 次

请教一个C#里调用C++写的dll的问题
我打算用C#调用用C++写的一个函数,原型是:

extern "C" __declspec(dllexport) unsigned short* Trans(unsigned int);

在c#里打算变换成

  [DllImport("USBCom.dll")]
  public static extern ref ushort Trans(uint vim);

结果报错:
  Invalid token 'ref' in class, struct, or interface member declaration f:\我的文档\visual studio 2010\Projects\dlltest\dlltest\MainForm.cs 47 30 dlltest

请问错误在哪里?怎么改正?



------解决方案--------------------
探讨

引用:

public static extern ref ushort Trans(uint vim);

==>

public static extern System.IntPtr Trans(uint vim);

感谢回复,这样得到IntPtr后怎么转换成原本想要的数组?新手提问比较基础,勿见怪哈