次の方法で共有


IDeviceAgentTransport

更新 : 2007 年 11 月

デスクトップ コンピュータ上の RemoteAgent と通信するために使用します。

IDeviceAgentTransport : public IUnknown

メソッド

メソッド

説明

IDeviceAgentTransport::AcknowledgeLaunch

サービス ID の配列を登録します。デバイス エージェントは、この配列に含まれるサービス ID を持つ開発用コンピュータからの接続要求を受け入れることができます。

IDeviceAgentTransport::AcceptConnectionEx

デスクトップ コンピュータ上で CreatePacketStream が呼び出されたときに開始された接続を受け入れます。次に、このメソッドは、データ転送のためのデバイス パケット ストリームの引数を準備します。

IDeviceAgentTransport::RegisterShutdownCallback

エージェントがシャットダウンされる前に通知を受け取るためのコールバックを登録します。

IDeviceAgentTransport::UnregisterShutdownCallback

コールバック リストからコールバックを削除します。コールバックはシャットダウン通知を受信しなくなります。

解説

このインターフェイスを実装するオブジェクトを取得するには、GetDeviceAgentTransport を使用します。

使用例

デスクトップに 1 つのパケットを書き込み、デスクトップから 1 つのパケットを読み取るデバイス エージェント アプリケーションの例を次に示します。

#include "stdafx.h"

// Custom implementation of IAgentTransportShutdownCallback
class MyShutdownCallback: public IAgentTransportShutdownCallback
{
private:
    long ref;
public:
    HRESULT STDMETHODCALLTYPE Shutdown(IUnknown *in_pUnknown) 
    {
        // Add your cleanup code here 
        MessageBox(NULL,_T("conmanclient2 exited"),_T("conmanclient exited"),0);
        return 0;
    }

    // Must implement members from IUnknown
    HRESULT STDMETHODCALLTYPE QueryInterface( REFIID riid, void __RPC_FAR *__RPC_FAR *ppvObject)
    {
        return 0;
    }
    ULONG STDMETHODCALLTYPE AddRef( void)
    {
        return InterlockedIncrement(&ref);
    }

    ULONG STDMETHODCALLTYPE Release( void)
    {
        if(InterlockedDecrement(&ref) == 0)
        {
            delete this;
            return 0;
        }
        return ref;
    }
};

int _tmain(int argc, _TCHAR* argv[])
{
    // Load the Device Agent Transport Library
    HINSTANCE hmod;
    hmod = LoadLibrary(L"DeviceAgentTransport.dll");

    // Get an instance of IDeviceAgentTransport
    GetDeviceAgentTransportFunc f1 = (GetDeviceAgentTransportFunc)
        ::GetProcAddress(hmod, L"GetDeviceAgentTransport");
    IDeviceAgentTransport *pTransport = NULL;
    f1(&pTransport);

    // Register the callback with the Device Agent Transport
    MyShutdownCallback *shutdownCallback = new MyShutdownCallback();
    pTransport->RegisterShutdownCallback(shutdownCallback,shutdownCallback);

    // Let the desktop application know that this remote agent was deployed successfully 
    // and that this remote agent will handle the supplied list of services.
    LPCOLESTR szServiceIds[] = {L"F85E57BA-5AE9-4FF7-8433-6AB7D991D033"};
    pTransport->AcknowledgeLaunch(1, szServiceIds);

    // Open a communcation stream with desktop application on the service.
    IDevicePacketStream *pStream = NULL;
    pTransport->AcceptConnectionEx(szServiceIds[0], &pStream);

    // Get an instance of IPacket
    GetNewPacketFunc f2 = (GetNewPacketFunc) ::  GetProcAddress(hmod, L"GetNewPacket");
    IPacket *pPacket = NULL;
    f2(&pPacket);

    // Write a message and sent the packet.
    pPacket->WriteBool(true);
    pPacket->WriteByte(0xff);
    pPacket->WriteChar('c');
    pPacket->WriteInt32(1024);
    pPacket->WriteString(L"Hello Desktop Computer");
    pStream->Write(pPacket);

    // Check for a packet while communication stream is connected.
    f2(&pPacket);
    VARIANT_BOOL connected;
    pStream->IsConnected(&connected);
    while(connected)
    {
        pStream->IsConnected(&connected);
        VARIANT_BOOL available;

        // If a packet is found, display the string.
        pStream->IsPacketAvailable(&available);
        if(available)
        {
            pStream->Read(&pPacket);
            VARIANT_BOOL endofpacket;
            pPacket->IsEndOfPacket(&endofpacket);
            while (!endofpacket) 

            {
                pPacket->IsEndOfPacket(&endofpacket);
                DataTypeEnum datatype;
                pPacket->ReadDataType(&datatype);
                switch (datatype)
                {
                    case DT_BYTE:
                        BYTE byteValue;
                        pPacket->ReadByte(&byteValue);
                        break;
                    case DT_INT32:
                        INT32 intValue;
                        pPacket->ReadInt32(&intValue);
                        break;
                    case DT_WIDECHAR:
                        wchar_t charValue;
                        pPacket->ReadChar(&charValue);
                        break;
                    case DT_BOOL:
                        VARIANT_BOOL boolValue;
                        pPacket->ReadBool(&boolValue);
                        break;
                    case DT_BYTEARRAY:
                        BYTE * buffer[100];
                        ULONG length;
                        pPacket->ReadBytes(buffer,&length);
                        break;
                    case DT_STRING:
                        LPWSTR string;
                        pPacket->ReadString(&string);
                        MessageBox(NULL, string,string,0);
                        break;
                    default:
                        break;
                }
            };
        }
    };
    return 0;
}

相当するマネージ機能

Microsoft.SmartDevice.DeviceAgentTransport.IDeviceAgentTransport

必要条件

DeviceAgentTransport.h

参照

その他の技術情報

アンマネージ デバイス側スマート デバイス接続 API