//
//	Copyright © 2005 Nemetschek North America 
//	All Rights Reserved.
//
// Created by Vladislav Stanev

#pragma once


#include "VWPluginLibraryArgTable.h"

#define MAX_ROUTINES_COUNT			255

namespace VWFC
{
	namespace PluginSupport
	{
		class VWPluginLibraryRoutine;
		class VWPluginLibraryApp
		{
		public:
									VWPluginLibraryApp();
			virtual					~VWPluginLibraryApp();

		// interface
		public:
			virtual long			DispatchRoutine(long routineSelector, VWPluginLibraryArgTable& argTable, long &userData);
			// the pointes passed is deleted when the app finishes (at ~VWPluginLibraryApp)
			void					AddLibraryRoutine(VWPluginLibraryRoutine* pRoutine);

		// VCOM
		public:
			virtual VCOMError		RegisterInterfaces(void* pModule);
			virtual void			CreateInterfaceInstance(const VWIID& iid, IVWUnknown** ppOutInterface);
			virtual void			DeleteInterfaceInstance(const VWIID& iid, IVWUnknown* pInterface);

		protected:
			VWPluginLibraryRoutine*	farrLibraryRoutines[ MAX_ROUTINES_COUNT ];
			size_t					fnLastRoutineIndex;
			long*					farrRoutinesUserData;
		};

	}
}
// the macross for easy registration
#define INSTANTIATE_PLUGINLIBRARY_APP			VWPluginLibraryApp	 g_varLibApp;

#define ADD_PLUGINLIBRARY_ROUTINE(clas) class clas##clas	\
		{public : clas##clas()	{									\
			g_varLibApp.AddLibraryRoutine( &_locVar ); \
		} private: clas _locVar;					\
		} g_var##clas
