#include "t_plugin.h"
#include "stdio.h"

void TPlugin::do_it(const char *msg)
{
	printf("TPlugin::do_it(%s)\n",msg);
}
extern "C"
__declspec(dllexport)
int t()
{
	int count=0;
	for(Registry<Plugin>::iterator it=Registry<Plugin>::begin();it!=Registry<Plugin>::end();it++,count++)
	{
		const SimpleRegistryEntry<Plugin> &e=*it;
		printf("t_plugin.dll:Plugin: %s(%s)\n",e.getName(),e.getDesc());
		Plugin *p = e.instantiate();
		p->do_it("t_plugin.dll");
		delete p;
	}
	return count;
}


#ifndef _MSC_VER
static Registry<Plugin>::Add<TPlugin>
T("t_plugin", "Plugin T");
#else
#if 1==0
template<>
void Registry<Plugin>::Announce(const Registry<Plugin>::entry &E,Ha_get_func get_func)   
{  
	HMODULE hDll=(HMODULE)0;
	if(!get_func)
	{
		char fname[261];  
		GetModuleFileNameA (GetModuleHandle(0),fname,260);  
		HMODULE hDll=LoadLibraryA(fname);  
		get_func=(Ha_get_func)GetProcAddress(hDll,"get_node_for_" "Plugin");  
	}
	Registry<Plugin>::listener *_Head = (Registry<Plugin>::listener *)(*get_func)(1,1);  
	for (Registry<Plugin>::listener *Cur = _Head; Cur; Cur = Cur->Next) 
        Cur->registered(E); 
	if(hDll)
		FreeLibrary(hDll);  
}
#endif
class PluginRegistryListener : public Registry<Plugin>::listener
{
public:
	void registered(const Registry<Plugin>::entry & e)
	{
		printf("t_plugin.dll:%s(%s) is registered\n",e.getName(),e.getDesc());
	}
}prl;

REGISTER_PLUGIN(Plugin,TPlugin,"t_plugin", "Plugin Test")
#endif
