Solved

CMemFile

Posted on 2003-11-26
2
261 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

862 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now