vbpslogo2.gif (19593 bytes)
Brad's VB-32 Programs & Samples

Posted: 12/08/99, last update: 12/08/99


GfxFromFrx: How to extract graphics from VB binary property files

The VB FRX binary files that have been around since the early days (< VB3?) are use to hold large property information assigned in designtime to Forms, and all controls contained with the Form, a property overflow bag if you will. Now we also have even more binary files that provide the same service for User Controls (.CTX), Property Pages (.PGX), User Documents (.DOX), and Active Designer projects (.DSX). Among the various property information stored in these files are graphics, which can include bitmaps (.BMP and .DIB), GIFs, JPEGs (.JPG), Metafiles (.WMF, .EMF), cursors (.CUR), and icons (.ICO). But once a graphic is stored in a binary file, how do you get it out? Well, it's a little tricky, but doable...

We know that data stored in these binary files is accessed via the binary file offsets assigned to the properties of the accompanying module (i.e. [Form.]Picture = "Form1.frx":0000), but what if the modules aren't available? Here's the most important info: the original graphic files themselves are stored in their entirety in VB binary property files. Very helpful. VB also adds binary header information before each graphic file in the binary file, including the length of the graphic file itself. But since this graphic file header information has changed as VB itself has changed, things get more difficult. The only definitive way to determine exactly where the graphic file starts and ends, is to verify the graphic file's format. This entails reading the bits of the binary file and comparing it to the known formats of the graphic file formats mentioned above. A little arduous...

So here's what the demo does: opens the specified binary property file and loads it into a byte array, walks the byte array looking for known VB binary header formats. If a known header format is found, then the length of the graphic file is obtained from the header, the graphic file's format is determined by reading its bytes, and the graphic file is stored in its own byte array. The code keeps walking the binary file's bits until no more graphic file headers are found. Property data other than graphic files (text, etc.) is accumulated and stored in its own byte array. Once the graphic files are in a byte array, they can either be viewed in the demo, and/or saved to file. Pretty darned handy.

Download gfxfromfrx.zip (12kb)