IVsUserSettings.ExportSettings Method
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)
Syntax
'宣言
Function ExportSettings ( _
pszCategoryGUID As String, _
pSettings As IVsSettingsWriter _
) As Integer
'使用
Dim instance As IVsUserSettings
Dim pszCategoryGUID As String
Dim pSettings As IVsSettingsWriter
Dim returnValue As Integer
returnValue = instance.ExportSettings(pszCategoryGUID, _
pSettings)
int ExportSettings(
string pszCategoryGUID,
IVsSettingsWriter pSettings
)
int ExportSettings(
[InAttribute] String^ pszCategoryGUID,
[InAttribute] IVsSettingsWriter^ pSettings
)
function ExportSettings(
pszCategoryGUID : String,
pSettings : IVsSettingsWriter
) : int
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 Persisting Settings
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.
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.
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;
};
Permissions
- Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see Using Libraries from Partially Trusted Code.
See Also
Concepts
How to: Export Settings Using Interop Assemblies
How to: Use Interop Assemblies to Import Settings