Is this page helpful?
#include "ltmm.h"
#include "ILMNetSnk2.h"
HRESULT AddNetTarget();
IltmmCapture *pCapture;
void ServerSide_Example ( )
{
BSTR sUser;
BSTR sPassword;
long lIndex = 0;
long lCount = 0;
long lOldConversion;
long lConversion;
HRESULT hr;
IUnknown* pUnk = NULL;
CoInitialize(NULL);
hr = CoCreateInstance(&CLSID_ltmmCapture, NULL, CLSCTX_INPROC_SERVER, &IID_IltmmCapture, (void**) &pCapture);
if(FAILED(hr))
{
//AfxMessageBox("Can't instantiate capture library");
return;
}
AddNetTarget();
//USES_CONVERSION;
IltmmCapture_GetSubObject (pCapture,ltmmCapture_Object_Sink, &pUnk);
if(pUnk)
{
ILMNetSnk* pSnk = NULL;
IUnknown_QueryInterface(pUnk,&IID_ILMNetSnk, (void**) &pSnk);
IUnknown_Release(pUnk);
if(pSnk)
{
VARIANT_BOOL vbBool;
long lUserCount;
BSTR UserName;
BSTR Password;
long i;
long ID;
ILMNetSnkConnection* pcon;
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);
// get the count of registered user
ILMNetSnk_get_UserCount (pSnk,&lUserCount);
for (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
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);
ILMNetSnk_FindConnection (pSnk,1, &pcon);
ILMNetSnkConnection_Release(pcon);
ILMNetSnk_get_FirstConnection(pSnk,&pcon);
// Check all connections with the server.
while(pcon)
{
ILMNetSnkConnection* pnext;
BSTR bstr;
long id;
VARIANT_BOOL enabled;
VARIANT_BOOL connected;
ILMNetSnkConnection_get_NextConnection(pcon,&pnext);
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);
// Check if the connection is enabled
ILMNetSnkConnection_get_Enabled(pcon,&enabled);
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
BSTR bstrAddress = SysAllocString(L"10.0.0.5"); //this will not allow him to connect to the server.
long lRestrictionCount = 0; // Number of restrictions we have.
long lRestriction ;
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);
}
ILMNetSnk_FindRestriction(pSnk , bstrAddress, &lRestriction);
// Remove the Restriction from the user
ILMNetSnk_RemoveRestriction(pSnk, lRestriction);
}//add a restriction to the client which has the IP = 10.0.0.5
// 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;
BSTR bstr ;
long index;
hr = IltmmCapture_get_TargetFormats(pCapture, &formats);
if(FAILED(hr))
return hr;
bstr = SysAllocString(L"Net Server Target");
if(!bstr)
{
IltmmTargetFormats_Release(formats);
return E_OUTOFMEMORY;
}
hr = IltmmTargetFormats_Find(formats, bstr, &index);
if(FAILED(hr))
{
IltmmTargetFormats_Release(formats);
SysFreeString(bstr);
return hr;
}
if(index == -1)
{
long count;
IltmmTargetFormat* format;
hr = IltmmTargetFormats_Add(formats, bstr, -1);
SysFreeString(bstr);
if(FAILED(hr))
{
IltmmTargetFormats_Release(formats);
return hr;
}
hr = IltmmTargetFormats_get_Count(formats, &count);
if(FAILED(hr))
{
IltmmTargetFormats_Release(formats);
return hr;
}
index = count - 1;
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;
}
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document