次の方法で共有


IDeviceEmulatorManagerVMID

更新 : 2007 年 11 月

このインターフェイスは、デバイス エミュレータ マネージャ (DEM: Device Emulator Manager) で、1 つのエミュレータを表します。このインターフェイスを使用することによって、接続、クレードルへの接続、リセットなどの操作をエミュレータで実行します。

interface IDeviceEmulatorManagerVMID : IDispatch{}

メソッド

メソッド

説明

IDeviceEmulatorManagerVMID::get_VMID

エミュレータを一意に識別する仮想マシン ID (VMID: Virtual Machine Identifier) を取得します。

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

参照

その他の技術情報

Device Emulator samples