共用方式為


IDeviceEmulatorManagerVMID

更新:2007 年 11 月

這個介面代表 [裝置模擬器管理員] (DEM) 內的單一模擬器。您可以使用這個介面,在模擬器上執行如連接、連接底座和重設等作業。

interface IDeviceEmulatorManagerVMID : IDispatch{}

方法

方法

描述

IDeviceEmulatorManagerVMID::get_VMID

取得虛擬機器識別碼 (Virtual Machine Identifier,VMID),這是模擬器的唯一識別。

IDeviceEmulatorManagerVMID::get_State

取得模擬器目前的狀態。模擬器可以是未執行、執行中或已連接底座的狀態。

IDeviceEmulatorManagerVMID::get_Name

取得模擬器的名稱,例如 Pocket PC 2003 SE 模擬器。

IDeviceEmulatorManagerVMID::Connect

如果尚未啟動 [裝置模擬器] 並與其連接,則將其啟動。

IDeviceEmulatorManagerVMID::Cradle

連接模擬器。

IDeviceEmulatorManagerVMID::UnCradle

移除模擬器。

IDeviceEmulatorManagerVMID::Shutdown

關閉模擬器,並選擇性地儲存模擬器的狀態。

IDeviceEmulatorManagerVMID::Reset

重設模擬器。

IDeviceEmulatorManagerVMID::ClearSaveState

清除與此裝置相關聯之裝置模擬器儲存的狀態檔 (.dess)。下一次啟動裝置模擬器時,模擬器將會從其 ROM 映像啟動,而不是從儲存的狀態檔啟動。

IDeviceEmulatorManagerVMID::BringToFront

顯示 [裝置模擬器] 視窗。

IDeviceEmulatorManagerVMID::GetConfiguration

取得格式為裝置模擬器組態 XML 的模擬器組態。

IDeviceEmulatorManagerVMID::SetConfiguration

設定已正確格式化為裝置模擬器組態 XML 字串的模擬器組態。

備註

若要建立實作此介面的物件,請使用 IEnumVMIDs::get_VMID

範例

這個範例會啟動 Pocket PC 2003 模擬器並執行各種作業。

BOOL FindDevice(const CComBSTR& deviceIdentifier, IDeviceEmulatorManagerVMID** pDeviceVMID);

int _tmain(int argc, _TCHAR* argv[])
{
    if (SUCCEEDED(CoInitializeEx(NULL, COINIT_MULTITHREADED)))
    {
        HRESULT hr;
        CComPtr<IDeviceEmulatorManagerVMID> pDevice = NULL;

        // Get the emulator by calling a helper function
        hr = FindDevice("Pocket PC 2003 SE Emulator", &pDevice);

        // If the emulator is found
        if (SUCCEEDED(hr))
        {
            // Output the name of the emulator
            CComBSTR deviceName;
            hr = pDevice->get_Name(&deviceName);
            if (SUCCEEDED(hr)) wprintf_s(L"Device Name: %s\n", deviceName);

            // Output the emulator's VMID
            CComBSTR VMID;
            hr = pDevice->get_VMID(&VMID);
            if (SUCCEEDED(hr)) wprintf_s(L"Device VMID: %s\n", VMID);

            // Output the emulator's current state
            EMULATOR_STATE deviceState = EMU_NOT_RUNNING;
            hr = pDevice->get_State(&deviceState);
            if (SUCCEEDED(hr))
            {
                if (deviceState == EMU_CRADLED) wprintf_s(L"Emulator is Cradled\n");
                else if (deviceState == EMU_RUNNING) wprintf_s(L"Emulator is Running\n");
                else wprintf_s(L"Emulator is Not Running\n");
            }

            // Connect to the emulator
            hr = pDevice->Connect();
            if (SUCCEEDED(hr)) wprintf_s(L"Emulator is connected\n");

            // Make the Device Emulator window visible
            hr = pDevice->BringToFront();
            if (SUCCEEDED(hr)) wprintf_s(L"Device Emulator window is on top\n");

            // Cradle the emulator
            hr = pDevice->Cradle();
            if (SUCCEEDED(hr)) wprintf_s(L"Emulator is cradled\n");
            system("pause");

            // Uncradle the emulator
            hr = pDevice->UnCradle();
            if (SUCCEEDED(hr)) wprintf_s(L"Emulator is uncradled\n");

            // Save state and shutdown the emulator
            hr = pDevice->Shutdown(true);
            if (SUCCEEDED(hr)) wprintf_s(L"Emulator is shutdown\n");

            // Delete the .dess save state file for this device
            hr = pDevice->ClearSaveState();
            if (SUCCEEDED(hr)) wprintf_s(L"Save state file is deleted");
            system("pause");
        }
    }
    return 0;
}

// Helper method to find a device given name or VMID
BOOL FindDevice(const CComBSTR& deviceIdentifier, IDeviceEmulatorManagerVMID** pDeviceVMID)
{
    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;
    }

    // For each of the four nodes in the Device Emulator Manager window
    // (Datastore, My Device Emulators, All Device Emulators, and Others)
    for (; SUCCEEDED(hr); (hr = pDeviceEmulatorManager->MoveNext()))
    {
        CComPtr<IEnumManagerSDKs> pSDKEnumerator;


        // Get a list of SDKs/platforms in this node
        hr = pDeviceEmulatorManager->EnumerateSDKs(&pSDKEnumerator);
        if (FAILED(hr)) {
            continue;
        }

        // For every SDK/platform in the list
        for (; SUCCEEDED(hr); (hr = pSDKEnumerator->MoveNext()))
        {

            // Get the list of emulators in the SDK/platform
            CComPtr<IEnumVMIDs> pDeviceEnumerator;
            hr = pSDKEnumerator->EnumerateVMIDs(&pDeviceEnumerator);
            if (FAILED(hr)) {
                continue;
            }

            // For every emulator in the list
            for (; SUCCEEDED(hr); (hr = pDeviceEnumerator->MoveNext()))
            {
                CComBSTR deviceName;
                CComPtr<IDeviceEmulatorManagerVMID> pDevice;

                // Get the IDeviceEmulatorManagerVMID object.
                hr = pDeviceEnumerator->GetVMID(&pDevice);
                if (FAILED(hr)) {
                    continue;
                }

                // Get the name of the emulator
                hr = pDevice->get_Name(&deviceName);
                if (FAILED(hr)){
                    continue;
                }

                // If the name of the device matches the supplied name, 
                // then this is the device we are looking for. 
                if (deviceIdentifier == deviceName){
                    *pDeviceVMID = pDevice;
                    (*pDeviceVMID)->AddRef();
                    return TRUE;
                }
            }
        }
    }
    wprintf_s(L"Error: Unable to locate the device '%s'", deviceIdentifier);
    return FALSE;
}

需求

DEMComInterface.tlb

請參閱

其他資源

裝置模擬器範例