private void writeToFileStream(RecEmasterHdr rec) { byte[] buffer = new byte[RecEmasterSize]; GCHandle gcHandle = GCHandle.Alloc(buffer, GCHandleType.Pinned); Marshal.StructureToPtr(rec, gcHandle.AddrOfPinnedObject(), true); metastockGlobals.Fs2.Write(buffer, 0, RecEmasterSize); gcHandle.Free(); }
private void readFromFileStream(ref RecEmasterHdr rec) { byte[] buffer = new byte[RecEmasterSize]; int offset = 0; while (offset < buffer.Length) { offset += metastockGlobals.Fs2.Read(buffer, offset, buffer.Length - offset); } GCHandle gcHandle = GCHandle.Alloc(buffer, GCHandleType.Pinned); rec = (RecEmasterHdr)Marshal.PtrToStructure(gcHandle.AddrOfPinnedObject(), typeof(RecEmasterHdr)); 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); }