private static byte[] ReadBytesFromPtr(IntPtr intPtr, int bufferLength)
{
    var result = new byte[bufferLength];
    var count = bufferLength;
    for (var i = 0; i < bufferLength; i++)
    {
        result[i] = Marshal.ReadByte(intPtr, i);
        if (result[i] == 0)
        {
            count = i;
            break;
        }
    }
    return result.Take(count).ToArray();
}
private static void WriteBytesToPtr(IntPtr intPtr, byte[] bytes)
{
    int j;
    for (j = 0; j < bytes.Length; j++)
    {
        Marshal.WriteByte(intPtr, j, bytes[j]);
    }
    Marshal.WriteByte(intPtr, j, 0);
}

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-08-22
  • 2021-05-24
  • 2022-12-23
  • 2021-12-26
  • 2021-09-24
  • 2021-08-27
猜你喜欢
  • 2021-07-07
  • 2022-12-23
  • 2021-07-10
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案