SAMPLE: CmdLanch.exe Launches EXE from Custom Outlook Menu Item

ID: Q199360

The information in this article applies to:


CmdLanch.exe is a self-extracting executable file that contains a custom extension sample written with Microsoft Visual C++ 5.0 for use with Microsoft Outlook 98. The code sample demonstrates how to implement custom command extensions for the Microsoft Outlook Client.

CmdLanch creates three menu items and corresponding toolbar buttons then adds them to the Outlook client's menu bar and standard toolbar. The commands currently launch Notepad, Wordpad and Paint respectively. This extension can be easily modified to launch the executable of your choice or to perform other activities from custom Outlook commands.

If you want to create custom extensions for use with Outlook 98, then this sample will help you get started. It also gives you a working example of using the Exchange extension interfaces from Visual C++.


The following file is available for download from the Microsoft Software Library:

Release Date: Mar-11-1999

For more information about downloading files from the Microsoft Software Library, please see the following article in the Microsoft Knowledge Base:
Q119591 How to Obtain Microsoft Support Files from Online Services

The CmdLanch.exe file will self extract to produce the following files:

   File Name         Size     Description

   CmdLanch.dll      40KB     Exchange extension DLL
   CmdLaunchExe.reg   1KB     Extension registration file
   cmdExt.cpp        28KB     Main extension source file
   cmdExt.h           6KB     main extension header file
   CmdLaunchExe.dsp   4KB     Microsoft Visual C++ 5.0 project file
   CmdLaunchExe.dsw   1KB     Microsoft Visual C++ 5.0 workspace file
   resource.h         1KB     Extension resource header file
   script1.rc         3KB     Extension resource template
   bitmap2.bmp        1KB     Toolbar button bitmap resource
   bitmap3.bmp        1KB     Toolbar button bitmap resource
   bitmap4.bmp        1KB     Toolbar button bitmap resource 

Installing and Configuring the Sample

  1. Copy the CmdLanch.dll file to your Windows\System directory (WINNT\SYSTEM32 is used by this sample).

  2. Open the CmdLaunchExe.reg file in Notepad and change the path to reflect the actual location of the CmdLanch.dll file on your system.

  3. Save the CmdLaunchExe.reg file and exit Notepad.

  4. Double-click the CmdLaunchExe.reg file in Windows Explorer. This will register the CmdLanch.dll file for use by Outlook as a custom extension.

  5. Re-start Microsoft Outlook.

  6. You should see a custom Toolbar button on the Toolbar, and a custom menu item on the Tools menu, for the Launch .exe command.

  7. Click either command and Notepad should start immediately.

Instructions for Customizing CmdLaunchExe.dll

The source for this sample was created using VC++ 5.0 Service Pack 3. You can modify the source for this extension to reflect your own menu item and toolbar button bitmaps. (See the MyExchExtCommands::InstallCommands method for more information.)

The .exe that launches can be changed by editing the MyExchExtCommands::DoCommand method. Alternatively, you could request the .exe location from the user using the CommonDialog control.

You will also want to edit the following methods to reflect your own text requirements:


More Exchange Extension Information

This sample requires Microsoft Windows NT 3.51 or Windows 95, the MAPI 1.0 PDK, Microsoft Visual C++ version 2.0 (or later), and the Win32 Platform SDK.

Exchange client extensions are designed using OLE's Component Object Model. The Client calls methods, which are provided in the extension. In some calls to the extension interface, a pointer to a callback interface is used (IExchExtCallback) for the extension to call back into the Exchange client. For more information regarding this interface, please see "Extending the Microsoft Exchange Client" in the MAPI PDK documentation.

This sample implements three interface objects: IExchExt, IExchExtCommands, and IExchExtUserEvents. To extend the command set of Exchange, it is necessary to provide implementations for IExchExt and IExchExtCommands. It is optional to provide implementation for IExchExtUserEvents. This sample implements IExchExtUserEvents to enable or disable the custom command, depending on what object the user is selecting in the Exchange main viewer. The menu item is always enabled in the Search Folder dialog box.

The custom command is available in both the Main viewer and the Search Folder dialog box. The IExchExtCommands provides an interface for the client to display context help on the custom menu item and to display tooltip text and status window text. Select the custom menu item and press F1 to open an About dialog box.

This extension works in two different contexts, main viewer and search dialog. For each context an extension supports, a complete set of interface objects is created. In this sample, the MyExchExt, MyExchExtCommands and MyExchExtUserEvents objects are created once for the main viewer context and once for the search dialog. However, because there is only one implementation for all contexts, there is a context flag data member which indicates from which context Exchange is calling.

A context in many cases corresponds to a user interface. For example, the search viewer is one context and the main viewer is another. QueryInterface is called for each interface identifier (IID) for each context. In this example, QueryInterface is called each time for all IIDs in the main viewer context when Exchange first starts. QueryInterface is called again each time for all IIDs in the search viewer context. For each of the contexts, a unique pointer to the MyExchExtCommands and MyExchExtUserEvents objects is returned to Exchange in the QueryInterface call. Then when Exchange is calling DoCommands from the search viewer, it is calling the one using the interface pointer returned to it through QueryInterface in the search viewer context. When Exchange is calling DoCommands from the main viewer, it is calling the one using the interface pointer returned to it through QueryInterface in the main viewer context.

Additional query words: kbdse kbMsg kbVC kbOutlook98 kbMAPI extension

Keywords          : kbfile kbsample kbAutomation kbEDK kbMAPI kbMsg kbOutlook 
Version           : WINDOWS:
Platform          : WINDOWS 
Issue type        : kbinfo 

Last Reviewed: April 2, 1999