Command Contracts in Interop Assemblies

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

Concepts

How VSPackages Add User Interface Elements to the IDE

Command Implementation

Other Resources

Command Routing in VSPackages