日期:2014-05-17  浏览次数:21095 次

调用动态库出现无法封送处理“return value”: 无效的托管/非托管类型组合。
有一个动态库函数(delphi编写的)
 [DllImport(".\\KBClientDll.dll")]
       public static extern byte[] GetDataByteArray();代码

c#代码:
int len;            
len = GetDataLen();//数据长度
byte[] vbyte = new byte[len];
vbyte = GetDataByteArray();
这样调用出现标题的错误,请问这是什么原因 要怎样调用 


------解决方案--------------------
试试:
public static extern IntPtr GetDataByteArray();

.............
 int lpByte = (int)GetDataByteArray();
            byte[] vbyte = new byte[len];
            for (int i = 0; i < len; i++)
            {
                vbyte[i]=System.Runtime.InteropServices.Marshal.PtrToStructure((IntPtr)(lpByte++),typeof(byte));
            }