private void writeToFileStream(RecMasterHdr rec) { byte[] buffer = new byte[RecMasterSize]; GCHandle gcHandle = GCHandle.Alloc(buffer, GCHandleType.Pinned); Marshal.StructureToPtr(rec, gcHandle.AddrOfPinnedObject(), true); metastockGlobals.Fs1.Write(buffer, 0, RecMasterSize); gcHandle.Free(); }
private void readFromFileStream(ref RecMasterHdr rec) { byte[] buffer = new byte[RecMasterSize]; int offset = 0; while (offset < buffer.Length) { offset += metastockGlobals.Fs1.Read(buffer, offset, buffer.Length - offset); } GCHandle gcHandle = GCHandle.Alloc(buffer, GCHandleType.Pinned); rec = (RecMasterHdr)Marshal.PtrToStructure(gcHandle.AddrOfPinnedObject(), typeof(RecMasterHdr)); gcHandle.Free(); }
public DirHdr(MsGlobals msglobal) { metastockGlobals = msglobal; masterHeader = new RecMasterHdr(); emasterHeader = new RecEmasterHdr(); xmasterHeader = new RecXmasterHdr(); if (File.Exists(metastockGlobals.Fs1Pth) && metastockGlobals.Fs1 != null) { readFromFileStream(ref masterHeader); } if (File.Exists(metastockGlobals.Fs2Pth) && metastockGlobals.Fs2 != null) { readFromFileStream(ref emasterHeader); } if (!File.Exists(metastockGlobals.Fs3Pth) || metastockGlobals.Fs3 == null) { return; } readFromFileStream(ref xmasterHeader); }