// aplReportMgr.cpp : Defines the initialization routines for the DLL.
//

#include "stdafx.h"
#include <afxdllx.h>
#include "resource.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif


static AFX_EXTENSION_MODULE AplReportMgrDLL = { NULL, NULL };

int cd_count = 0;
HINSTANCE dllInst=0;
CDC		*_pPrinterDC = NULL;
//CImageList	*m_ImageList = NULL;

extern "C" int APIENTRY
DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
{
	UNREFERENCED_PARAMETER(lpReserved);

	dllInst = hInstance;
	if (dwReason == DLL_PROCESS_ATTACH)
	{
		TRACE(_T("APLREPORTMGR.DLL Initializing!\n"));
		
		if (!AfxInitExtensionModule(AplReportMgrDLL, hInstance))
			return 0;

		new CDynLinkLibrary(AplReportMgrDLL);

		/*m_ImageList = new CImageList;
		CBitmap bm;
		bm.LoadBitmap(IDB_BITMAPS);
		m_ImageList->Create(16, 16, ILC_COLOR24|ILC_MASK, 0, 100);
		m_ImageList->Add(&bm,RGB(192,192,192));
		bm.DeleteObject();*/
	}
	else if (dwReason == DLL_PROCESS_DETACH)
	{
		//m_ImageList->DeleteImageList();
		//delete m_ImageList;

		if(_pPrinterDC)
		{
			if(_pPrinterDC->GetSafeHdc()!=NULL) _pPrinterDC->DeleteDC();
			delete _pPrinterDC;
			_pPrinterDC = NULL;
			
			TRACE(_T("Destroy and delete Printer DC.\n"));
		}

		TRACE(_T("APLREPORTMGR.DLL Terminating!\n"));
		AfxTermExtensionModule(AplReportMgrDLL);
	}
	return 1;
}
