The Server Side 2 Example for C++

#include "ltmm.h" 
#include "ILMNetSnk2.h" 
 
HRESULT AddNetTarget(); 
IltmmCapture *pCapture;  
void main() 
{ 
   BSTR sUser;  
   BSTR sPassword;  
   long lIndex = 0;  
   long lOldConversion;  
   long lConversion; 
   long lCount = 0;  
   CoInitialize(NULL);  
   HRESULT hr = CoCreateInstance(CLSID_ltmmCapture, NULL, CLSCTX_INPROC_SERVER, IID_IltmmCapture, (void**) &pCapture);  
   if(FAILED(hr))  
   { 
      AfxMessageBox(TEXT("Can't instantiate capture library")); 
      return;  
   } 
   AddNetTarget(); 
   pCapture->EditGraph(); 
 
   IUnknown* pUnk = NULL;  
    
   pCapture->GetSubObject(ltmmCapture_Object_Sink, &pUnk);  
   if(pUnk)  
   { 
      ILMNetSnk* pSnk = NULL;  
      pUnk->QueryInterface(IID_ILMNetSnk, (void**) &pSnk);  
      pUnk->Release(); 
      if(pSnk)  
      { 
         //Require login with user name and password from the client.  
         pSnk->put_RequireLogin(VARIANT_TRUE);  
         //Get The current connection version.  
         pSnk->get_ConnectionVersion(&lOldConversion);  
         sUser     = SysAllocString(L"User1"); 
         sPassword = SysAllocString(L"P12345"); 
         // add User1 to the server with the password "P12345" 
         pSnk->AddUser(sUser, sPassword, &lIndex);  
         // Free the user name and the password 
         SysFreeString(sUser);  
         SysFreeString(sPassword);  
         pSnk->get_ConnectionVersion(&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" 
         pSnk->AddUser(sUser, sPassword, &lIndex);  
 
         // Free the user name and the password 
         SysFreeString(sUser);  
         SysFreeString(sPassword);  
 
         long lUserCount;  
         // get the count of registered user 
         pSnk->get_UserCount(&lUserCount);  
 
         BSTR UserName;  
         for (long i = 0 ; i < lUserCount ; i++) 
         { 
 
            pSnk->GetUsername(i,&UserName);  
            //do something with the name 
            SysFreeString(UserName);  
         } 
 
         UserName = SysAllocString(L"User2");; 
          
         //Find the ID of a given user 
         long ID;  
         pSnk->FindUser(UserName,&ID);  
         //change the password for the user ID.  
         sPassword = SysAllocString(L"XYZ0"); 
         pSnk->SetPassword(ID,sPassword);  
         SysFreeString(UserName);  
         SysFreeString(sPassword);     
         //get number of connections connected to the server. 
         pSnk->get_ConnectionCount(&lCount);    
         ILMNetSnkConnection* pcon;  
         pSnk->FindConnection(1, &pcon);  
         pcon->Release(); 
         pSnk->get_LastConnection(&pcon);  
        // Check all connections with the server.  
         while(pcon)  
         { 
            ILMNetSnkConnection* pPrev;  
            BSTR bstr;  
            pcon->get_PrevConnection(&pPrev);  
            long id;  
            pcon->get_ID(&id);  
            pcon->get_Username(&bstr); 
            ::SysFreeString(bstr); 
            pcon->get_Address(&bstr); 
            //Enable the connection 
            pcon->put_Enabled(VARIANT_TRUE); 
            //Check if connection is enabled or not.  
            VARIANT_BOOL enabled;  
            pcon->get_Enabled(&enabled);  
            // check if this connection is enabled 
            if(enabled == VARIANT_FALSE)  
            { 
               //if the connection is disabled 
               //close this connection OPTIONAL 
               pcon->Close(); 
            } 
            pcon->Release(); 
            pcon = pPrev;  
         } 
 
         //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;  
         pSnk->AddRestriction(bstrAddress,&lRestrictionCount);  
         SysFreeString(bstrAddress);     
 
         // get Number of restriction 
         pSnk->get_RestrictionCount(&lRestrictionCount);  
         // Remove User2 from the registered users list.  
         UserName = SysAllocString(L"User2"); 
         pSnk->FindUser(UserName,&ID);  
         pSnk->RemoveUser(ID);  
         SysFreeString(UserName); 
      } 
      pSnk->CloseAll(); 
      pSnk->Release(); 
   } 
} 
 
HRESULT AddNetTarget() 
{ 
   IltmmTargetFormats* formats;  
   HRESULT hr;  
    
   hr = pCapture->get_TargetFormats(&formats);  
   if(FAILED(hr))  
      return hr;  
   BSTR bstr = SysAllocString(L"Net Server Target"); 
   if(!bstr)  
   { 
      formats->Release(); 
      return E_OUTOFMEMORY;  
   } 
    
   long index;  
    
   hr = formats->Find(bstr, &index);  
   if(FAILED(hr))  
   { 
      formats->Release(); 
      SysFreeString(bstr);  
      return hr;  
   } 
   if(index == -1)  
   {      
      hr = formats->Add(bstr, -1);  
      SysFreeString(bstr);  
      if(FAILED(hr))  
      { 
         formats->Release(); 
         return hr;  
      } 
      long count;  
      hr = formats->get_Count(&count);  
      if(FAILED(hr))  
      { 
         formats->Release(); 
         return hr;  
      } 
      index = count - 1;  
      IltmmTargetFormat* format;  
      hr = formats->Item(index, &format);  
      if(FAILED(hr))  
      { 
         formats->Release(); 
         return hr;  
      } 
      bstr = SysAllocString(L"@device:sw:{083863F1-70DE-11D0-BD40-00A0C911CE86}\\{E2B7DE05-38C5-11D5-91F6-00104BDB8FF9}"); 
      if(!bstr)  
      { 
         format->Release(); 
         formats->Remove(index);  
         formats->Release(); 
         return E_OUTOFMEMORY;  
      } 
      hr = format->put_Sink(bstr);  
      SysFreeString(bstr);  
      if(FAILED(hr))  
      { 
         format->Release(); 
         formats->Remove(index);  
         formats->Release(); 
         return hr;  
      } 
       
      bstr = SysAllocString(L"@device:sw:{083863F1-70DE-11D0-BD40-00A0C911CE86}\\{E2B7DE01-38C5-11D5-91F6-00104BDB8FF9}"); 
      if(!bstr)  
      { 
         format->Release(); 
         formats->Remove(index);  
         formats->Release(); 
         return E_OUTOFMEMORY;  
      } 
      hr = format->put_Mux(bstr);  
      SysFreeString(bstr);  
      if(FAILED(hr))  
      { 
         format->Release(); 
         formats->Remove(index);  
         formats->Release(); 
         return hr;  
      } 
      format->Release(); 
   } 
   else 
   { 
      SysFreeString(bstr);  
   } 
   formats->Release(); 
   return S_OK;  
} 
Help Version 23.0.2024.2.29
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS Multimedia C API Help
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.