#include <stdio.h>
#include <windows.h>

#include "MyQipPlugin.h"	

//Подключаем SDK QIP
#include "SDK/u_common.h"		
#include "SDK/u_lang_ids.h"
#include "SDK/u_plugin_msg.h"
#include "SDK/u_plugin_info.h"

const int	PLUGIN_VER_MAJOR   = 1;
const int	PLUGIN_VER_MINOR   = 0;

const PWSTR PLUGIN_NAME		   = L"MyQipPlugin";
const PWSTR PLUGIN_AUTHOR	   = L"Lazy_elf";
const PWSTR PLUGIN_DESCRIPTION = L"Тестовый плагин-заготовка для QIP";
const PWSTR PLUGIN_HINT	       = L"Тестовый плагин-заготовка для QIP";
//////////////////////////////////////////////////////////////////////////////////////////////////
class TQipPlugin : public IQIPPlugin
{
	public:
		ULONG   __stdcall	AddRef();
		HRESULT	__stdcall	QueryInterface(REFIID riid, void** ppvObject);
		ULONG   __stdcall	Release();

		TQipPlugin(IQIPPluginService* PluginService);	
		~TQipPlugin();

		TPluginInfo*	__stdcall	GetPluginInfo();
		void			__stdcall	OnQipMessage(TPluginMessage* PlugMsg);

	private:	
		ULONG PlugCntr;
		IQIPPluginService*			PlugServ;
		TPluginInfo					PlugInfo;
		int                         LastFade;
  
};
//Главная экспортируемая функция
void __stdcall CreateInfiumPLUGIN(IQIPPlugin** Result, IQIPPluginService* PluginService)
{
	*Result = new TQipPlugin(PluginService);
}

//////////////////////////////////////////////////////////////////////////////////////////////////
ULONG			__stdcall	TQipPlugin::AddRef()	{return ++PlugCntr;}
HRESULT			__stdcall	TQipPlugin::QueryInterface(REFIID riid, void** ppvObject){return E_FAIL;}
ULONG			__stdcall	TQipPlugin::Release()	{return --PlugCntr;}
//////////////////////////////////////////////////////////////////////////////////////////////////
//Конструктор класса
TQipPlugin:: TQipPlugin(IQIPPluginService* PluginService):PlugCntr(0){PlugServ = PluginService;}
//Деструктор класса
TQipPlugin::~TQipPlugin(){}
TPluginInfo* __stdcall	TQipPlugin::GetPluginInfo(){return &PlugInfo;}
//////////////////////////////////////////////////////////////////////////////////////////////////
/*-----------------------------------------------------------------------------------------------------------*/
void __stdcall	TQipPlugin::OnQipMessage(TPluginMessage* PlugMsg)
{   
	TPluginMessage SendMsg; 
	SendMsg.DllHandle = PlugInfo.DllHandle;
    
	switch(PlugMsg->Msg)
    {   
		case PM_PLUGIN_LOAD_SUCCESS:
            WCHAR PlugPath[MAX_PATH];
            GetModuleFileName(PlugInfo.DllHandle, PlugPath, MAX_PATH); 
	        PlugInfo.DllPath		   = SysAllocString(PlugPath);     
	        PlugInfo.QipSdkVerMajor    = QIP_SDK_VER_MAJOR;
	        PlugInfo.QipSdkVerMinor    = QIP_SDK_VER_MINOR;
	        PlugInfo.PlugVerMajor      = PLUGIN_VER_MAJOR;
	        PlugInfo.PlugVerMinor      = PLUGIN_VER_MINOR;
	        PlugInfo.PluginName        = SysAllocString(PLUGIN_NAME);
	        PlugInfo.PluginAuthor      = SysAllocString(PLUGIN_AUTHOR);
            PlugInfo.PluginDescription = SysAllocString(PLUGIN_DESCRIPTION);
            PlugInfo.PluginHint        = SysAllocString(PLUGIN_HINT);
            PlugInfo.PluginIcon        = 0;
        break;

        case PM_PLUGIN_RUN:   
        case PM_PLUGIN_ENABLE:
            /* Start plugin working */
        break;

        case PM_PLUGIN_QUIT:
        case PM_PLUGIN_DISABLE:
            /* Stop plugin working */
			
        break;

		case PM_PLUGIN_OPTIONS:
			MessageBox(NULL,PLUGIN_HINT,PLUGIN_NAME,MB_OK);
		break;

		case PM_PLUGIN_WRONG_SDK_VER:
		break;
	}       
}
/*-----------------------------------------------------------------------------------------------------------*/
