IVsUserSettings.ExportSettings Method (String, IVsSettingsWriter)

 

Saves a VSPackage's configuration using the Visual Studio settings mechanism when the export option of the Import/Export Settings feature available on the IDE’s Tools menu is selected by a user.

Namespace:   Microsoft.VisualStudio.Shell.Interop
Assembly:  Microsoft.VisualStudio.Shell.Interop.8.0 (in Microsoft.VisualStudio.Shell.Interop.8.0.dll)

Function ExportSettings (
	pszCategoryGUID As String,
	pSettings As IVsSettingsWriter
) As Integer

Parameters

pszCategoryGUID
Type: System.String

[in] GUID identifying the group of settings to be exported. This is the identifying GUID for the Custom Settings Point. For more information on Custom Settings Points, see Registering Settings Persistence Support

pSettings
Type: Microsoft.VisualStudio.Shell.Interop.IVsSettingsWriter

[in] An IVsSettingsWriter interface provided by the environment to the VSPackage providing write access to the Visual Studio settings file.

Return Value

Type: System.Int32

If the method succeeds, it returns S_OK. If it fails, it returns an error code.

A single VSPackage can support more than one Custom Settings Point (settings category).

Therefore, implementations of ExportSettings must check the category GUID passed in and choose the correct mechanism for saving the state specified by the particular Custom Settings Point.

In the example below, ExportSettings calls a different implementation for persisting command bar state as opposed to persisting key binding state.

In addition to data saved by the implementation of ExportSettings, the settings API also automatically saves the version of Visual Studio used to export configuration information.

In this example, the implementation of ExportSettings chooses between two different methods of exporting depending on the pszCategoryGUID argument.

STDMETHOD(ExportSettings)(WCHAR *pszCategoryGUID, IVsSettingsWriter *pSettings)
{
    CLSID clsidCategory;
    HRESULT hr;
    hr = CLSIDFromString(pszCategoryGUID, &clsidCategory);
    IfFailGo(hr);
    //Delegate to the right internal implementation based on the requested category

    if (GUID_Profiles_CommandBars == clsidCategory) {
        hr = ExportSettings_CommandBars(pSettings);
    }else if (GUID_Profiles_KeyBindings == clsidCategory) {
        hr = ExportSettings_KeyBindings(pSettings);
    }else{
        hr = E_UNEXPECTED;
    }
 Error:
    return hr;
};

HRESULT ExportSettings_CommandBars(IVsSettingsWriter *pSettings)
{
    if (!pSettings)
        return E_INVALIDARG;

    hr = pSettings->WriteSettingString(c_szFirstSettingName, L"Value1");
    IfFailGo(hr);

    int cRandomTrash = 12345;
    BYTE *pRandomTrash = (BYTE *)VSAlloc(cRandomTrash);
    if (pRandomTrash){
        hr = pSettings->WriteSettingBytes(c_szRandomTrashBytes, pRandomTrash, cRandomTrash);
        IfFailGo(hr);
        hr = pSettings->WriteSettingLong(c_szRandomTrashLength, cRandomTrash);
        IfFailGo(hr);
    }

 Error:
    return hr;
};

HRESULT ExportSettings_KeyBindings(IVsSettingsWriter *pSettings)
{
    if (!pSettings)
        return E_INVALIDARG;

    hr = pSettings->WriteSettingString(c_szBreakPointWindow, L"Ctrl + Alt + B");
    IfFailGo(hr);

 Error:
    return hr;
};

Return to top
Show: