简体   繁体   中英

How can I read a CLongBinary field from my database and write it into a CFile object?

im using a CRecordset to get data from my SQL Server. One table stores a binary file (pdf, odt, ...). My VisualStudio maps the columns to a CLongBinary field.

How can I read and open the file from the CLongBinary field?

im using some ancient version 4.2 of MFC, VisualStudio 6.0

Do something like this. This will just give you an idea. I haven't tested the code.

CLongBinary myfield ;

... retrive myfield from database here


BYTE *dataptr = (BYTE*)GlobalLock(myfield.m_hData) ;

// now dataptr points to your raw data, and myfield.m_dwDataLength is the length of that data

CString tempname = ... create temporary filename somewhere
CFile myfile ;
myfile.Open(tempfilename, CFile::modeCreate|CFile::modeWrite);
myfile.Write(dataptr, myfield.m_dwDataLength) ,
myfile.Close() ;
GlobalUnlock(myfield.m_hData) ;

ShellExecute(NULL, _T("open"), tempfilename, NULL, NULL, SW_SHOW) ;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM