C# IntPtr转换为Byte[]


[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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM