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.
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.
- 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:
- On the Project menu, select Add Class.
- Select MFC Class from Typelib from the list of templates.
- For Add Class from, select Registry.
- In the list of available type libraries, find the friendly name for the type library from which you want to add classes.
- From the list of interfaces in that type library, select the classes for which you want to add wrappers.
- Click Finish.
- 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.
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).
Article ID: 311408 - Last Review: October 26, 2013 - Revision: 3.0
- Microsoft Visual C++ .NET 2002 Standard Edition
|kbnosurvey kbarchive kbfix kbautomation kbbug kbpending KB311408|