
#include "plugin.h"
#include "registry.h"
#include "t_plugin.h"
#include "windows.h"
#include "stdio.h"
typedef Registry<Plugin> PluginRegistry;

//PluginRegistry registry;
extern "C"
typedef int (*t_func)();
IMPLEMENT_PLUGIN_REGISTRY(Plugin)
/*
Registry<Plugin>::node *Registry<Plugin>::Head;
Registry<Plugin>::node *Registry<Plugin>::Tail;
static void Announce(const entry &E) {
      for (listener *Cur = ListenerHead; Cur; Cur = Cur->Next)
        Cur->registered(E);
    }
*/

class PluginT2: public Plugin
{
public:
	PluginT2()
	{
	}
	virtual ~PluginT2()
	{
	}
	virtual void do_it(const char *msg)
	{
		printf("Ha %s\n",msg);
	}
};

REGISTER_PLUGIN(Plugin,PluginT2,"PluginT2", "PluginT2 Test")

void LoadPlugins()
{
	for(Registry<Plugin>::iterator it=Registry<Plugin>::begin();it!=Registry<Plugin>::end();++it)
	{
		const SimpleRegistryEntry<Plugin> &e=*it;
		printf("t_registry.exe:Plugin: %s(%s)\n",e.getName(),e.getDesc());
		Plugin *p = e.instantiate();
		p->do_it("t_registry.exe");
		delete p;
	}

}
int main()
{
	HMODULE hDll=LoadLibraryA("t_plugin.dll");
	LoadPlugins();
	t_func t=(t_func)GetProcAddress(hDll,"t");
	(*t)();
	if(hDll)
		FreeLibrary(hDll);
	return 0;
}


extern "C"
__declspec(dllexport)
 void Ha()
{
	printf("Ha\n");
}