The Server Side Example for C

#include "ltmm.h"
#include "ILMNetSnk2.h"

HRESULT AddNetTarget();
IltmmCapture *pCapture; 

void main()
{
   BSTR sUser; 
   BSTR sPassword; 
   long lIndex = 0; 
   BSTR szFileName; 
   Long lCount = 0; 
   long lOldConversion; 
   long lConversion; 

   CoInitialize(NULL); 
   HRESULT hr = CoCreateInstance(CLSID_ltmmCapture, NULL, CLSCTX_INPROC_SERVER, IID_IltmmCapture, (void**) &pCapture); 
   if(FAILED(hr)) 
   {
      //AfxMessageBox("Can't instantiate capture library");
      return; 
   }
   AddNetTarget();

   IUnknown* pUnk = NULL; 
   //USES_CONVERSION; 
   IltmmCapture_GetSubObject (pCapture,ltmmCapture_Object_Sink, &pUnk); 
   if(pUnk) 
   {
      ILMNetSnk* pSnk = NULL; 
      pUnk->QueryInterface(IID_ILMNetSnk, (void**) &pSnk); 
      pUnk->Release();
      if(pSnk) 
      {
          VARIANT_BOOL vbBool; 
           ILMNetSnk__get_RequireLogin(pSnk,& vbBool); 
         //Require login with user name and password from the client. 
         ILMNetSnk__put_RequireLogin(pSnk,VARIANT_TRUE); 
         //Get The current connection version. 
         ILMNetSnk__get_ConnectionVersion(pSnk,&lOldConversion); 
         sUser     = SysAllocString(L"User1");
         sPassword = SysAllocString(L"P12345");
         // add User1 to the server with the password "P12345"
         ILMNetSnk_AddUser(pSnk,sUser, sPassword, &lIndex); 
         // Free the user name and the password
         SysFreeString(sUser); 
         SysFreeString(sPassword); 
         ILMNetSnk_get_ConnectionVersion (pSnk,&lConversion); 
         if(lConversion != lOldConversion) 
         {
            // the version number is updated after adding User1
         }
         sUser     = SysAllocString(L"User2");
         sPassword = SysAllocString(L"ABC123");
         // add User2 to the server with the password "ABC123"
         ILMNetSnk_AddUser (pSnk,sUser, sPassword, &lIndex); 

         // Free the user name and the password
         SysFreeString(sUser); 
         SysFreeString(sPassword); 

         long lUserCount; 
         // get the count of registered user
         ILMNetSnk_get_UserCount (pSnk,&lUserCount); 

         BSTR UserName; 
         BSTR Password;
        for (long i = 0 ; i < lUserCount ; i++)
        {
          ILMNetSnk__getPassword(pSnk, i, &Password);
           //do something with the password
           //..............................
           ILMNetSnk__getUsername(pSnk, i, &UserName);
           //do something with the name
           //..............................
           SysFreeString(UserName);
           SysFreeString(Password);
        }

         UserName = SysAllocString(L"User2");;
         
         //Find the ID of a given user
         long ID; 
         ILMNetSnk_FindUser(pSnk,UserName,&ID); 
         //change the password for the user ID. 
         sPassword = SysAllocString(L"XYZ0");
         ILMNetSnk_SetPassword(pSnk,ID,sPassword); 
         SysFreeString(UserName); 
         SysFreeString(sPassword);    
         
         //get number of connections connected to the server. 
        ILMNetSnk_get_ConnectionCount (pSnk ,&lCount);   

         ILMNetSnkConnection* pcon; 
         ILMNetSnk_FindConnection (pSnk,1, &pcon); 
         pcon->Release();
         ILMNetSnk__get_FirstConnection(pSnk,&pcon); 
         // Check all connections with the server. 
         while(pcon) 
         {
            ILMNetSnkConnection* pnext; 
            BSTR bstr; 
            ILMNetSnkConnection__get_NextConnection(pcon,&pnext); 
            long id; 
            ILMNetSnkConnection__get_ID(pcon,&id); 
            ILMNetSnkConnection__get_Username (pcon,&bstr);                
            ::SysFreeString(bstr); 
            ILMNetSnkConnection__get_Address(pcon,&bstr); 
   // Enable the connection
            ILMNetSnkConnection__put_Enabled (pcon ,VARIANT_TRUE); 
            VARIANT_BOOL enabled; 
            // Check if the connection is enabled
ILMNetSnkConnection__get_Enabled
(pcon,&enabled); 
            VARIANT_BOOL connected;
           ILMNetSnkConnection__get_Connected(pcon,&connected);
           // check if this connection is disabled or not connected
           if(enabled == VARIANT_FALSE || connected == VARIANT_FALSE)
            {
               //if the connection is disabled
               //close this connection OPTIONAL
               ILMNetSnkConnection_Close(pcon); 
            }
            ILMNetSnkConnection_Release(pcon); 
            pcon = pnext; 
         }

         //add a restriction to the client which has the IP = 10.0.0.5
         //this will not allow him to connect to the server. 
         BSTR bstrAddress = SysAllocString(L"10.0.0.5");
         // Number of restrictions we have. 
         long lRestrictionCount = 0; 
         ILMNetSnk_AddRestriction (pSnk,bstrAddress,&lRestrictionCount); 
         SysFreeString(bstrAddress);    

         // get Number of restriction
        ILMNetSnk_get_RestrictionCount(pSnk ,&lRestrictionCount); 
       for(i = 0 ; i < lRestrictionCount ; i++)
       {
          BSTR bstrRestriction;
          ILMNetSnk__getRestriction(pSnk, i, &bstrRestriction);
          // do something with Restriction
          //..............................
          //free the Restriction name
          SysFreeString(bstrRestriction);
       }

       long lRestriction ;
       ILMNetSnk_FindRestriction(pSnk , bstrAddress, &lRestriction);

       // Remove the Restriction from the user
       ILMNetSnk_RemoveRestriction(pSnk, lRestriction);

         // Remove User2 from the registered users list. 
         UserName = SysAllocString(L"User2");
         ILMNetSnk_FindUser (pSnk,UserName,&ID); 
         ILMNetSnk_RemoveUser(pSnk,ID); 
         SysFreeString(UserName);    
         //Remove all restrctions 
         ILMNetSnk_RemoveAllRestrictions(pSnk);   
        ILMNetSnk_CloseAll(pSnk);
        ILMNetSnk_RemoveAllUsers(pSnk);

      }
      ILMNetSnk_Release(pSnk);         
   }
}
HRESULT AddNetTarget()
{
   IltmmTargetFormats* formats; 
   HRESULT hr; 
   
   hr = IltmmCapture__get_TargetFormats(pCapture, &formats); 
   if(FAILED(hr)) 
      return hr; 
   BSTR bstr = SysAllocString(L"Net Server Target");
   if(!bstr) 
   {
      IltmmTargetFormats_Release(formats); 
      return E_OUTOFMEMORY; 
   }
   
   long index; 
   
   hr = IltmmTargetFormats_Find(formats, bstr, &index); 
   if(FAILED(hr)) 
   {
      IltmmTargetFormats_Release(formats); 
      SysFreeString(bstr); 
      return hr; 
   }
   if(index == -1) 
   {     
      hr = IltmmTargetFormats_Add(formats, bstr, -1); 
      SysFreeString(bstr); 
      if(FAILED(hr)) 
      {
         IltmmTargetFormats_Release(formats); 
         return hr; 
      }
      long count; 
      hr = IltmmTargetFormats__get_Count(formats, &count); 
      if(FAILED(hr)) 
      {
         IltmmTargetFormats_Release(formats); 
         return hr; 
      }
      index = count - 1; 
      IltmmTargetFormat* format; 
      hr = IltmmTargetFormats_Item(formats, index, &format); 
      if(FAILED(hr)) 
      {
         IltmmTargetFormats_Release(formats); 
         return hr; 
      }
      bstr = SysAllocString(L"@device:sw:{083863F1-70DE-11D0-BD40-00A0C911CE86}\\{E2B7DE05-38C5-11D5-91F6-00104BDB8FF9}");
      if(!bstr) 
      {
         IltmmTargetFormat_Release(format); 
         IltmmTargetFormats_Remove(formats, index); 
         IltmmTargetFormats_Release(formats); 
         return E_OUTOFMEMORY; 
      }
      hr = IltmmTargetFormat__put_Sink(format, bstr); 
      SysFreeString(bstr); 
      if(FAILED(hr)) 
      {
         IltmmTargetFormat_Release(format); 
         IltmmTargetFormats_Remove(formats, index); 
         IltmmTargetFormats_Release(formats); 
         return hr; 
      }
      
      bstr = SysAllocString(L"@device:sw:{083863F1-70DE-11D0-BD40-00A0C911CE86}\\{E2B7DE01-38C5-11D5-91F6-00104BDB8FF9}");
      if(!bstr) 
      {
         IltmmTargetFormat_Release(format); 
         IltmmTargetFormats_Remove(formats, index); 
         IltmmTargetFormats_Release(formats); 
         return E_OUTOFMEMORY; 
      }
      hr = IltmmTargetFormat__put_Mux(format, bstr); 
      SysFreeString(bstr); 
      if(FAILED(hr)) 
      {
         IltmmTargetFormat_Release(format); 
         IltmmTargetFormats_Remove(formats, index); 
         IltmmTargetFormats_Release(formats); 
         return hr; 
      }
      IltmmTargetFormat_Release(format); 
   }
   else
   {
      SysFreeString(bstr); 
   }
   IltmmTargetFormats_Release(formats); 
   return S_OK; 
}