Microsoft Personal Support Center Home   All Products  |   Support  |   Search  |   microsoft.com Home  
Microsoft
  Support Home  |   Search Support  |   Browse  |   Products  |   Downloads  |   Contact Us  |   Site Help  |

HOWTO: Determine the Version of a Microsoft Word Document

The information in this article applies to:
  • Microsoft Visual C++, 32-bit Editions, versions 2.0, 2.1, 2.2, 4.0, 4.1, 4.2, 5.0
  • Microsoft Word 97 for Windows
  • Microsoft Word for Windows 95, version 7.0
  • Microsoft Word for Windows, version 6.0

SUMMARY

This article shows you how to determine the version of a Microsoft Word document.

MORE INFORMATION

Microsoft Word saves its data in an OLE Compound file that is made up of streams and storages. In particular, it creates a data stream called "WordDocument" where it saves the contents and a special header called a "FIB" (File information block). This header contains information about the various attributes of the file that are documented in the MSDN as well as the version of Microsoft Word that saved the document. The following Microsoft Visual C++ code demonstrates how to open and read the WordDocument stream, and return the version number.

Sample Code

   // Word's File-Information-Block (FIB) structure...
   typedef struct _fib {
      short magicNumber;
      // Word 6.0: 0xA5DC
      // Word 7.0 (95): 0xA5DC
      // Word 8.0 (97): 0xA5EC

      short version;   // >= 101 for Word 6.0 and higher...
      // Word 6.0: 101
      // Word 7.0 (95): 104
      // Word 8.0 (97): 105
   } FIB, *LPFIB;


   //* WordVersionFromFile()
******************************************************
   //* Returns
   //*        6 for Word 6.0
   //*        7 for Word 7.0 (95)
   //*        8 for Word 8.0 (97)
   //*        Negative if an error occurs...
   //****************************************************
   int WordVersionFromFile(char *filename) {
      // Translate filename to UNICODE...
      WCHAR wcFilename[1024];
      int i = mbstowcs(wcFilename, filename, strlen(filename));
      wcFilename[i] = 0;

      IStorage *pStorage;
      HRESULT hr;
      FIB fib;

      // Open document as an OLE compound document...
      hr = ::StgOpenStorage(wcFilename, NULL, STGM_READ |
STGM_SHARE_EXCLUSIVE, NULL, 0, &pStorage);

      if(!FAILED(hr)) {
         // Open the data-stream where Word stores the data...
         IStream *pStream;
         hr = pStorage->OpenStream(L"WordDocument", NULL, STGM_READ |
STGM_SHARE_EXCLUSIVE, 0, &pStream);

         if(!FAILED(hr)) {
            // Read relevant FIB information...
            DWORD dwCount; // bytes read...
            pStream->Read(&fib, sizeof(FIB), &dwCount);

            // Let go of our IStream pointer...
            pStream->Release();
         }
         else return -2;

         // Let go of our IStorage pointer...
         pStorage->Release();
      }
      else return -1;

      // Determine version to return...
      if(fib.version < 101) return fib.version;

      switch(fib.version) {
         case 101: return 6;
         case 103: // fall-through...
         case 104: return 7;
         case 105: return 8;
         default: return 8; // Default, return the latest
      }
   }

REFERENCES

For more information about OLE Compound files and Structured Storage, search the MSDN or Microsoft Visual C++ online help on "Structured Storage."

For more information about the Microsoft Word file format, and/or the FIB structure, search the MSDN for "Microsoft Word 97 Binary File Format."

Additional query words: word97 winword

Keywords          : kbcode
Version           : WINDOWS:6.0,7.0,97; WINNT:2.0,2.1,2.2,4.0,4.1,4.2,5.0
Platform          : WINDOWS winnt
Issue type        : kbhowto


Last Reviewed: September 23, 1997
© 1999 Microsoft Corporation. All rights reserved. Terms of Use.


Article ID: Q174140

Last Reviewed:
September 23, 1997

Provided by Support Online from Microsoft Product Support Services.


Did the information in this article help answer your question?

Yes
No
Did not apply

Please provide additional comments on this article.
(255 character max)