Advanced Topics - Windows SideShow Gadgets 

The following topics discuss more advanced gadget development topics.

Multiple Gadgets in a Single Binary

Each gadget must have its own gadget metadata (registry entries). If each of your gadgets will be hosted in a separate process, your binary can identify which gadget is invoked by making use of the StartCommand registry entry. Each gadget can have a start command that invokes the executable and passes an argument that indicates which specific gadget is to be run. In the following example, the application ID of the gadget to be run is supplied as an argument to the gadget executable. The example shows two StartCommand values for gadgets contained within the same binary.

StartCommand for Gadget 1:

%programFiles%\Windows SideShow\My Gadget\MyGadget.exe {58DD4119-E708-4c0a-8740-D0E02BAF212F}

StartCommand for Gadget 2:

%programFiles%\Windows SideShow\My Gadget\MyGadget.exe {3D863983-3947-4c57-A1D7-D459B903D738}

Alternatively, multiple gadgets can also be contained in a DLL and run by rundll32.exe. In that case, the DLL can expose multiple entry points (for example, GadgetEntry1, GadgetEntry2), and specify a StartCommand value as shown in the following example.

rundll32.exe “%programFiles%\Windows SideShow\My Gadget\MyGadget.dll”,GadgetEntry1

This approach saves the developer from parsing the command line for executable-based gadgets.

For more information about installing a gadget, see Installing a Gadget.

Multiple Gadgets in a Single Process

In some cases, it might be useful to run multiple gadgets in the same process. For example, a PIM application might have separate gadgets for e-mail, calendar, and contacts all running at the same time within the PIM application's process.

If the process containing the gadgets is invoked by the Gadget Manager, it is important that the binary allows only one running instance at a time. We recommend that each gadget within the process perform its initial registration with Windows SideShow, but minimize its use of additional resources until it has devices to send content to. Upon startup, gadgets can determine the number of available devices by querying for the device capabilities collection, and if the device count is 0, gadgets can wait to be notified when devices are added through an event sink.

COM API Threading Model

The Windows SideShow COM API operates in a multi-threaded apartment (MTA). When a gadget accesses the API objects from a single-threaded apartment (STA), COM marshals the calls between the gadget and the API apartments. For more information about COM threading models, see Processes, Threads, and Apartments in the Windows SDK.