Link to home
Start Free TrialLog in
Avatar of LittlePerson
LittlePerson

asked on

CMemFile

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);
ASKER CERTIFIED SOLUTION
Avatar of AlexFM
AlexFM

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of LittlePerson
LittlePerson

ASKER

Thanks