Have you ever wish you could automatically cradle an emulator, run a test for example and then close down the emulator? With the current emulators v1.0 and 2.0 it was possible but not practical since no API existed for the device manager and emulators. The next version of Visual Studio, Orcas, includes the new Device Emulator v3.0 which has a COM interface to control the manager.
Automate Device Emulator
The team building the new emulator focused on manageability and automation for version 3. The item that was most intriguing for me was being able to automate the emulator. So I broke out Orcas and tried it.
Since this was for Orcas I started a Windows WPF project. Next I add a COM reference for DEMComInterface 1.0 Type Library. This gave me the following interfaces.
The first interface is DeviceEmulationManager. This interface gives you access to the device manager. The device manager can be is used
- to enumerate through the data stores
- show the device manager UI
- force a refresh
- get notification of a refresh
Once a data store is found it can be retrieved by using IEnumManagerSDKs to loop through available SDKs. IEnumManagerSDK only allows for enumerating SDKs.
IDeviceEmulatorManagerVMID is used to control and enumerate through various emulators associated with an SDK. IDeviceEmulatorManagerVMID can be used to
- launch and shutdown an emulator
- cradle and uncradle the emulator
- get and set configuration information
- clear save state
To enumerate with these interfaces you have limited ability. You can simply do MoveNext and then use Get???? to retrieve the current item.
Hello Emulator
The following will start an emulator and cradle it.
- connect to the COM interfaces
- get a data store with the emulators
- get the SDK wanted e.g. Windows Mobile 5
- get the emulator wanted e.g. Square Phone
- Launch
- Cradle
// Variable Declaration
IDeviceEmulatorManager mgr;
IEnumManagerSDKs sdks;
IEnumVMIDs vms;
IDeviceEmulatorManagerVMID emulator;
// Connect to Device Manager
mgr = new DeviceEmulatorManagerClass();
// Get the WM5 PPC SDK
sdks = mgr.EnumerateSDKs();
while (sdks.get_Name() != "Windows Mobile 5.0 Pocket PC SDK")
{
sdks.MoveNext();
}
// Get the Emulator
vms = sdks.EnumerateVMIDs();
while (vms.GetVMID().get_Name() != "Windows Mobile 5.0 Pocket PC Emulator")
{
vms.MoveNext();
}
// Get COM Interface to Emulator
emulator = vms.GetVMID();
// Launch emulator
emulator.Connect();
// Cradle emulator
emulator.Cradle();
Attach the above to a button click event and viola an emulator is launched and cradle. Next project, wrap the interfaces so emulators can be accessed using Linq.
Comments