[英]Can file pointer change during the process of write or read of a CFile object
[英]How can I read a CLongBinary field from my database and write it into a CFile object?
即時通訊使用CRecordset從我的SQL Server獲取數據。 一個表存儲一個二進制文件(pdf,odt等)。 我的VisualStudio將列映射到CLongBinary字段。
如何從CLongBinary字段讀取和打開文件?
即時通訊使用的是MFC, VisualStudio 6.0的某些較早版本4.2
做這樣的事情。 這只會給您一個想法。 我還沒有測試代碼。
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) ;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.