IVsUserSettings.ExportSettings(String, IVsSettingsWriter) Method

Definition

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.

public:
 int ExportSettings(System::String ^ pszCategoryGUID, Microsoft::VisualStudio::Shell::Interop::IVsSettingsWriter ^ pSettings);
public:
 int ExportSettings(Platform::String ^ pszCategoryGUID, Microsoft::VisualStudio::Shell::Interop::IVsSettingsWriter ^ pSettings);
int ExportSettings(std::wstring const & pszCategoryGUID, Microsoft::VisualStudio::Shell::Interop::IVsSettingsWriter const & pSettings);
public int ExportSettings (string pszCategoryGUID, Microsoft.VisualStudio.Shell.Interop.IVsSettingsWriter pSettings);
abstract member ExportSettings : string * Microsoft.VisualStudio.Shell.Interop.IVsSettingsWriter -> int
Public Function ExportSettings (pszCategoryGUID As String, pSettings As IVsSettingsWriter) As Integer

Parameters

pszCategoryGUID
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
IVsSettingsWriter

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

Returns

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

Examples

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;  
};  

Remarks

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.

Applies to