InetSendCmd2 Example for C++ 5.0 and later

// my user defined commands
#define INETCMD_FLIP INETCMD_USER_CUSTOM

short nRet;
CString csOut;
ILEADRasterInetPacket *pPacket=NULL;
TCHAR szText[]=TEXT("This is Flip");
VARIANT var;
SAFEARRAY FAR *psa;
SAFEARRAYBOUND rgsabound[1];
VARIANT vaVal;
HRESULT hr;

hr = CoCreateInstance(CLSID_LEADRasterInetPacket, NULL, CLSCTX_ALL, IID_ILEADRasterInetPacket, (void**)&pPacket);

pPacket->put_ParamCount(1);
VariantInit(&vaVal);
V_VT(&vaVal) = (VT_UI4);
V_UI4(&vaVal) = 999;
pPacket->put_ParamValue(0, vaVal);
pPacket->put_ParamType(0, PARAM_TYPE_UINT32);

VariantInit(&var);
rgsabound[0].lLbound = 0;
rgsabound[0].cElements = lstrlen(szText) + 1;

psa = SafeArrayCreate(VT_UI1, 1, rgsabound);
if (psa != NULL)
{
   SafeArrayLock(psa);
   lstrcpy((char far *)psa->pvData, szText);
   SafeArrayUnlock(psa);
   V_VT(&var) = (VT_ARRAY | VT_UI1);
   V_ARRAY(&var) = psa;

   nRet = m_pRasterInet->InetSendCmd2(INETCMD_FLIP, 999, pPacket, lstrlen(szText) + 1, &var);

   if((nRet != 0) && (nRet != ERROR_DATA_QUEUED))
   {
      csOut.Format(TEXT("ERROR %d calling InetSendCmd2.\n"), nRet);
      OutputDebugString(csOut);
   }
   else
      OutputDebugString(TEXT("InetSendCmd2 executed.\n"));
   }
pPacket->Release();