Problem reading a stream in .NET

Matt_KeyesMatt_Keyes Member Posts: 23
i've read the thread here:

http://www.mibuso.com/forum/viewtopic.p ... et&start=0

that uses this project here:

http://www.mibuso.com/dlinfo.asp?FileID=776

however, i don't think it really works.

When i pass an Outstream to a C# component, the loop that reads the stream looks like this (in the object from the link above):
public bool LoadFromNavision([In, MarshalAs(UnmanagedType.AsAny)] object COMStream, string fileName)
		{
			bool flag1 = true;
			Stream stream1 = new MemoryStream();
			byte[] buffer1 = new byte[0xafc8];
			this.rwBytes = Marshal.AllocHGlobal(4);
			IStream COMStream1 = COMStream as IStream;
			FileStream writer = new FileStream(fileName, FileMode.CreateNew);
			int _rwBytes = 0;

			do
			{
				COMStream1.Read(buffer1, 0xafc8, this.rwBytes);
				_rwBytes = Marshal.ReadInt32(this.rwBytes);
				writer.Write(buffer1, 0, _rwBytes);
			}
			while (_rwBytes > 0);
			Marshal.FreeHGlobal(this.rwBytes);
			writer.Close();
			writer.Dispose();
			return flag1;
		}

During the read loop, it doesn't matter that 45000 is passed into the IStream read function (COMStream1.Read) - it always returns the length of the stream in the IntPtr. Thus, while(_rwBytes > 0) always returns true (and thus it crashes). i can take it out of the loop, and it works as long as the stream is shorter than 45000 bytes.

Anyone had a similar experiences or have a fix?
Sign In or Register to comment.