How to: Register Editor Factories
Before you can use an editor VSPackage you have created, you first must register information about it, including the file extensions it can handle, in the system's HKLocalMachine/Visual Studio 8.0/Editors registry subkey.
If your VSPackage is written in managed code, such as Visual C#, you can use the Managed Package Framework (MPF) method RegisterEditorFactory to register the editor factory. If your VSPackage is written in unmanaged code, such as Visual C++, then after the integrated development environment (IDE) loads your package, you must provide the IDE with a pointer to the editor factory. The procedure for each of these scenarios is described below.
If you provide an editor factory, you should register it by overriding the Initialize method. First call base.Initialize, and then call RegisterEditorFactory for each editor factory. For example:
protected override void Initialize() {
// This method is called when the package is first
// initialized. Override it if you need to do work
// that happens as part of package initialization.
base.Initialize();
// Register our editor factory
RegisterEditorFactory(new VSEditorFactory());
In managed code, there is no need to unregister an editor factory as the VSPackage will handle this for you. Also, if your editor factory is IDisposable, it is automatically disposed when it is unregistered.
To register an editor factory with the IDE (unmanaged code)
In the SetSite implementation for your editor package, pass the IDE a pointer to your editor factory using the SVsRegisterEditors service as follows:
In your VSPackage's SetSite implementation, use the QueryService method to call SVsRegisterEditors.
Doing this returns a pointer to IVsRegisterEditors.
Call the RegisterEditor method and pass the IDE a pointer to the object that implements the IVsEditorFactory interface for the selected editor.
Nota
Implement IVsEditorFactory on its own object.
Robust Programming
The following process occurs when the IDE loads your editor using your editor factory:
The Visual Studio project system calls OpenStandardEditor.
The IDE's implementation of this method first gets the editor factory. The IDE delays loading the editor's package, however, until a project system actually needs the editor.
When a project system needs the editor, the IDE calls CreateEditorInstance, a specialized method that returns both the document view and the document data objects.
The IDE then creates the document window, places the document view object in it, and makes an entry into the running document table (RDT) for the document data object, if calls by the IDE to your editor factory using CreateEditorInstance, return both a document data object and a document view object.