日期:2014-05-19  浏览次数:20817 次

如何将byte[]传入到VC写的函数里?
VC原型:
  unsigned   char   *   EncryptData(   unsigned   char   *   )
c#里将byte[]传入到VC写的函数EncryptData中,处理后再返回?

------解决方案--------------------
//参考如下代码:
[DllImport( "your.dll ")]
public static extern IntPtr EncryptData(IntPtr ABuffer);

private void button1_Click(object sender, EventArgs e)
{
byte[] vBufferSrc = new byte[1024];
IntPtr vAddressSrc = Marshal.UnsafeAddrOfPinnedArrayElement(vBuffer, 0);
IntPtr vAddressDesc = EncryptData(vAddressSrc);
byte[] vBufferDesc = new byte[1024];
Marshal.Copy(vAddressDesc, vBufferDesc, 0, 1024);
}