public static TestStruct FromBinaryReaderBlock(BinaryReader br)
{ //Read byte array byte[] buff = br.ReadBytes(Marshal.SizeOf(typeof(TestStruct))); ?
//Make sure that the Garbage Collector doesn't move our buffer ?
GCHandle handle = GCHandle.Alloc(buff, GCHandleType.Pinned); ?
//Marshal the bytes TestStruct s = (TestStruct)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(TestStruct)); ?
handle.Free();//Give control of the buffer back to the GC ?
return s;
}
想用這段程序,但結(jié)構(gòu)是直接指定的,如果結(jié)構(gòu)是個(gè)變量應(yīng)該怎么寫?
1 回答

慕后森
TA貢獻(xiàn)1802條經(jīng)驗(yàn) 獲得超5個(gè)贊
什么意思,沒看懂,你的意思是想:TestStruct ts=FromBinaryReaderBlock(br);想這么用?
- 1 回答
- 0 關(guān)注
- 305 瀏覽
添加回答
舉報(bào)
0/150
提交
取消