我正在使用CRecordset从我的SQL Server获取数据。一个表存储二进制文件(pdf、odt等)。我的VisualStudio将列映射到CLongBinary字段。
如何从CLongBinary字段读取和打开文件?
我正在使用一些古老的MFC4.2版本,VisualStudio 6.0
发布于 2013-09-04 18:49:51
做这样的事情。这只会给你一个概念。我还没有测试代码。
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) ;
https://stackoverflow.com/questions/18609953
复制相似问题