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;  
   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)  
      { 
         VARIANT_BOOL vbBool;  
         pSnk ->get_RequireLogin (& vbBool);  
         //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; 
         BSTR Password; 
         for (long i = 0 ; i < lUserCount ; i++) 
         { 
            pSnk->GetPassword (i,&Password); 
            //do something with the password 
            //.............................. 
            pSnk->GetUsername (i,&UserName); 
            //do something with the name 
            //.............................. 
            SysFreeString(UserName); 
            SysFreeString(Password); 
         } 
 
         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_FirstConnection (&pcon); 
         // Check all connections with the server. 
         while(pcon) 
         { 
            ILMNetSnkConnection* pnext; 
            BSTR bstr; 
            pcon->get_NextConnection(&pnext); 
            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); 
            VARIANT_BOOL connected; 
            pcon->get_Connected(&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 
               pcon->Close (); 
            } 
            pcon->Release(); 
            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; 
         pSnk->AddRestriction(bstrAddress,&lRestrictionCount); 
         SysFreeString(bstrAddress);     
 
         // get Number of restriction 
         pSnk->get_RestrictionCount (&lRestrictionCount); 
 
         for(int i = 0 ; i < lRestrictionCount ; i++) 
         { 
            BSTR bstrRestriction; 
            pSnk->GetRestriction (i,&bstrRestriction); 
            // do something with Restriction 
            //.............................. 
            //free the Restriction name 
            SysFreeString(bstrRestriction); 
         } 
 
         long lRestriction; 
         pSnk->FindRestriction (bstrAddress,&lRestriction); 
 
         // Remove the Restriction from the user 
         pSnk->RemoveRestriction (lRestriction); 
 
         // Remove User2 from the registered users list. 
         UserName = SysAllocString(L"User2"); 
         pSnk->FindUser (UserName,&ID); 
         pSnk->RemoveUser(ID); 
         SysFreeString(UserName);     
         //Remove all restrctions 
         pSnk->RemoveAllRestrictions ();    
         pSnk->CloseAll (); 
         pSnk->RemoveAllUsers();     
      } 
      pUnk->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.