InetReceiveCmd2 Example for C++ 5.0 and later

Note: This is not a complete example for handling events, some steps have been omitted. For a complete example of how to handle events, refer to the example Initializing a Computer as a Server and Accepting Connections.

// my user defined commands
#define INETCMD_FLIP INETCMD_USER_CUSTOM


void CRasterInetSink::OnInetReceiveCmd2(short iComputer, short InetCommand, long nCommandID, short nError, struct ILEADRasterInetPacket * Params, long nExtraDataSize, const _variant_t & ExtraData)
{
   short nStatus;
   CString szOut;
   CString szTmp;
   ILEADRasterInetPacket *Packet = Params;
   short nRet;

   nStatus = ERROR_FEATURE_NOT_SUPPORTED;

   szOut.Format(TEXT("Command %d id=%d, nError=%d nParams=%d received"),
InetCommand, nCommandID, nError, Packet->GetParamCount());

   if(nExtraDataSize > 0)
   {
      szTmp.Format(TEXT(", nExtraDataSize=%d"), nExtraDataSize);
      szOut = szOut + szTmp;
   }
   OutputDebugString(szOut);
   OutputDebugString(TEXT("\n"));

   if(nError != 0)
      nStatus = ERROR_TRANSFER_ABORTED;
   else
   {
      switch(InetCommand)
      {
         case INETCMD_LOAD:
            // check the validity of the parameters
            if((Packet->GetParamCount() == 4) && (Packet->GetParamType(0) == PARAM_TYPE_STRING) &&
(Packet->GetParamType(1) == PARAM_TYPE_INT32) && (Packet->GetParamType(2) == PARAM_TYPE_INT32) &&
(Packet->GetParamType(3) == PARAM_TYPE_UINT32))
            {
               //NOTE: this is a function you must create
               nStatus = ProcessLoadCommand(Packet->GetParamValue(0).bstrVal, (short)Packet->GetParamValue(1).lVal);
               if(nStatus != 0)
                  nStatus = ERROR_INV_PARAMETER; // invalid parameters
               m_pDlg->m_pRasterInet->InetSendLoadRsp2(nCommandID, 0, 0, NULL, nStatus);
               return;
            }
         break;

         case INETCMD_CREATE_WIN:
            // check the validity of the parameters
            if((Packet->GetParamCount() == 8) && (Packet->GetParamType(0) == PARAM_TYPE_STRING) &&
(Packet->GetParamType(1) == PARAM_TYPE_STRING) && (Packet->GetParamType(2) == PARAM_TYPE_UINT32) &&
(Packet->GetParamType(3) == PARAM_TYPE_INT32) && (Packet->GetParamType(4) == PARAM_TYPE_INT32) &&
(Packet->GetParamType(5) == PARAM_TYPE_INT32) && (Packet->GetParamType(6) == PARAM_TYPE_INT32) &&
(Packet->GetParamType(7) == PARAM_TYPE_UINT32))
            {
               long nWindowID;
               //NOTE: this is a function you must create
               nWindowID = ProcessCreateWinCommand(Packet->GetParamValue(1).bstrVal,
Packet->GetParamValue(3).lVal,
Packet->GetParamValue(4).lVal,
Packet->GetParamValue(5).lVal,
Packet->GetParamValue(6).lVal);

               nRet = m_pDlg->m_pRasterInet->InetSendCreateWinRsp2(nCommandID, nWindowID, 0, NULL, 0);
               return;
            }
         break;

         case INETCMD_ATTACH_BITMAP:
            if((Packet->GetParamCount() == 2) && (Packet->GetParamType(0) == PARAM_TYPE_UINT32) &&
(Packet->GetParamType(1) == PARAM_TYPE_UINT32))
            {
               //NOTE: this is a function you must create
               nStatus = ProcessAttachBitmapCommand(Packet->GetParamValue(0).ulVal,
Packet->GetParamValue(1).ulVal);
               nRet = m_pDlg->m_pRasterInet->InetSendAttachBitmapRsp2(nCommandID, 0, NULL, nStatus);
               return;
            }
         break;

         case INETCMD_SAVE:
            if((Packet->GetParamCount() == 6) && (Packet->GetParamType(0) == PARAM_TYPE_STRING) &&
(Packet->GetParamType(1) == PARAM_TYPE_UINT32) && (Packet->GetParamType(2) == PARAM_TYPE_INT32) &&
(Packet->GetParamType(3) == PARAM_TYPE_INT32) && (Packet->GetParamType(4) == PARAM_TYPE_INT32) &&
(Packet->GetParamType(5) == PARAM_TYPE_UINT32))
            {
               //NOTE: this is a function you must create
               nStatus = ProcessSaveCommand(Packet->GetParamValue(0).bstrVal,
Packet->GetParamValue(1).ulVal,
Packet->GetParamValue(2).lVal,
Packet->GetParamValue(3).lVal,
Packet->GetParamValue(4).lVal,
Packet->GetParamValue(5).ulVal);

               nRet = m_pDlg->m_pRasterInet->InetSendSaveRsp2(nCommandID, 0, NULL, nStatus);
               return;
            }
            else
               nStatus = ERROR_INV_PARAMETER;
         break;

         case INETCMD_FLIP:
            if((Packet->GetParamCount() == 1) && (Packet->GetParamType(0) == PARAM_TYPE_UINT32))
                  //NOTE: this is a function you must create
               nStatus = ProcessFlipCommand(Packet->GetParamValue(0).ulVal);
            else
               nStatus = ERROR_INV_PARAMETER;
         break;
      }
   }
   //return an error response
   m_pDlg->m_pRasterInet->InetSendRsp2((InetCmdType)InetCommand, nCommandID, NULL, 0, NULL, nStatus);
}