Compartilhar via


Command contracts in interop assemblies

Applies to: yesVisual Studio noVisual Studio for Mac

Note

This article applies to Visual Studio 2017. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here

The basic contract for handling commands through the IOleCommandTarget interface is that the environment calls the QueryStatus method to determine whether the command is supported and, if it is supported, to determine its state and text. Then, the environment calls the Exec method to execute the command.

The QueryStatus method is handled identically for all commands. Further communication, if required (for example, with drop-down lists), is managed by calling the Exec method with appropriate parameters. The interpretation of these parameters depends on the command specified.

If the command target returns values in the output parameter, the caller is always responsible for freeing any resources that had been allocated. Because this parameter is a variant, clearing the variant frees the resources.

In cases where commands must operate within a hierarchy window, the IVsUIHierarchy interface must be used. The IVsUIHierarchy interface has a similar contract with similar methods: QueryStatusCommand and ExecCommand.

See also