I didn't see anything in forums posted on this yet. My goal is to read data from a Stream^ object in varying lengths of bytes, display the data in user-editable textboxes, then finally be able to save that data back to the Stream^ (which will of course be written back to the file after synchronizing). I'm using C++/.Net to do this in VSExpress 2005. Thanks to Faldrax, I understand how to get the datastream to be accessible to the whole form now without errors. My trouble now is with line 65. I get a C2664 error for offending the compiler's array with my request for a string. I can't seem to get around the textbox (either masked or not) inherent property of String^, yet the data being read is in array^ format. I've tried using both the regular textbox and the masked textbox, but both fail in my implementation of them. For decimal values, the masks are set for "###", and the one masked box that takes letter or numbers is masked "CCCCCCC". Even using Convert::ToString() doesn't work for me. Is there a different way to read the data from the stream? Or at least an easier way to get the types to be compatible while sticking with the .NET? Any help would be appreciated.
Hi,
my thoughts would be to have an array to read to/from for the reader/writer, and then to convert from this array to / from string^.
1 2 3 4 5 6
Const int MaxChars = 100; //Chose the max value you will want to read or write here
BinaryReader^ reader = gcnew BinaryReader(GameStream);
BinaryWriter^ writer = gcnew BinaryWriter(GameStream);
array<Char>^ buf = gcnew array<Char>(MaxChars>;
reader->Read(buf,0,7);
//Now convert to String^ and put into your textbox
Note that the Read method of the BinaryReader has the form
Read(Dest, Start, Count)
where Dest is the array, Start is the position in the ARRAY to PUT the data read, and Count is the number of chars to read, so you probably always want that second parameter to be zero.
I tried your suggestion, but I get an error upon trying to compile. error C2664 (or C2440): 'int System::IO::BinaryReader::Read(cli::array<Type,dimension> ^,int,int)' : cannot convert parameter 1 from 'cli::array<Type> ^' to 'cli::array<Type,dimension> ^'
I tried jumbling things around all things I tried resulted in the same error or 'cannot convert from 'cli::array<Type,dimension> ^' to 'cli::array<Type,dimension> ^'. WEIRD!! Is my IDE buggy??
sorry, forgot to post code. I want to declare the array in line 5 so that it will be accessible throughout the form so that eventually I can make an accessible function out of the array for read/write operations with parameters of offset in FileStream, count of bytes to read/write to that stream.
I double checked and what the help files and error messages have led me to understand is that it needs to be declared as a 'wchar-t' type. In my line 5 of my declaration of an array I noticed that I didn't have the left and right sides matching. I declared it 'wchar_t' but on the right it was only 'char' so after changing that it now appears to compile correctly. I also had to correct the reader->Read (line65) because it was apparently trying to seek to that posistion in my ARRAY an not in my FileStream so I added a line to Seek the FileStream first then all came together well. Thanks for the help again Faldrax :-)
Now onto the beast of getting it to read multiple fields as a function....