Solved

CMemFile

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Tab names are off by one 5 49
NotAlone Challenge 20 70
withoutTen challenge 14 88
wordmultiple challenge 12 89
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. …
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

708 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

12 Experts available now in Live!

Get 1:1 Help Now