Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

CMemFile

Posted on 2003-11-26
2
Medium Priority
?
279 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 48

Accepted Solution

by:
AlexFM earned 300 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Ready to get certified? Check out some courses that help you prepare for third-party exams.
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.
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

730 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