ClearBox Server™ v1.2 Developer's Guide

Step 2. Implementing Core Interface

1. Open Class View window, select CExtension class and right-click it. Select Add -> Implement Interface... from the context menu. Click Implement interface from file option, and in the Location box locate the file C:\Program files\ClearBox Server\SDK\TACRADServer.tlb (or another filename if the server was installed in another folder).

In the appeared list of available interfaces select ICommonExtender and ICommonExtender. Then move them to the right list and click Finish.

The development environment generates empty methods implementation, but some changes in the code are required.

2. Find CExtension class declaration. It should be the following:

	 ...
]
class ATL_NO_VTABLE CExtension : 
	public IExtension,
	public ICommonExtenderEx,
	public ICommonExtender
{
public:
	CExtension()
	  ...

Remove ICommonExtender from the list of inherited interfaces as ICommonExtenderEx is already inherited from it. Now declaration should be

	 ...
]
class ATL_NO_VTABLE CExtension : 
	public IExtension,
	public ICommonExtenderEx
{
public:
	CExtension()
	  ...

3. Now we need to make the compiler not register extension's library.

  • In the Class View window select the top-most node AdvancedExtension and right-click it. Select Properties from the context menu.
  • Select All configurations in the Configuration list.
  • In the dialog appeared select Linker in the left tree, its Embedded IDL node, and set Ignore Embedded IDL option to Yes(/IGNOREIDL).
  • In the Merged IDL Base File Name list select <inherit from project defaults>.
  • In the MIDL -> Output section of configuration properties set Generate Type Library option to No(/notlb).

4. In the Solution Explorer window find the file AdvancedExtension.cpp. Its content is the following:

// AdvancedExtension.cpp : Implementation of DLL Exports.

#include "stdafx.h"
#include "resource.h"

// The module attribute causes DllMain, DllRegisterServer and DllUnregisterServer to be 
// automatically implemented for you
[ module(dll, uuid = "{D84CA787-3BE0-4E8C-A7A4-154AB56C3FC5}", 
		 name = "AdvancedExtension", 
		 helpstring = "AdvancedExtension 1.0 Type Library",
		 resource_name = "IDR_ADVANCEDEXTENSION") ];
		

Now change it:

// AdvancedExtension.cpp : Implementation of DLL Exports.

#include "stdafx.h"
#include "resource.h"

[ module(dll, uuid = "{D84CA787-3BE0-4E8C-A7A4-154AB56C3FC5}", 
		 name = "AdvancedExtension", 
		 helpstring = "AdvancedExtension 1.0 Type Library",
		 resource_name = "IDR_ADVANCEDEXTENSION") ]
class CMy: public CAtlBaseModule
{
	public:
	HRESULT DllRegisterServer() 
	{
		return __super::DllRegisterServer(FALSE);
	}
};
	  

By these changes we override DLLRegisterServer method of the CAtlDllModuleT class and pass FALSE to the base class method so to skip type library registration. Inheriting our CMy class from CAtlBaseModule we get access to the module's HINSTANCE.

Next, we need to move this class definition (starting from the line [ module(dll, uuid = "{D84CA787-3BE0-4E8C-A7A4-154AB56C3FC5}",) to the extension.h file before CExtension class declaration before the lines

// CExtension

[
	coclass,
...		
		

It's necessary as we need to make available CMy class to other classes.

4. Now it's time to implement ICommonExtender and ICommonExtenderEx methods.

First, we need to query pointers for IServer2, ILivingstonAccounting and ICSVAccounting interfaces and store them in class fields. They will be used later. Add the following lines at the end of CExtender class declaration:

private:
	IServer2Ptr m_pServ2;
	ILivingstonAccountingPtr m_pLivAcct;
	ICSVAccountingPtr m_pCSVAcct;
		

These interfaces are declared in a separate type library, so it must be imported.

Find stdafx.h file in Solution Explorer and add to its end the following lines:

#import "C:\Program Files\ClearBox Server\SDK\CBServer.tlb" no_namespace, named_guids, auto_search, \
exclude("IServer"), exclude("ATTRIBVALTYPE"), exclude("tagUSERINFOLITE"), \
exclude("tagRADIUS_ATTRIBUTE"), exclude("MANDATORYTYPE"), exclude("ACCESSTYPE"), \
	exclude("tagAVPAIR"), exclude("tagTAC_AUTHORPARAMS")
#include "c:\program files\clearbox server\sdk\tacacs_codes.h"
#include <atlstr.h>
#include <atldbcli.h>
#include <ATLComTime.h>
#include <winsock2.h>
#pragma comment (lib,"ws2_32.lib")

#include <list>
		

The path of the imported library may be different if the server is installed not in its default directory.

The included file atlstr.h is need as we'll use CString class. atldbcli.h is used for ATLOLE DB templates, atlcomtime.h for COleDateTime class, tacacs_codes.h for TACACS+ constants declaration. Other instructions are necessary for access to WinSock functions and std::list class.

5. Find InitializeEx method in the CExtension class using Class View. Change its implementation to the following:

STDMETHOD(InitializeEx)(VARIANT_BOOL start, IServer * pServer)
{
	if (start==VARIANT_TRUE)
	{
		m_pServ2=pServer;
		m_pLivAcct=pServer;
		m_pCSVAcct=pServer;
	}
	return S_OK;
}

This code uses 'smart pointers', so there's no explicit QueryInterface calls here.

6. The final step is to make our co-class register in COM category CATID_RADTACServerExtension. You can read more about component categories here.

Copy ext_category.h file from the <server installation path>/SDK folder to the folder with this project.

Add the following line to Extension.h file

#include "ext_category.h"
	  

after the line

#include "resource.h"       // main symbols
	  

Then add an attribute implements_category("CATID_TACRADServerExtension") to the list of co-class attributes, so now CExtension class declaration is

[
	coclass,
	threading("free"),
	vi_progid("AdvancedExtension.Extension"),
	progid("AdvancedExtension.Extension.1"),
	version(1.0),
	uuid("9928F8EB-344B-47DB-A4B3-BC4683354ABB"),
	helpstring("Extension Class"),
	implements_category("CATID_TACRADServerExtension")
]
class ATL_NO_VTABLE CExtension : 
	public IExtension,
	public ICommonExtenderEx
{
...		
		

Go to the next step.


© 2001-2003 XPerience Technologies. www.xperiencetech.com

Created by chm2web html help conversion utility.