[DllImport("OpenNetStream.dll")] public static extern int OpenSDK_Data_GetDevList(IntPtr szAccessToken, int iPageStart, int iPageSize, ref IntPtr pBuf, ref int iLength);
//其中pBuf参数,为返回的一个byte[]数据,现在要将其转换为byte[],然后在转换为string
int size = 1024; byte[] managedArray = new byte[size]; Marshal.Copy(pBuf, managedArray, 0, size);
//获得string类型 string json = System.Text.Encoding.Default.GetString(managedArray);
参考:http://stackoverflow.com/questions/5486938/c-sharp-how-to-get-byte-from-intptr
https://msdn.microsoft.com/en-us/library/system.runtime.interopservices.marshal.copy.aspx