更新:2007 年 11 月
您可以使用下列步驟建立 Visual C++ Win32 主控台應用程式 (Console Application),以程式設計方式啟動及控制裝置模擬器管理員 (DEM)。應用程式會使用 DEM Automation 介面控制 DEM。
使用這些介面,您就能以程式設計方式,針對電腦上的裝置模擬器執行列舉、啟動、連接底座、移除底座,以及關閉等操作。這些介面通常是由必須對許多模擬器自動進行測試的品質保證 (QA) 團隊使用。
若要建立使用裝置模擬器管理員 Automation 介面的專案
建立 Visual C++ Win32 主控台專案。
啟動 Visual Studio
在 [檔案] 功能表上,指向 [新增],然後按一下 [專案]。
[新增專案] 對話方塊隨即出現。
展開 [Visual C++],然後按一下 [Win32]。
按一下 [範本] 窗格中的 [Win32 主控台應用程式],將專案命名為 DEMSample,再按一下 [確定]。
[Win32 應用程式精靈] 隨即出現。
按 [下一步]。
核取 [應用程式設定] 頁面中的 [ATL],再按一下 [完成]。
新的專案隨即建立,並出現在 [方案總管] 中。
將 Microsoft Device Emulator 加入專案所包含的目錄中。
以滑鼠右鍵按一下 [方案總管] 內的 [DEMSample],再按一下 [屬性]。
[DEMSample 屬性頁] 對話方塊隨即出現。
展開 [組態屬性],然後按一下 [C/C++]。
在 [其他 Include 目錄] 旁邊加入 Microsoft Device Emulator 的資料夾,然後按一下 [確定]。
預設的位置為 drive:\program files\Microsoft Device Emulator\1.0。
將匯入 Automation 介面匯入。
按兩下 [方案總管] 中的 [stdafx.h],在 [程式碼編輯器] 中開啟這個檔案。
在檔案結尾加入下列程式碼:
#import "DEMComInterface.tlb" no_namespace raw_interfaces_only
在應用程式的 Main 方法中使用 IDeviceEmulatorManager。
按兩下 [方案總管] 中的 [DEMSample.cpp],在 [程式碼編輯器] 中開啟這個檔案。
在 Main 方法的 return 0; 上方,加入下列程式碼:
int _tmain(int argc, _TCHAR* argv[]) { if (SUCCEEDED(CoInitializeEx(NULL, COINIT_MULTITHREADED))) { // HRESULT is used to determine whether method calls are successful HRESULT hr; // Instantiate DeviceEmulatorManager (DEM) object. // This starts DvcEmuManager.exe in silent mode CComPtr<IDeviceEmulatorManager> pDeviceEmulatorManager; hr = pDeviceEmulatorManager.CoCreateInstance(__uuidof(DeviceEmulatorManager)); if (FAILED(hr)) { wprintf_s(L"Error: Unable to instantiate DeviceEmulatorManager. ErrorCode=0x%08X\n", hr); return false; } // Show the window. hr = pDeviceEmulatorManager->ShowManagerUI(true); system("pause"); // Hide the window. pDeviceEmulatorManager->ShowManagerUI(false); system("pause"); return true; CoUninitialize(); } return 0; }在 [偵錯] 功能表上按一下 [開始偵錯]。
程式會啟動裝置模擬器管理員,然後再呼叫 IDeviceEmulatorManager::ShowManagerUI,使其成為可見的狀態。