What does Material.dat contain? Is it a single protocol buffer or a series of protocol buffers?
On Mon, Apr 10, 2017 at 11:38 PM, revanth rao <[email protected]> wrote: > down votefavorite > <http://stackoverflow.com/questions/43336683/how-to-store-binary-file-data-in-structure#> > > Hi all, > > I have a file shown below(Material.dat) which is binary file , I want to > read data from the file and put in the structure(Header) for that I have > used GetRecord() function. > > HANDLE hFileMac = ::CreateFile(_T("Material.dat"), GENERIC_READ, > FILE_SHARE_READ, NULL, > OPEN_EXISTING, FALSE ? FILE_FLAG_SEQUENTIAL_SCAN : FILE_ATTRIBUTE_NORMAL, > NULL); > > if (!(hFileMac != INVALID_HANDLE_VALUE)) > { > return; > } > > GetRecord(hFileMac, RECORD_NUMBER, sizeof(Header), reinterpret_cast<void > *>(&Header)); > > My doubt is what to pass as a record number to Get Record() function? > > GetRecord(hFileMac, RECORD_NUMBER, sizeof(Header), > reinterpret_cast(&Header)); > > int GetRecord(HANDLE hFile, int RecordNumber, int RecordSize, void > *RecordPtr){ > if (RecordNumber <= 0 || RecordSize <= 0) > return 1; > LONG lOffset = (RecordNumber - 1) * RecordSize; > > if (SetFilePointer(hFile, lOffset, NULL, FILE_BEGIN) == 0xFFFFFFFF) > return 2; > > DWORD dwSize; > > if (::ReadFile(hFile, RecordPtr, RecordSize, &dwSize, NULL) == 0) > return 3; > > return 0;} > > -- > You received this message because you are subscribed to the Google Groups > "Protocol Buffers" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at https://groups.google.com/group/protobuf. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Protocol Buffers" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/protobuf. For more options, visit https://groups.google.com/d/optout.
