gpt4 book ai didi

c++ - 如何从数据库中读取 CLongBinary 字段并将其写入 CFile 对象?

转载 作者:搜寻专家 更新时间:2023-10-31 01:07:57 26 4
gpt4 key购买 nike

我正在使用 CRecordset 从我的 SQL Server 获取数据。一张表存储一个二进制文件(pdf、odt、...)。我的 VisualStudio 将列映射到 CLongBinary 字段。

如何从 CLongBinary 字段读取和打开文件?

我正在使用 MFC 的一些古老版本 4.2VisualStudio 6.0

最佳答案

做这样的事情。这只会给你一个想法。我还没有测试代码。

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) ;

关于c++ - 如何从数据库中读取 CLongBinary 字段并将其写入 CFile 对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18609953/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com