专栏首页施炯的IoT开发专栏VS2008下使用托管代码控制Windows Mobile Device Emulators

VS2008下使用托管代码控制Windows Mobile Device Emulators

  在听黎波老师的Webcast-Visual Studio 2008 移动开发新体验时,听他提到过可以使用代码来控制Device Emulator。今天在msdn上看到了Jim Wilson写的” How To: Programmatically Control the Windows Mobile Device Emulators from .NET”一文,觉得很有必要和大家分享一下。

  大家知道,device emulator在调试windows mobile应用程序的时候非常有用。Device Emulator Manager可以执行包括启动device emulator、保存device emulator状态、cradle(和Activesync进行同步)、关闭device emulator等功能。现在我们面临的challenge就是:必须通过Device Emulator Manager的UI,手动控制device emulator。这样就给测试自动化带来了困难。

   Device Emulator Manager 和 Device Emulator 3.0是VS2008默认安装的部分,它们引入了Device Emulator Manager API,从而在一定程度上解决了上面的问题。Device Emulator Manager API提供了访问Device Emulator的编程接口,我们可以在desktop应用中调用Device Emulator Manager API,来执行和Device Emulator Manager同样的功能。

l The Device Emulator Manager API

   Device Emulator Manager API是通过组件对象模型(COM) In-Process库实现的,即在.NET托管代码中,使用Microsoft.DeviceEmulatorManager.Interop.9.0.dll提供接口。该dll文件位于”%Program Files%\Microsoft Device Emulator\1.0”下,使用API必须添加"Microsoft.DeviceEmulatorManager.Interop"命名空间。同时,为了使用P/F,我们最好加入"System.Runtime.InteropServices"。

l Controlling the Device Emulator

  最常用的Device Emulator API就是IDeviceEmulatorManagerVMID接口。下表列出了该Interface的方法和描述。

Method

Description

BringToFront

Moves the Device Emulator to the foreground of the desktop display and makes the Device Emulator the active application.

ClearSaveState

Clears the Device Emulator's saved state file (.dess). The next time you start the Device Emulator, the Device Emulator will have no existing state and will start from the ROM image. The Device Emulator will therefore appear as a new device. Any software you have installed or setting changes you have made are lost.

Connect

Starts the Device Emulator.

Cradle

Puts the Device Emulator in the virtual cradle and causes the Device Emulator to connect to the desktop using Microsoft ActiveSync® (Windows XP) or Windows Mobile Device Center (Windows Vista®).

get_Name

Returns the display name of the emulator such as Windows Mobile 6 Professional Emulator or Windows Mobile 5.0 Smartphone. The display name is the same value that appears in the Device Emulator Manager user interface's list of Device Emulators.

get_State

Returns the EMULATOR_STATE enumeration value corresponding to the Device Emulator's current state. Possible values are EMU_NOT_RUNNING, EMU_RUNNING, and EMU_CRADLED. A Device Emulator is in only one state at a time.

get_VMID

Returns the Device Emulator's Virtual Machine Identifier (VMID), which is a globally unique identifier (GUID) unique to each emulator image.

GetConfiguration

Returns an XML string describing the Device Emulator's current configuration.

Reset

Performs a soft-reset or hard-reset of the Device Emulator as specified by the passed integer parameter. A non-zero parameter value specifies a soft-reset.

SetConfiguration

Sets the Device Emulator to the configuration described in the provided XML string parameter.

Shutdown

Shuts down the Device Emulator, optionally saving the Device Emulator's state as specified by the passed integer parameter. A non-zero parameter value specifies that the state should be saved.

UnCradle

Removes the Device Emulator from the virtual cradle and causes the Device Emulator to disconnect from ActiveSync (Windows XP) or Windows Mobile Device Center (Windows Vista).

l A Device Emulator Manager Wrapper

 包装(Wrapper)这些API给.NET托管代码来用,可以为许多工程带来方便。示例工程提供的封装包括以下几个类,同时给出了描述:

Type

Description

DeviceEmulatorManagerEx

Represents the Device Emulator Manager. Encapsulates the Device Emulator Manager features of the IDeviceEmulatorManager interface.

DeviceEmulatorCategory

Represents an individual category. Encapsulates those features of the IDeviceEmulatorManager interface that represent a single category.

DeviceEmulatorSdk

Represents an individual SDK. Encapsulates those features of the IEnumManagerSDKs interface that represent a single SDK.

DeviceEmulator

Represents an individual Device Emulator. Provides the same features as the IDeviceEmulatorManagerVMID interface.

  恩,就啰嗦到这里吧。具体的代码大家可以直接去MSDN上下载,或者通过下面这个链接来获得:http://files.cnblogs.com/dearsj001/DEMAutomationWrapperExample.rar

Good Luck!

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

我来说两句

0 条评论
登录 后参与评论

相关文章

  • Application Architecture Guide 2.0 - CH 19 - Mobile Applications(5)

    本文翻译"Deployment"、"Pattern Map"、"Pattern Descriptions"和"Technology Considerations...

    ShiJiong
  • Appointment over SMS on Windows Mobile

        设想这样一个场景,早上出门的时候,手机里一个Appointment提醒弹了出来,恰好昨天还没有来得及通知参与该会议的几个重要成员,而这时候身边又没有可以...

    ShiJiong
  • Ring Tone Manager on Windows Mobile

        手机铃声经常能够体现一个人的个性,有些哥们儿在自习室不把手机设置成震动,一来电就@#$^%^@&^%#$&$*@,声音还很大,唯恐别人听不到。 Win...

    ShiJiong
  • 剖析Oracle中oerr命令(r8笔记第70天)

    Oralce中的命令非常丰富,oerr命令是一个不错的辅助工具,很多看起来没有眉目的错误代码,可以让DBA很快定位问题的缘由,我们根本不需要去记有哪些ORA错误...

    jeanron100
  • Numpy模拟生命

    用户2183996
  • 代码转换工具 Code Converter 2013

    http://www.codeproject.com/Articles/260997/Code_Converter This is a Code Conver...

    张善友
  • 猴脑-脑功能区拓扑结构赏析Network architecture of the long-distance ... brain

    Network architecture of the long-distance pathways in the macaque brain

    用户1908973
  • 聊聊flink Table的ScalarFunction

    flink-table_2.11-1.7.1-sources.jar!/org/apache/flink/table/functions/ScalarFunct...

    codecraft
  • basic_consume() got multiple values for keyword argument 'queue'

    今天在新的服务器上安装了一个pip install pika,然后连接mq的程序就报错了

    周小董
  • 学界 | 谷歌云提出渐进式神经架构搜索:高效搜索高质量CNN结构

    机器之心

扫码关注云+社区

领取腾讯云代金券

玩转腾讯云 有奖征文活动