#include "ltmm.h"
#include "ILMNetSnk2.h"
HRESULT AddNetTarget();
IltmmCapture *pCapture;
void ServerSide2_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();
IltmmCapture_GetSubObject (pCapture,ltmmCapture_Object_Sink, &pUnk);
if(pUnk)
{
ILMNetSnk* pSnk = NULL;
IUnknown_QueryInterface (pUnk,&IID_ILMNetSnk, (void**) &pSnk);
IUnknown_Release (pUnk);
if(pSnk)
{
long lUserCount;
BSTR UserName;
long i ;
long ID;
ILMNetSnkConnection* pcon;
//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_GetUsername (pSnk,i,&UserName);
//do something with the name
SysFreeString(UserName);
}
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_LastConnection(pSnk,&pcon);
// Check all connections with the server.
while(pcon)
{
ILMNetSnkConnection* pPrev;
BSTR bstr;
long id;
VARIANT_BOOL enabled;
ILMNetSnkConnection_get_PrevConnection (pcon,& pPrev);
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);
// check if this connection is enabled
if(enabled == VARIANT_FALSE)
{
//if the connection is disabled
//close this connection OPTIONAL
ILMNetSnkConnection_Close (pcon);
}
ILMNetSnkConnection_Release(pcon);
pcon = pPrev;
}
{//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.
ILMNetSnk_AddRestriction (pSnk,bstrAddress,&lRestrictionCount);
SysFreeString(bstrAddress);
// get Number of restriction
ILMNetSnk_get_RestrictionCount (pSnk ,&lRestrictionCount);
}//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);
}
ILMNetSnk_CloseAll(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