随笔 - 249  文章 - 1  评论 - 1207  阅读 - 61万

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 ManagerUI,手动控制device emulator。这样就给测试自动化带来了困难。

   Device Emulator Manager Device Emulator 3.0VS2008默认安装的部分,它们引入了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上下载,或者通过下面这个链接来获得:https://files.cnblogs.com/dearsj001/DEMAutomationWrapperExample.rar

Good Luck

posted on   施炯  阅读(1828)  评论(2编辑  收藏  举报
编辑推荐:
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
< 2008年10月 >
28 29 30 1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31 1
2 3 4 5 6 7 8

点击右上角即可分享
微信分享提示