Solved

CMemFile

Posted on 2003-11-26
2
268 Views
Last Modified: 2013-11-20
Hi

I am trying to read a BLOB from a mysql database into a CMemFile and then read the
contents of the CMemFile.

This is my code.............

// deviceDB is the recordset derived class that has attribute m_cal_file declared as CLongBinary

CMemFile memFile;
LPSTR buffer = (LPSTR) GlobalLock(deviceDB.m_cal_file.m_hData);
memFile.WriteHuge(buffer, deviceDB.m_cal_file.m_dwDataLength);
GlobalUnlock(deviceDB.m_cal_file.m_hData);

char buf[10];
DWORD dwBytesRemaining = memFile.GetLength();

CString msg;
msg.Format("%d", dwBytesRemaining);
AfxMessageBox(msg);                                        // comes out as 98

CString text;
CString strTmp;

while(dwBytesRemaining) {

                UINT nBytesRead = memFile.Read(buf, sizeof(buf));
      dwBytesRemaining -= nBytesRead;
      strTmp = text;
      text.Format("%s%s", strTmp, (LPCSTR)buf);

      msg.Format("%d", nBytesRead);
      AfxMessageBox(msg);                                                   // always comes out as being 0 - zero!!!
}
                  
Obviously I am getting stuck in an infinite loop as the number of bytes read is never anything but zero.

How can the CMemFile tell me it has 98 bytes of data and then reads none at a time?

Can anyone help??

Thanks in advance

LittlePerson
AfxMessageBox(text);
0
Comment
Question by:LittlePerson
2 Comments
 
LVL 48

Accepted Solution

by:
AlexFM earned 75 total points
ID: 9825102
Try to set current position in the memFile using SeekToBegin() before the loop.
0
 

Author Comment

by:LittlePerson
ID: 9825119
Thanks
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
WinWaitActive parameters 12 31
countEvens challenge 2 113
post4 challenge 28 113
Thin secure Windows 10 5 107
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question