问题
I have a C++ application that needs to support binary database content (images, etc). When using MS Access or MS SQL Server this data is wrapped inside an OLE object. How do I strip this OLE header information? Note that I can't just look for the beginning of a specific tag as the content can be png, jpg and a whole heap of other formats. Should I use something like COleDataObject?
回答1:
Using MS Access 2007 (I need to test other MS databases) the format seems to be:
84 bytes
file name + \0
full path + \0
5 bytes + [2] bytes (the third byte of those five bytes)
temp path + \0
4 bytes
actual data (if not using a link to the file)
So far I simply parse and strip the part before the actual data, but I'm still wondering if there's no way to use something like COleDataSource to help parse this information more robustly.
Also note that this format only applies for generic content (start tag 0x15 0x1c 0x32). When using bitmaps (start tag 0x15 0x1c 0x2f) there's a fixed offset of 78 bytes and when using PowerPoint (start tag 0x15 0x1c 0x34) there's a fixed offset of 95 bytes.
回答2:
See Stephen Lebans OleToDisk code. Note that the code is in VBA. Also I don't know that this will work as is in SQL Server.
回答3:
I'm reposting my comment as an answer:
Don't use OLE fields, just use regular BLOBs.
来源:https://stackoverflow.com/questions/2874403/strip-ole-header-information-ms-access-sql-server