tags:

views:

233

answers:

3

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  A: 

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.

Tony Toews
+1  A: 

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.

crimson13
Not the ideal solution, but I've found no better answer yet.
crimson13
Are we sure the OLE wrapper is always the same?
David-W-Fenton
For MS Access 2007 I tested a great variety in file types (gif, bmp, jpg, tiff, png, avi. mpg, swf, ...) and the format 'holds'. I unfortunately have no easy access to other MS database systems, so I've not yet been able to verify them.
crimson13
+1  A: 

I'm reposting my comment as an answer:

Don't use OLE fields, just use regular BLOBs.

David-W-Fenton
I would if I could :-)Unfortunately I don't have control over that part of the problem (other people/software writes the database, I just have to read it).
crimson13