REND.CPP

/*++ 

Copyright (c) 1995 Microsoft Corporation

Module Name:

rend.cpp

Abstract:

This demonstrates how to use TAPI 3.0 Rendezvous Controls APIs to :
. initialize conference directory, get directory server name and path,
. create a conference, get a conference, and delete a conference,
. and enumerate conferences.

Notes:

1. Build the program, and the exe is obj\*\rend.exe
2. To run it, type "rend" on the command line.
3. The directory server and path should be specified in registry:
HKLM\Software\Microsoft\Windows\CurentVersion\Dynamic Directory
as "ServerName" (REG_SZ), and "DirectoryPath" (REG_SZ)

Author:

Bin Li 17-Aug-1997

Revision History:

dd-mmm-yyyy <email>

--*/

///////////////////////////////////////////////////////////////////////////////
// //
// include //
// //

#include <windows.h>
#include <objbase.h>
#include <stdio.h>
#include <oleauto.h>
#include <rend.h>

///////////////////////////////////////////////////////////////////////////////
// //
// define //
// //

#define MAX_STRING_LENGTH255
#define MAX_NUM_CONFERENCES5
#define CONF_NAME_PREFIXL"Rendezvous Controls Sample Program - CONFERENCE No. "

#define RETURN_ON_FAILURE_NODIR(hr) \
{if (FAILED(hr)) { wprintf(L"Error 0x%x\n", hr); return hr; } }

#define RETURN_ON_FAILURE_DIR(hr)\
{if (FAILED(hr)) \
{ wprintf(L"Error 0x%x\n", hr);\
pITDir->Release(); \
return hr; \
} \
}


///////////////////////////////////////////////////////////////////////////////
// //
// functions //
// //


///////////////////////////////////////////////////////////////////////////////
// //
// main //
// //

INT _CRTAPI1
main()
{
ITConferenceDirectory*pITDir;
BSTRbszConfName[MAX_NUM_CONFERENCES];

/*
* 1. initialize conference directory server and path
*/

wprintf(L"\n\nInitialize conference directory ...\n");

::CoInitialize( NULL );

// query for conference directory interface
HRESULT hr = ::CoCreateInstance(CLSID_ConferenceDirectory,
NULL,
CLSCTX_INPROC_SERVER,
IID_ITConferenceDirectory,
(void **)&pITDir
);

RETURN_ON_FAILURE_NODIR( hr );

// initialize conference directory with default values in registry
// you can also specify different directoy server or path by replacing
// "NULL" with the respective name or path
hr = pITDir->Init( NULL, NULL );

RETURN_ON_FAILURE_NODIR( hr );

BSTR bszServer = NULL;
BSTR bszDirPath = NULL;

// query the server name
hr = pITDir->get_ServerName( &bszServer );
RETURN_ON_FAILURE_DIR( hr );

// query the directoy path
hr = pITDir->get_DirectoryPath( &bszDirPath );
RETURN_ON_FAILURE_DIR( hr );

wprintf(L"\tServer = %s\tDirectoryPath=%s\n",
bszServer, bszDirPath);

::SysFreeString( bszServer );
::SysFreeString( bszDirPath );


/*
* 2. create conferences
*/

wprintf(L"Create conference ...\n");
for (int i = 0; i < MAX_NUM_CONFERENCES; i ++)
{
WCHARtszConfName[MAX_STRING_LENGTH];

swprintf( tszConfName, L"%s%d",CONF_NAME_PREFIX,i );
bszConfName[i] = ::SysAllocString( tszConfName );

ITConference*pITConf;

// to ensure a successful creating, delete it first in case a same
// name conference already exists
hr = pITDir->DeleteConference( bszConfName[i] );

wprintf(L"\t%s", bszConfName[i]);
hr = pITDir->CreateConference( bszConfName[i], &pITConf );

RETURN_ON_FAILURE_DIR( hr );

// release the interface, as we don't need it now
// also, (RefCount == 0) will cause the conferenc blob to be written
// to the ILS server
pITConf->Release();

wprintf(L"\n");
}

/*
* 3. enumerate conferences
*/

// set a filter used for enumeration to limit the set of conferences
// that will be enumerated.
// if no filter is set, all conferences will be retrieved

WCHARtszFilter[MAX_STRING_LENGTH];

swprintf( tszFilter, L"uid=%s*", CONF_NAME_PREFIX );
BSTRbszFilter = SysAllocString( tszFilter );

wprintf(L"Set a filter \"%s\" ...", bszFilter );
hr = pITDir->put_Filter( bszFilter );

::SysFreeString( bszFilter );

RETURN_ON_FAILURE_DIR( hr );
wprintf(L"\n");

// get the enumerator
IEnumVARIANT*pIEnumConf;

wprintf(L"Get an enumerator ...");
hr = pITDir->get__NewEnum( (IUnknown **) &pIEnumConf );

RETURN_ON_FAILURE_DIR( hr );
wprintf(L"\n");

// enumerate each conference
wprintf(L"Enumerate conference ...\n");
i = 0;
do
{
VARIANTvarITConf;
ULONGcConferencesGet;

// initialization is required for NT5 Beta-1
::VariantInit( &varITConf );

wprintf(L"\t%d - ", i);
hr = pIEnumConf->Next(1, &varITConf, &cConferencesGet);

if ( SUCCEEDED(hr) && (hr != S_FALSE) )
{
ITConference*pITConference = (ITConference *)
V_DISPATCH( &varITConf );
BSTR bConfNameGet = NULL;

hr = pITConference->get_Name( &bConfNameGet );

pITConference->Release();

RETURN_ON_FAILURE_DIR( hr );

wprintf(L"%s\n", bConfNameGet);
::SysFreeString( bConfNameGet );
i = i + 1;
}
}
while ( SUCCEEDED(hr) && (hr != S_FALSE) );

pIEnumConf->Release();

RETURN_ON_FAILURE_DIR( hr );

wprintf(L"\n");

/*
* 4. get and delete conferences
*/

wprintf(L"Get then delete conference ...\n");
for (i = 0; i < MAX_NUM_CONFERENCES; i ++)
{
// get a conference
ITConference*pITConf;

wprintf(L"\t%d - %s", i, bszConfName[i]);
hr = pITDir->GetConference( bszConfName[i], &pITConf );

pITConf->Release();

RETURN_ON_FAILURE_DIR( hr );

// delete the conference
hr = pITDir->DeleteConference( bszConfName[i] );
wprintf(L"\n");

::SysFreeString( bszConfName[i] );

RETURN_ON_FAILURE_DIR( hr );
}

pITDir->Release();

::CoUninitialize();

wprintf(L"\n\n");

return 0;

} // end of main