Microsoft KB Archive/185282

= PRB: CRichEditView, AppWizard View-Based Apps and Compound Files =

Article ID: 185282

Article Last Modified on 11/21/2006

-

APPLIES TO

 Microsoft Foundation Class Library 4.2, when used with:  Microsoft Visual C++ 4.0 Standard Edition

 Microsoft Visual C++ 4.1 Subscription

 Microsoft Visual C++ 4.2 Enterprise Edition

 Microsoft Visual C++ 4.2 Professional Edition</li></ul>

 Microsoft Visual C++ 5.0 Enterprise Edition</li></ul>

 Microsoft Visual C++ 5.0 Professional Edition</li></ul>

 Microsoft Visual C++ 6.0 Enterprise Edition</li></ul>

 Microsoft Visual C++ 6.0 Professional Edition</li></ul>

 Microsoft Visual C++ 6.0 Standard Edition</li></ul> </li></ul>

-

<div class="notice_section">

This article was previously published under Q185282

<div class="symptoms_section">

SYMPTOMS
You can experience two problems when you choose compound file support for an MFC application based on CRichEditView. The first problem also occurs with MFC applications based on other view classes (eg. CView, CEditView, and so on):

<ol>  The document's Serialize function will pass in what seems to be an invalid CArchive object. For example, if you place the following code in the Serialize function of an application that includes compound file support, nothing will appear in the message box: CFile *pFile = ar.GetFile; AfxMessageBox(pFile->GetFilePath); </li> When you save your document to a file, Word or WordPad will not be able to correctly read it.</li></ol>

These problems can arise when you use the AppWizard to create single document interface (SDI) or multiple document interface (MDI) applications, and when you enable compound file support (in Step 3 of the AppWizard). Typically, you see a call to EnableCompoundFile in the constructor of your CDocument-derived class when this problem occurs.

<div class="cause_section">

CAUSE

 * 1) The CArchive object passed in by the document's Serialize function is fine. The m_strFileName (file name) member of CArchive is empty because the compound file support is enabled in the application. The CArchive object is associated with a COleStreamFile object, which is a wrapper for a stream object (it supports the IStream interface). This stream object represents only a part of the compound file, and so the file name field is empty.
 * 2) When you enable compound files in a CrichEditView-based application, the Rich Text Format (RTF) stream provided is stored in a compound file layout, which neither Word nor WordPad understands. When you try to display a compound file with either Word or Wordpad, the files display as plain text.

<div class="resolution_section">

RESOLUTION

 * 1) If you want to use compound files, your code must not try to get information that isn't defined for a compound file from the CArchive object.
 * 2) If you want your files to be compatible with Word and WordPad, don't choose compound file support. Word and WordPad can understand the RTF stream stored in a flat file.

<div class="status_section">

STATUS
This behavior is by design.

<div class="moreinformation_section">

MORE INFORMATION
To reproduce the perceived problem of an invalid CArchive object, perform the following steps:


 * 1) Use the MFC AppWizard (exe) to generate an SDI or MDI application with all the defaults, except in Step 3.

In Step 3, select any of the following options: Container, Mini-server, Full-server, or Both container and server. Then select "Yes" in response to "Would you like support for compound files?".
 * 1) Finish AppWizard, and put a break point at the beginning of the document's Serialize function.
 * 2) Build a debug version. Run the application, and save a file.
 * 3) At the breakpoint, do a QuickWatch of the ar (CArchive) object. Notice that ar.m_strFileName is empty. The same thing occurs when opening a file.

<div class="references_section">