// RegisterDll.cpp: implementation of the CRegisterDll class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "RegisterDll.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CRegisterDll::CRegisterDll()
{
	
}

CRegisterDll::~CRegisterDll()
{
	
}

BOOL CRegisterDll::RegisterDll(LPCTSTR filepath)
{
	HINSTANCE hInst;
	FARPROC proc;

	hInst = LoadLibrary(filepath);
	if(hInst==NULL)
	{
		return FALSE;;
	}

	proc = GetProcAddress(hInst,("DllRegisterServer"));
	if(proc==NULL)
	{
		FreeLibrary(hInst);
		return FALSE;
	}

	proc();
	if(GetLastError())
	{	
		FreeLibrary(hInst);
		return FALSE;
	}
		
	FreeLibrary(hInst);	
	return TRUE;
}

BOOL CRegisterDll::UnRegisterDll(LPCTSTR filepath)
{
	HINSTANCE hInst;
	FARPROC proc;

	hInst = LoadLibrary(filepath);
	if(hInst==NULL)
	{
		return FALSE;;
	}

	proc = GetProcAddress(hInst,("DllUnregisterServer"));
	if(proc==NULL)
	{
		FreeLibrary(hInst);
		return FALSE;
	}

	proc();
	if(GetLastError())
	{	
		FreeLibrary(hInst);
		return FALSE;
	}
		
	FreeLibrary(hInst);	
	return TRUE;	
}
