IVsCommandWindow.PrepareCommand Method (String, Guid, UInt32, IntPtr, PREPARECOMMANDRESULT[])

 

Performs all the steps to prepare to execute a command-line command.

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

int PrepareCommand(
	string szCommand,
	out Guid pguidCmdGroup,
	out uint pdwCmdID,
	out IntPtr ppvaCmdArg,
	PREPARECOMMANDRESULT[] pResult
)

Parameters

szCommand
Type: System.String

[in] String containing the command.

pguidCmdGroup
Type: System.Guid

[out] Pointer to the GUID of the command's group.

pdwCmdID
Type: System.UInt32

[out] Pointer to the identifier of the command.

ppvaCmdArg
Type: System.IntPtr

[out] A pointer to a VARIANT array containing the command arguments.

pResult
Type: Microsoft.VisualStudio.Shell.Interop.PREPARECOMMANDRESULT[]

[out] A pointer to a PREPARECOMMANDRESULT structure containing additional error information.

Return Value

Type: System.Int32

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

The method performs the following steps:

  1. Parses the command string.

  2. Looks up the command.

  3. Verifies the command is enabled.

  4. Determines whether it accepts parameters.

  5. Prepares a VARIANT containing the parameters and a structure to receive the command results.

Upon return, the caller has all the information needed to call the Exec method of the IOleCommandTarget interface.

From vsshell.idl:

HRESULT IVsCommandWindow::PrepareCommand(
   [in, ref] LPCOLESTR szCommand, 
   [out] GUID* pguidCmdGroup, 
   [out] DWORD* pdwCmdId, 
   [out] VARIANT** ppvaCmdArg, 
   [out, retval] PREPARECOMMANDRESULT* pResult
);

On failure, PrepareCommand returns E_FAIL and sets pResult to a value of type PREPARECOMMANDRESULT indicating the nature of the failure. This enables the caller to customize the reporting of various errors. Also on failure the thread error information is set with a meaningful string.

The caller is responsible for the VARIANT argument ppvaCmdArg. To free it, the caller must first call to clear the contents, and then call to free the VARIANT itself.28741d81-8404-4f85-95d3-5c209ec138353d0af12e-fc74-4ef7-b2dd-e9da5d0483c7

Return to top
Show: