License Holder Example for C++

class CLicenseHolder 
{ 
protected: 
   CComPtr<IltmsLicenseManager> m_licmgr; 
   BOOL m_service; 
   BOOL m_verbose; 
   CString m_title; 
 
   BOOL IsDisplayEnabled(void) 
   { 
      return (m_verbose && !m_service); 
   } 
 
   int DisplayLicenseError(LPCTSTR message) 
   { 
      return ::MessageBox(NULL, message, m_title, MB_OK | MB_ICONERROR); 
   } 
 
public: 
   CLicenseHolder(BOOL verbose = TRUE, LPCTSTR title = _T("LEAD Media Server")) : m_service(FALSE), m_verbose(verbose), m_title(title) 
   { 
 
      HWINSTA hWindowStation = GetProcessWindowStation(); 
      USEROBJECTFLAGS flags; 
      DWORD dwLength = 0; 
      GetUserObjectInformation(hWindowStation, UOI_FLAGS, (PVOID)&flags, sizeof(USEROBJECTFLAGS), &dwLength); 
      if(!(flags.dwFlags & WSF_VISIBLE)) 
         m_service = TRUE; 
   } 
 
   virtual ~CLicenseHolder() 
   { 
   } 
 
   HRESULT LoadLicenseManager(void) 
   { 
      if(!m_licmgr) 
      { 
         HRESULT hr; 
         hr = CoCreateInstance(__uuidof(ltmsLicenseManager), NULL, CLSCTX_ALL, __uuidof(IltmsLicenseManager), (void**) &m_licmgr); 
         if(FAILED(hr)) 
         { 
            if(IsDisplayEnabled()) 
            { 
               DisplayLicenseError(_T("Cannot instantiate LEADTOOLS Media Streaming License Manager")); 
            } 
            return hr;      
         } 
      } 
      return S_OK; 
   } 
 
   HRESULT SetLicense(LPCTSTR license = _T("%ltmsAppFolder%\\LEADTOOLS.LIC"), LPCTSTR key = _T("%ltmsAppFolder%\\LEADTOOLS.LIC.KEY"), LONG flags = ltmsSetLicenseFlags_LicenseIsFile | ltmsSetLicenseFlags_KeyIsFile) 
   { 
      HRESULT hr; 
      hr = LoadLicenseManager(); 
      if(FAILED(hr)) 
         return hr; 
      hr = m_licmgr->SetLicense(CComBSTR(license), CComBSTR(key), flags); 
      if(FAILED(hr)) 
      { 
         if(IsDisplayEnabled()) 
         { 
            DisplayLicenseError(_T("Your license file is missing, invalid or expired. The LEADTOOLS Media Streaming Library will not function. Please contact LEAD Sales for information on obtaining a valid license.")); 
            ShellExecute(NULL, _T("open"), _T("https://www.leadtools.com/downloads/evaluation-form.asp?evallicenseonly=true"), NULL, NULL, 1); 
         } 
         return hr; 
      } 
      return S_OK; 
   } 
 
   void UnloadLicenseManager(void) 
   { 
      m_licmgr = NULL; 
   } 
}; 
Help Version 22.0.2022.12.7
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.

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