Partager via


Synchronous Application Requirements (Windows Embedded CE 6.0)

1/6/2010

When using synchronous mode for the device-side component of your plug-in, there are several requirements that the device-side application must meet. In the synchronous mode of communication, the application only runs code when the desktop component sends a query for data to the device.

Native Mode Requirements

The following list explains the requirements that your application must meet when using native mode for the application.

  1. Implement a WinMain entry point.
    This function calls the StartCommandHandler method of the CDeviceRemoteTool object. This function blocks until the desktop-side component closes the command transport.
    The following code sample shows the WinMain entry point from the SimplePlugin sample.

    CDeviceRemoteTool g_DeviceRemoteTool;
    
    int WINAPI WinMain(
        HINSTANCE hInstance, 
        HINSTANCE hPrevInstance, 
        LPTSTR    lpCmdLine, 
        int       nCmdShow
        )
    {
        // The lpCmdLine must be left untouched
        g_DeviceRemoteTool.StartCommandHandler(
            lpCmdLine, 
            g_DeviceRemoteTool.COMMANDHANDLER_SYNC, 
            TestCallback
        );
        return (int) 0;
    }
    
  2. Implement a callback function.
    The StartCommandHandler method call specifies a callback function that is called each time that the application on the device receives a command packet. In this function, the code should use the command ID and parameters of the packet to run. After the tasks specified in the code have completed, the code must fill out the return command packet with data and then return a value of S_OK.
    The following code sample shows the callback function from the SimplePlugin sample.

    HRESULT STDAPICALLTYPE TestCallback(
        DWORD cmd, 
        const CCommandPacket* pCmdDataIn, 
        CCommandPacket* pCmdDataOut
    )
    {
        switch (cmd)
        {
        case 1:
            pCmdDataOut->AddParameterWORD ( 10 );
            pCmdDataOut->AddParameterDWORD ( 2000000 );
            pCmdDataOut->AddParameterString ( _T("My Plugin") );
    
            BYTE bytes[4]; 
            bytes[0] = 11; 
            bytes[1] = 22; 
            bytes[2] = 33; 
            bytes[3] = 44;
            pCmdDataOut->AddParameterBytes ( bytes, 4 );
            break;
        }
        return S_OK;
    }
    

Managed Mode Requirements

The following list explains the requirements that your application must meet if you have chosen to write an application that uses managed mode.

  1. Implement a Main entry point.
    This method must take the command-line prompt and pass the first argument into a constructor for the DeviceCommandTransport object. This object initiates an event when command packets arrive from the desktop. This method must also start the device command transport.
    The following code example shows how to start the device command transport.

    static void Main(string[] args)
    {
        m_commandTransport = new DeviceCommandTransport(args[0]);
        m_commandTransport.CommandPacketReceived +=
        new CommandPacketEventHandler(
            m_commandTransport_CommandPacketReceived
        );
        m_commandTransport.StartCommandHandlerSync();
    }
    
  2. Implement an event handler.
    This event handler is called whenever a command packet arrives from the desktop, and is the equivalent of the callback function in a synchronous application that uses native code.

    static void m_commandTransport_CommandPacketReceived(
        object sender,
        CommandPacketEventArgs e
        )
    {
    switch (e.CommandPacketIn.CommandId)
    {
        case 1:
            CommandPacket cp = new CommandPacket();
            cp.CommandId = 1;
            cp.AddParameterWORD(10);
            cp.AddParameterDWORD(100000);
            cp.AddParameterString("Hello, Managed World!");
            cp.AddParameterBytes(new byte[]{ 11, 22, 33, 44 });
            e.CommandPacketOut = cp;
            break;
        }
    }
    

See Also

Concepts

Requirements for Device-Side Components