

#include "plugin.h"
#include "registry.h"

#include "windows.h"
#include "stdio.h"

typedef Registry<Plugin> PluginRegistry;

//PluginRegistry registry;
extern "C"
typedef int (*t_func)();
IMPLEMENT_PLUGIN_REGISTRY(Plugin)

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

REGISTER_PLUGIN(Plugin,PluginTA,"PluginTA", "PluginTA Test")

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

}
class PluginRegistryListener : public Registry<Plugin>::listener
{
public:
	PluginRegistryListener()
	{
		init();
	}
	void registered(const Registry<Plugin>::entry & e)
	{
		printf("t_registryA.exe:%s(%s) Registered\n",e.getName(),e.getDesc());
	}
}prl;

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

int main()
{
	
	HMODULE hDll=LoadLibraryA("t_plugin.dll");
	if(!hDll)
	{
		printf("Ha,Failed to load t_plugin.dll\n");
		return 1;
	}
	LoadPlugins();
	t_func t=(t_func)GetProcAddress(hDll,"t");
	
	if(!t)
	{
		printf("Ha,Failed to find t in t_plugin.dll\n");
		FreeLibrary(hDll);
		return 1;
	}
	else
		(*t)();
	FreeLibrary(hDll);
	return 0;
}

