You are currently offline, waiting for your internet to reconnect

FIX: 'Read-Only' Warning When Adding an MFC Class From a Type Library

This article was previously published under Q311408
This article has been archived. It is offered "as is" and will no longer be updated.
Symptoms
When you add a COM wrapper class to a Microsoft Foundation Classes (MFC) project by using a type library with the Microsoft Visual Studio .NET Wizard, you may receive an error message if you browse to the type library file instead of using the library that is already registered in the registry. If the type library file has been marked Read-Only on disk and you browse to that type library by using the wizard, you receive the following error message, and adding the class fails:
Cannot save the file. The file exists and is marked Read-Only. Save the file with another file name or to another location.
Resolution
To work around this problem, do any of the following:
  • Type the location of the type library that you want to use directly into the Location text box, rather than browsing to the file. The problem is with the code that uses the dialog box for the Browse operation, and not the actual import.-or-

  • Make sure that the type library from which you need to add classes is already registered, and then add the class from the registry instead of from a file. To do this, follow these steps:
    1. On the Project menu, select Add Class.
    2. Select MFC Class from Typelib from the list of templates.
    3. For Add Class from, select Registry.
    4. In the list of available type libraries, find the friendly name for the type library from which you want to add classes.
    5. From the list of interfaces in that type library, select the classes for which you want to add wrappers.
    6. Click Finish.
    -or-

  • Change the file permissions for the type library so that the file is not marked Read-Only.The Add Class From TypeLib Wizard does not actually change the type library. This workaround may be useful in cases in which it is not feasible to register the type library. Note, however, that modifying file permissions can leave the type library open to accidental changes, and should be done carefully.
Status
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article. This bug was corrected in Microsoft Visual C++ .NET (2003).
More information

Steps to Reproduce Behavior

  1. On the Project menu, select Add Class.
  2. Select MFC Class from Typelib from the list of templates.
  3. For Add Class from, select File.
  4. Click the Browse button next to the Location text box and browse to the location of a type library file that is marked as read-only.
  5. Click Save.
Excel.exe
Properties

Article ID: 311408 - Last Review: 10/26/2013 12:11:00 - Revision: 3.0

Microsoft Visual C++ .NET 2002 Standard Edition

  • kbnosurvey kbarchive kbfix kbautomation kbbug kbpending KB311408
Feedback