How to: Create Menu Commands for a VSPackage Using the Binary Command Table Compiler
You add commands and menus to your VSPackage using a two-step process. First, you place them into a .ctc file and compile them into a binary command table output (.cto) file using the Binary Command Table Compiler. Then, you include the .cto file as a resource in the local native satellite DLL, managed satellite DLL, or in managed VSPackage code.
The following procedures are necessary only if you are not using the Visual Studio SDK wizards, because they automatically perform these tasks for you.
The first procedure demonstrates how to compile the menu commands for your VSPackage into a binary .cto file. The next procedure shows how to use this file to expose the new VSPackage menus and commands in the Visual Studio IDE.
To create menu commands for a VSPackage
Create a command table .ctc file for the VSPackage as detailed in.
Compile the .ctc file using the Binary Command Table Compiler (Ctc.exe) to produce a binary .cto file.
Ctc.exe is located in EnvSDK\tools\bin\x86 directory under the Visual Studio SDK installation path. The default path is C:\Program Files\VSIP <Version>\EnvSDK\tools\bin\x86, where <Version> is the version of the Visual Studio SDK release.
Add the .cto file as a binary resource either to the managed VSPackage project, to a local native satellite DLL, or to a managed satellite DLL.
To do this, add the .cto file as a custom resource named CTMENU to the VSPackage's resource (.rc) file and assign it a unique ID. All of the menu and toolbar samples (listed in the Samples folder under Menu and Toolbar Commands folder in the table of contents) use this method. For more information about this, see.
To expose the new VSPackage menus and commands in the IDE
Install your VSPackage in Visual Studio.
Register the VSPackage using Regpkg.exe as detailed in.
This places a registry key named CLSIDofPackage in the [HKEY_LOCAL_MACHINE\Software\Microsoft\VisualStudio\<version>\Menus] section.
To avoid disrupting the existing IDE commands and menus with those of your package while you are debugging it, your VSPackage is registered in an alternate registry called the experimental hive. For more information about this, see.
There are two possible values for CLSIDofPackage:
<blank space>, 1000, 10
<drive>:\VisualStudio\bin\MyPackage.dll, 1000, 10
The data field for CLSIDofPackage is split into three sections separated by commas.
First Section: The full path name to the .cto file. If you leave this field blank, which is the recommended method, then the environment searches for the .cto information in your VSPackage's satellite DLL, as specified under the VSPackages section in the registry. If you need to, however, you can provide a specific path to the .cto file.
Second Section: The resource number of the menus in the .cto file. This must be a number, not a name or identifier.
Third Section: The version of the menu resource. Increment this number as you update the menus. Visual Studio will detect the version number change and re-merge the menus.
Implement handlers for the new commands. For information on doing this, see.
At a command prompt, enter devenv /setup to cause Visual Studio to merge the new VSPackage menus and commands with those already in Visual Studio.
The first procedure on this page outlines how to manually run Ctc.exe to create the .cto file. But when normally creating VSPackages, it is easier to instead run Ctc.exe by configuring a custom build step in Visual Studio. The Visual Studio SDK wizards do this for you. This eliminates the manual compilation step.
When you uninstall a VSPackage, the uninstaller removes the CLSIDofPackage registry key. Running devenv /setup then removes the menus from the IDE.
Visual Studio 2005 SDK features resource registration by modifying the class that defines your managed VSPackage with registration attributes likeand . When you execute Regpkg.exe, resource registry locations are extracted through reflection and are written to the registry. While the creation of the registration attribute classes has made registering VSPackage resources much easier, the underlying registry-based implementation remains unchanged.
Ctc.exe reads only multi-byte character set (MBCS) encoded files which it then converts to Unicode using the codepage of the current console. It will not read files saved as Unicode. Keywords are case-sensitive, must be ASCII, and must match the documentation exactly. The entire .cto file must be copied and localized.
The devenv.exe /setup command merges the new VSPackage's menus and commands into a user-specific initialization file called <user profile path>\Application Data\Microsoft\VisualStudio\<version>\<loc>\devenv.ctm. Additional customizations, such as the position of toolbars, are stored in a user profile file called <user profile path>\Application Data\Microsoft\VisualStudio\<version>\<loc>\cmdUI.PRF.
In the above paths, <user profile path> is a user's home directory, such as C:\Documents and Settings\MyLogin. <version> is the version of Visual Studio, and <loc> is the localization subdirectory (for U.S. English, this is 1033).